diff --git a/ui/core/app/routes/scopes/scope/orgs.js b/ui/core/app/routes/scopes/scope/orgs.js index 1e07d5f65..30a6c938f 100644 --- a/ui/core/app/routes/scopes/scope/orgs.js +++ b/ui/core/app/routes/scopes/scope/orgs.js @@ -12,10 +12,13 @@ export default class ScopesScopeOrgsRoute extends Route { // =methods /** - * If arriving here unauthenticated, redirect to index for further processing. + * If arriving here unauthenticated or from a non-global scope, + * redirect to index for further processing. */ beforeModel() { if (!this.session.isAuthenticated) this.transitionTo('index'); + const scope = this.modelFor('scopes.scope'); + if(!scope.isGlobal) this.transitionTo('index'); } /** diff --git a/ui/core/tests/acceptance/orgs-test.js b/ui/core/tests/acceptance/orgs-test.js index 941d3429c..aaeca8356 100644 --- a/ui/core/tests/acceptance/orgs-test.js +++ b/ui/core/tests/acceptance/orgs-test.js @@ -1,75 +1,125 @@ import { module, test } from 'qunit'; -//import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers'; +import { visit, currentURL, click, find, findAll, fillIn } 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 { Response } from 'miragejs'; -import //authenticateSession, -// These are left here intentionally for future reference. -//currentSession, -//invalidateSession, -'ember-simple-auth/test-support'; +import a11yAudit from 'ember-a11y-testing/test-support/audit'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; module('Acceptance | org', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); - // let org; - // let orgID; - // let orgsURL; - // let newOrgURL; - // let existingOrg; - // let existingOrgURL; - // let getOrgScopesCount; - // let getFirstOrgScope; - // let initialOrgScopesCount; - // - // hooks.beforeEach(function () { - // authenticateSession({}); - // - // }); + const instances = { + scopes: { + global: null, + }, + orgs: null, + }; + const urls = { + root: null, + scopes: null, + globalScope: null, + orgs: null, + newOrg: null, + }; + let orgsCount; + + hooks.beforeEach(function () { + // Setup Mirage mock resources for this test + authenticateSession({}); + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.orgs = this.server.createList('scope', 2, { + type: 'org', + scope: { id: 'global', type: 'global' }, + }); + orgsCount = instances.orgs.length; + // Generate route URLs for resources + urls.root = '/'; + urls.scopes = `/scopes`; + urls.globalScope = `${urls.scopes}/global`; + urls.orgs = `${urls.globalScope}/orgs`; + urls.newOrg = `${urls.orgs}/new`; + }); test('visiting orgs', async function (assert) { - assert.expect(0); + assert.expect(3); + await visit(urls.orgs); + await a11yAudit(); + assert.ok(orgsCount); + assert.equal(currentURL(), urls.orgs); + assert.equal(findAll('article').length, orgsCount); }); - test('visiting orgs within a org scope redirects to the parent org scope', async function (assert) { - assert.expect(0); + test('visiting scopes redirects to index', async function (assert) { + assert.expect(1); + await visit(urls.scopes); + assert.equal(currentURL(), urls.orgs); }); - test('can create new orgs', async function (assert) { - assert.expect(0); + test('visiting root redirects to index', async function (assert) { + assert.expect(1); + await visit(urls.root); + assert.equal(currentURL(), urls.orgs); }); - test('can cancel create new orgs', async function (assert) { - assert.expect(0); + test('visiting orgs within a non global scope redirects to index', async function (assert) { + const nonGlobalScopeURL = `${urls.scopes}/123/orgs`; + assert.expect(1); + await visit(nonGlobalScopeURL); + assert.equal(currentURL(), urls.orgs); + }); + + test('can create a new org', async function (assert) { + assert.expect(1); + await visit(urls.newOrg); + await fillIn('[name="name"]', 'Org name'); + await fillIn('[name="description"]', 'description'); + await click('form [type="submit"]:not(:disabled)'); + assert.equal(this.server.db.scopes.where(scope => scope.type === 'org').length, orgsCount + 1); + }); + + test('can cancel new org creation', async function (assert) { + assert.expect(2); + await visit(urls.newOrg); + await fillIn('[name="name"]', 'Org name'); + await fillIn('[name="description"]', 'description'); + await click('form button:not([type="submit"])'); + assert.equal(currentURL(), urls.orgs); + assert.equal(this.server.db.scopes.where(scope => scope.type === 'org').length, orgsCount); }); test('saving a new org with invalid fields displays error messages', async function (assert) { - assert.expect(0); - }); - - test('can save changes to existing org', async function (assert) { - assert.expect(0); - }); - - test('can cancel changes to existing org', async function (assert) { - assert.expect(0); - }); - - test('can delete org', async function (assert) { - assert.expect(0); - }); - - test('saving an existing org with invalid fields displays error messages', async function (assert) { - assert.expect(0); - }); - - test('errors are displayed when save org fails', async function (assert) { - assert.expect(0); - }); - - test('errors are displayed when delete org fails', async function (assert) { - assert.expect(0); + assert.expect(2); + this.server.post('/scopes', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid.', + details: { + request_fields: [ + { + name: 'name', + description: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit(urls.newOrg); + await fillIn('[name="name"]', 'new org'); + await click('form [type="submit"]'); + await a11yAudit(); + assert.ok(find('[role="alert"]')); + assert.ok(find('.rose-form-error-message')); }); }); diff --git a/ui/core/tests/acceptance/targets-test.js b/ui/core/tests/acceptance/targets-test.js index 822986f12..7cf31d8c5 100644 --- a/ui/core/tests/acceptance/targets-test.js +++ b/ui/core/tests/acceptance/targets-test.js @@ -6,9 +6,9 @@ import a11yAudit from 'ember-a11y-testing/test-support/audit'; import { Response } from 'miragejs'; import { authenticateSession, -// // These are left here intentionally for future reference. -// //currentSession, -// //invalidateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, } from 'ember-simple-auth/test-support'; module('Acceptance | targets', function (hooks) {