Files
threshold-ui/ui/admin/tests/acceptance/groups/list-test.js
T

125 lines
3.9 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
2021-08-25 23:43:07 -07:00
import { module, test } from 'qunit';
import { visit, click, fillIn, waitUntil, findAll } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
2021-08-25 23:43:07 -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';
2024-11-06 15:13:17 -08:00
import * as commonSelectors from 'admin/tests/helpers/selectors';
2021-08-25 23:43:07 -07:00
module('Acceptance | groups | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);
const SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]';
const NO_RESULTS_MSG_SELECTOR = '[data-test-no-groups-results]';
2021-08-27 13:09:00 -07:00
2021-08-25 23:43:07 -07:00
const instances = {
scopes: {
global: null,
org: null,
},
group1: null,
group2: null,
2021-08-25 23:43:07 -07:00
};
const urls = {
orgScope: null,
2021-08-25 23:43:07 -07:00
groups: null,
group1: null,
group2: null,
2021-08-25 23:43:07 -07:00
};
hooks.beforeEach(async function () {
2021-08-25 23:43:07 -07:00
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create(
2021-08-25 23:43:07 -07:00
'scope',
{
type: 'org',
scope: { id: 'global', type: 'global' },
},
'withChildren',
2021-08-25 23:43:07 -07:00
);
instances.group1 = this.server.create('group', {
scope: instances.scopes.org,
});
instances.group2 = this.server.create('group', {
scope: instances.scopes.org,
2021-08-25 23:43:07 -07:00
});
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
urls.group1 = `${urls.groups}/${instances.group1.id}`;
urls.group2 = `${urls.groups}/${instances.group2.id}`;
await authenticateSession({});
2021-08-25 23:43:07 -07:00
});
test('can navigate to groups with proper authorization', async function (assert) {
await visit(urls.orgScope);
2021-08-27 13:09:00 -07:00
assert.ok(
instances.scopes.org.authorized_collection_actions.groups.includes(
'list',
),
2021-08-27 13:09:00 -07:00
);
2024-11-06 15:13:17 -08:00
assert.dom(commonSelectors.HREF(urls.groups)).isVisible();
2021-08-25 23:43:07 -07:00
});
2021-08-27 13:09:00 -07:00
test('User cannot navigate to index without either list or create actions', async function (assert) {
instances.scopes.org.authorized_collection_actions.groups = [];
await visit(urls.orgScope);
2024-11-06 15:13:17 -08:00
2021-08-25 23:43:07 -07:00
assert.notOk(
instances.scopes.org.authorized_collection_actions.groups.includes(
'list',
),
2021-08-25 23:43:07 -07:00
);
2024-11-06 15:13:17 -08:00
assert.dom(commonSelectors.HREF(urls.groups)).doesNotExist();
2021-08-27 13:09:00 -07:00
});
test('User can navigate to index with only create action', async function (assert) {
instances.scopes.org.authorized_collection_actions.groups = ['create'];
await visit(urls.orgScope);
2024-11-06 15:13:17 -08:00
assert.dom(commonSelectors.HREF(urls.groups)).isVisible();
});
test('user can search for a specific group by id', async function (assert) {
await visit(urls.orgScope);
2024-11-06 15:13:17 -08:00
await click(commonSelectors.HREF(urls.groups));
2024-11-06 15:13:17 -08:00
assert.dom(commonSelectors.HREF(urls.group1)).exists();
assert.dom(commonSelectors.HREF(urls.group2)).exists();
await fillIn(SEARCH_INPUT_SELECTOR, instances.group1.id);
2024-11-06 15:13:17 -08:00
await waitUntil(
() => findAll(commonSelectors.HREF(urls.group2)).length === 0,
);
2024-11-06 15:13:17 -08:00
assert.dom(commonSelectors.HREF(urls.group1)).exists();
assert.dom(commonSelectors.HREF(urls.group2)).doesNotExist();
});
test('user can search for groups and get no results', async function (assert) {
await visit(urls.orgScope);
await click(`[href="${urls.groups}"]`);
assert.dom(`[href="${urls.group1}"]`).exists();
assert.dom(`[href="${urls.group2}"]`).exists();
await fillIn(SEARCH_INPUT_SELECTOR, 'fake group that does not exist');
await waitUntil(() => findAll(NO_RESULTS_MSG_SELECTOR).length === 1);
2024-11-06 15:13:17 -08:00
assert.dom(commonSelectors.HREF(urls.group1)).doesNotExist();
assert.dom(commonSelectors.HREF(urls.group2)).doesNotExist();
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
2021-08-25 23:43:07 -07:00
});
});