From 14408bc63ed98e73d7255a378bfac3451a02aa90 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Tue, 27 Oct 2020 15:26:12 -0400 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20test=20global=20scope=20?= =?UTF-8?q?auto-create?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/core/app/routes/scopes/scope.js | 4 ++-- ui/core/tests/acceptance/scopes-test.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ui/core/app/routes/scopes/scope.js b/ui/core/app/routes/scopes/scope.js index 95b31260d..3bc4ecaaa 100644 --- a/ui/core/app/routes/scopes/scope.js +++ b/ui/core/app/routes/scopes/scope.js @@ -27,6 +27,7 @@ export default class ScopesScopeRoute extends Route { return this.store.findRecord('scope', id).catch(() => { const maybeExistingScope = this.store.peekRecord('scope', id); const scopeOptions = { id, type }; + /* istanbul ignore else */ if (type === 'global') { scopeOptions.name = this.intl.t('titles.global'); } @@ -47,8 +48,7 @@ export default class ScopesScopeRoute extends Route { orgs = await this.store.query('scope', { scope_id: 'global' }) .catch(() => A([])); if (model.isProject) { - projects = await this.store.query('scope', { scope_id: model.scopeID }) - .catch(() => A([])); + projects = await this.store.query('scope', { scope_id: model.scopeID }); } // Then pull out the "selected" scopes, if relevant let selectedOrg, selectedProject; diff --git a/ui/core/tests/acceptance/scopes-test.js b/ui/core/tests/acceptance/scopes-test.js index d1d873a5c..2894c32c4 100644 --- a/ui/core/tests/acceptance/scopes-test.js +++ b/ui/core/tests/acceptance/scopes-test.js @@ -3,6 +3,7 @@ import { visit, currentURL, click } 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. @@ -58,6 +59,30 @@ module('Acceptance | scopes', function (hooks) { authenticateSession({}); }); + test('visiting global scope', async function (assert) { + assert.expect(1); + await visit(urls.globalScope); + await a11yAudit(); + assert.equal(currentURL(), urls.globalScope); + }); + + // TODO: this probably shouldn't be the case, but was setup to enable + // authentication when the global scope couldn't be loaded. + // In order to resolve this, we might hoist authentication routes up from + // under scopes. + test('visiting global scope is successful even when the global scope cannot be fetched', async function (assert) { + assert.expect(1); + this.server.get('/scopes/:id', ({ scopes }, { params: { id } }) => { + const scope = scopes.find(id); + const response = (id === 'global') + ? new Response(404) + : scope; + return response; + }); + await visit(urls.globalScope); + assert.equal(currentURL(), urls.globalScope); + }); + test('visiting org scope', async function (assert) { assert.expect(1); await visit(urls.orgScope);