* refactor: 💡 move model hook to groups/index ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * feat: 🎸 add pagination to groups list view ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * feat: 🎸 add searching to groups ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * fix: 🐛 update scopeId to scope_id ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * test: 💍 clean up test refactor ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * refactor: 💡 update how groupsExisit is set ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * refactor: 💡 update mirage config for groups ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * test: 💍 fix failing groups create tests ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * refactor: 💡 add groups mirage config back ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * refactor: 💡 use translation string for Groups ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * refactor: 💡 update how groups are queried ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 * Update ui/admin/tests/acceptance/groups/list-test.js Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * refactor: 💡 update groups translation to title_plural ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12591 --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
127 lines
3.8 KiB
JavaScript
127 lines
3.8 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { visit, click, fillIn, waitUntil, findAll } from '@ember/test-helpers';
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
|
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
|
import {
|
|
authenticateSession,
|
|
// These are left here intentionally for future reference.
|
|
//currentSession,
|
|
//invalidateSession,
|
|
} from 'ember-simple-auth/test-support';
|
|
|
|
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]';
|
|
|
|
const instances = {
|
|
scopes: {
|
|
global: null,
|
|
org: null,
|
|
},
|
|
group1: null,
|
|
group2: null,
|
|
};
|
|
|
|
const urls = {
|
|
orgScope: null,
|
|
groups: null,
|
|
group1: null,
|
|
group2: null,
|
|
};
|
|
|
|
hooks.beforeEach(function () {
|
|
instances.scopes.global = this.server.create('scope', { id: 'global' });
|
|
instances.scopes.org = this.server.create(
|
|
'scope',
|
|
{
|
|
type: 'org',
|
|
scope: { id: 'global', type: 'global' },
|
|
},
|
|
'withChildren',
|
|
);
|
|
instances.group1 = this.server.create('group', {
|
|
scope: instances.scopes.org,
|
|
});
|
|
instances.group2 = this.server.create('group', {
|
|
scope: instances.scopes.org,
|
|
});
|
|
|
|
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}`;
|
|
authenticateSession({});
|
|
});
|
|
|
|
test('can navigate to groups with proper authorization', async function (assert) {
|
|
await visit(urls.orgScope);
|
|
assert.ok(
|
|
instances.scopes.org.authorized_collection_actions.groups.includes(
|
|
'list',
|
|
),
|
|
);
|
|
|
|
assert.dom(`[href="${urls.groups}"]`).isVisible();
|
|
});
|
|
|
|
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);
|
|
assert.notOk(
|
|
instances.scopes.org.authorized_collection_actions.groups.includes(
|
|
'list',
|
|
),
|
|
);
|
|
|
|
assert.dom(`[href="${urls.groups}"]`).doesNotExist();
|
|
});
|
|
|
|
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);
|
|
|
|
assert.dom(`[href="${urls.groups}"]`).isVisible();
|
|
});
|
|
|
|
test('user can search for a specific group by id', 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, instances.group1.id);
|
|
await waitUntil(() => findAll(`[href="${urls.group2}"]`).length === 0);
|
|
|
|
assert.dom(`[href="${urls.group1}"]`).exists();
|
|
assert.dom(`[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);
|
|
|
|
assert.dom(`[href="${urls.group1}"]`).doesNotExist();
|
|
assert.dom(`[href="${urls.group2}"]`).doesNotExist();
|
|
assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found');
|
|
});
|
|
});
|