Skip to content

Commit

Permalink
test: πŸ’ Refactor host list test selectors (#2629)
Browse files Browse the repository at this point in the history
* test: πŸ’ Refactor host list test selectors
  • Loading branch information
calcaide authored Jan 8, 2025
1 parent 9a11925 commit 343e1d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
8 changes: 8 additions & 0 deletions ui/admin/tests/acceptance/host-catalogs/hosts/create-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,22 @@ module('Acceptance | host-catalogs | hosts | create', function (hooks) {

assert.dom(commonSelectors.HREF(urls.newHost)).doesNotExist();
});

test('Users can navigate to new host route with proper authorization', async function (assert) {
await visit(urls.hosts);

assert.ok(
instances.hostCatalog.authorized_collection_actions.hosts.includes(
'create',
),
);
assert.dom(selectors.MANAGE_DROPDOWN_HOST_CATALOG).exists();
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG);
assert
.dom(selectors.MANAGE_DROPDOWN_HOST_CATALOG_NEW_HOST)
.hasAttribute('href', urls.newHost);
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG_NEW_HOST);
assert.strictEqual(currentURL(), urls.newHost);
});

test('Users cannot navigate to new host route without proper authorization', async function (assert) {
Expand Down
27 changes: 15 additions & 12 deletions ui/admin/tests/acceptance/host-catalogs/hosts/list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
*/

import { module, test } from 'qunit';
import { visit, find, click } from '@ember/test-helpers';
import { visit, click, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'admin/tests/helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support';
import * as selectors from './selectors';
import * as commonSelectors from 'admin/tests/helpers/selectors';

module('Acceptance | host-catalogs | hosts | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

const MANAGE_DROPDOWN_SELECTOR =
'[data-test-manage-host-catalogs-dropdown] button:first-child';
const NEW_HOST_SELECTOR =
'[data-test-manage-host-catalogs-dropdown] div ul li a';

const instances = {
scopes: {
global: null,
Expand Down Expand Up @@ -69,33 +66,39 @@ module('Acceptance | host-catalogs | hosts | list', function (hooks) {
urls.newHost = `${urls.hosts}/new`;
await authenticateSession({});
});

test('Users can navigate to hosts with proper authorization', async function (assert) {
await visit(urls.hostCatalog);

assert.ok(
instances.hostCatalog.authorized_collection_actions.hosts.includes(
'list',
),
);
assert.dom(MANAGE_DROPDOWN_SELECTOR);
assert.ok(find(`[href="${urls.hosts}"]`));

assert.dom(selectors.MANAGE_DROPDOWN_HOST_CATALOG).isVisible();
assert.dom(commonSelectors.HREF(urls.hosts)).isVisible();
});

test('User cannot navigate to index without either list or create actions', async function (assert) {
instances.hostCatalog.authorized_collection_actions.hosts = [];
await visit(urls.hostCatalog);

assert.notOk(
instances.hostCatalog.authorized_collection_actions.hosts.includes(
'list',
),
);
assert.notOk(find(`[href="${urls.hosts}"]`));
assert.dom(commonSelectors.HREF(urls.hosts)).doesNotExist();
});

test('User can navigate to index with only create action', async function (assert) {
instances.hostCatalog.authorized_collection_actions.hosts = ['create'];
await visit(urls.hostCatalog);
assert.ok(find(`[href="${urls.hosts}"]`));
await click(MANAGE_DROPDOWN_SELECTOR);
assert.dom(NEW_HOST_SELECTOR).hasAttribute('href', urls.newHost);

assert.dom(commonSelectors.HREF(urls.hosts)).isVisible();
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG);
await click(selectors.MANAGE_DROPDOWN_HOST_CATALOG_NEW_HOST);
assert.strictEqual(currentURL(), urls.newHost);
});
});
2 changes: 2 additions & 0 deletions ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

export const MANAGE_DROPDOWN_HOST_CATALOG =
'[data-test-manage-host-catalogs-dropdown] button:first-child';
export const MANAGE_DROPDOWN_HOST_CATALOG_NEW_HOST =
'[data-test-manage-host-catalogs-dropdown] ul li:first-child a';
export const MANAGE_DROPDOWN_HOST =
'[data-test-manage-hosts-dropdown] button:first-child';
export const MANAGE_DROPDOWN_HOST_DELETE =
Expand Down

0 comments on commit 343e1d2

Please sign in to comment.