import { module, test } from 'qunit'; import { visit, currentURL, find } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { authenticateSession, // These are left here intentionally for future reference. //currentSession, //invalidateSession, } from 'ember-simple-auth/test-support'; module('Acceptance | targets | read', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); const instances = { scopes: { global: null, org: null, project: null, }, }; const urls = { globalScope: null, orgScope: null, projectScope: null, targets: null, target: null, newTarget: null, }; hooks.beforeEach(function () { // Generate resources instances.scopes.global = this.server.create('scope', { id: 'global' }); instances.scopes.org = this.server.create('scope', { type: 'org', scope: { id: 'global', type: 'global' }, }); instances.scopes.project = this.server.create('scope', { type: 'project', scope: { id: instances.scopes.org.id, type: 'org' }, }); instances.target = this.server.create('target', { scope: instances.scopes.project, }); // Generate route URLs for resources urls.globalScope = `/scopes/global/scopes`; urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; urls.projectScope = `/scopes/${instances.scopes.project.id}`; urls.targets = `${urls.projectScope}/targets`; urls.target = `${urls.targets}/${instances.target.id}`; urls.unknownTarget = `${urls.targets}/foo`; urls.newTarget = `${urls.targets}/new`; // Generate resource couner authenticateSession({}); }); test('visiting targets', async function (assert) { assert.expect(2); await visit(urls.targets); await a11yAudit(); assert.equal(currentURL(), urls.targets); await visit(urls.target); await a11yAudit(); assert.equal(currentURL(), urls.target); }); test('cannot navigate to target form without proper authorization', async function (assert) { assert.expect(1); instances.target.authorized_actions = instances.target.authorized_actions.filter((item) => item !== 'read'); await visit(urls.target); assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a')); }); test('visiting an unknown target displays 404 message', async function (assert) { assert.expect(1); await visit(urls.unknownTarget); await a11yAudit(); assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404'); }); });