2024-04-15 11:51:03 -05:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2024-04-15 11:51:03 -05:00
|
|
|
*/
|
|
|
|
|
|
2024-04-05 10:59:35 -07:00
|
|
|
import { module, test } from 'qunit';
|
2025-04-14 14:27:02 -07:00
|
|
|
import { currentURL, visit, fillIn, waitFor } from '@ember/test-helpers';
|
2024-12-02 12:51:24 -06:00
|
|
|
import { setupApplicationTest } from 'admin/tests/helpers';
|
2024-04-05 10:59:35 -07:00
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
|
|
|
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
2024-11-22 11:27:53 -08:00
|
|
|
import { authenticateSession } from 'ember-simple-auth/test-support';
|
2025-03-28 15:00:59 -07:00
|
|
|
import * as commonSelectors from 'admin/tests/helpers/selectors';
|
|
|
|
|
import * as selectors from './selectors';
|
2024-04-05 10:59:35 -07:00
|
|
|
|
|
|
|
|
module('Acceptance | scopes | list', function (hooks) {
|
|
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
setupIndexedDb(hooks);
|
|
|
|
|
|
|
|
|
|
const instances = {
|
|
|
|
|
scopes: {
|
|
|
|
|
global: null,
|
|
|
|
|
org1: null,
|
|
|
|
|
org2: null,
|
|
|
|
|
project1: null,
|
|
|
|
|
project2: null,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const urls = {
|
2025-04-14 14:27:02 -07:00
|
|
|
scopes: null,
|
2024-04-05 10:59:35 -07:00
|
|
|
globalScope: null,
|
|
|
|
|
orgScope: null,
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-03 10:27:27 -08:00
|
|
|
hooks.beforeEach(async function () {
|
2024-04-05 10:59:35 -07:00
|
|
|
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
|
|
|
|
instances.scopes.org1 = this.server.create('scope', {
|
|
|
|
|
type: 'org',
|
|
|
|
|
scope: { id: 'global', type: 'global' },
|
|
|
|
|
});
|
|
|
|
|
instances.scopes.org2 = this.server.create('scope', {
|
|
|
|
|
type: 'org',
|
|
|
|
|
scope: { id: 'global', type: 'global' },
|
|
|
|
|
});
|
|
|
|
|
instances.scopes.project1 = this.server.create('scope', {
|
|
|
|
|
type: 'project',
|
|
|
|
|
scope: { id: instances.scopes.org1.id, type: 'org' },
|
|
|
|
|
});
|
|
|
|
|
instances.scopes.project2 = this.server.create('scope', {
|
|
|
|
|
type: 'project',
|
|
|
|
|
scope: { id: instances.scopes.org1.id, type: 'org' },
|
|
|
|
|
});
|
2025-04-14 14:27:02 -07:00
|
|
|
|
|
|
|
|
urls.scopes = '/scopes';
|
|
|
|
|
urls.globalScope = '/scopes/global/scopes';
|
2024-04-05 10:59:35 -07:00
|
|
|
urls.orgScope = `/scopes/${instances.scopes.org1.id}/scopes`;
|
2024-12-03 10:27:27 -08:00
|
|
|
await authenticateSession({});
|
2024-04-05 10:59:35 -07:00
|
|
|
});
|
|
|
|
|
|
2025-04-14 14:27:02 -07:00
|
|
|
test('user gets redirected to scopes list view', async function (assert) {
|
|
|
|
|
await visit(urls.scopes);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(currentURL(), urls.globalScope);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('user can search for a specific org scope by id', async function (assert) {
|
2024-04-05 10:59:35 -07:00
|
|
|
await visit(urls.globalScope);
|
|
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.org1.id))
|
|
|
|
|
.exists();
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.org2.id))
|
|
|
|
|
.exists();
|
2024-04-05 10:59:35 -07:00
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
await fillIn(commonSelectors.SEARCH_INPUT, instances.scopes.org1.id);
|
|
|
|
|
await waitFor(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.org2.id), {
|
|
|
|
|
count: 0,
|
|
|
|
|
});
|
2024-04-05 10:59:35 -07:00
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.org1.id))
|
|
|
|
|
.exists();
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.org2.id))
|
|
|
|
|
.doesNotExist();
|
2024-04-05 10:59:35 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('user can search for org scopes and get no results', async function (assert) {
|
|
|
|
|
await visit(urls.globalScope);
|
|
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.org1.id))
|
|
|
|
|
.exists();
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.org2.id))
|
|
|
|
|
.exists();
|
2024-04-05 10:59:35 -07:00
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
await fillIn(
|
|
|
|
|
commonSelectors.SEARCH_INPUT,
|
|
|
|
|
'fake org scope that does not exist',
|
|
|
|
|
);
|
|
|
|
|
await waitFor(selectors.NO_SCOPE_RESULTS_MSG, { count: 1 });
|
2024-04-05 10:59:35 -07:00
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.org1.id))
|
|
|
|
|
.doesNotExist();
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.org2.id))
|
|
|
|
|
.doesNotExist();
|
2024-04-05 10:59:35 -07:00
|
|
|
});
|
|
|
|
|
|
2025-04-14 14:27:02 -07:00
|
|
|
test('user can search for a specific project scope by id', async function (assert) {
|
2024-04-05 10:59:35 -07:00
|
|
|
await visit(urls.orgScope);
|
|
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.project1.id))
|
|
|
|
|
.exists();
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.project2.id))
|
|
|
|
|
.exists();
|
2024-04-05 10:59:35 -07:00
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
await fillIn(commonSelectors.SEARCH_INPUT, instances.scopes.project1.id);
|
|
|
|
|
await waitFor(
|
|
|
|
|
selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.project2.id),
|
|
|
|
|
{
|
|
|
|
|
count: 0,
|
|
|
|
|
},
|
|
|
|
|
);
|
2024-04-05 10:59:35 -07:00
|
|
|
|
|
|
|
|
assert
|
2025-03-28 15:00:59 -07:00
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.project1.id))
|
|
|
|
|
.exists();
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.project2.id))
|
2024-04-05 10:59:35 -07:00
|
|
|
.doesNotExist();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('user can search for project scopes and get no results', async function (assert) {
|
|
|
|
|
await visit(urls.orgScope);
|
|
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.project1.id))
|
|
|
|
|
.exists();
|
|
|
|
|
assert
|
|
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.project2.id))
|
|
|
|
|
.exists();
|
2024-04-05 10:59:35 -07:00
|
|
|
|
2025-03-28 15:00:59 -07:00
|
|
|
await fillIn(
|
|
|
|
|
commonSelectors.SEARCH_INPUT,
|
|
|
|
|
'fake org scope that does not exist',
|
|
|
|
|
);
|
|
|
|
|
await waitFor(selectors.NO_SCOPE_RESULTS_MSG, { count: 1 });
|
2024-04-05 10:59:35 -07:00
|
|
|
|
|
|
|
|
assert
|
2025-03-28 15:00:59 -07:00
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.project1.id))
|
2024-04-05 10:59:35 -07:00
|
|
|
.doesNotExist();
|
|
|
|
|
assert
|
2025-03-28 15:00:59 -07:00
|
|
|
.dom(selectors.TABLE_ROW_SCOPE_LINK(instances.scopes.project2.id))
|
2024-04-05 10:59:35 -07:00
|
|
|
.doesNotExist();
|
|
|
|
|
});
|
|
|
|
|
});
|