From 343e1d219371e1c2124275189b70ade8f86fd213 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 8 Jan 2025 09:14:29 -0800 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20Refactor=20host=20list?= =?UTF-8?q?=20test=20selectors=20(#2629)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: 💍 Refactor host list test selectors --- .../host-catalogs/hosts/create-test.js | 8 ++++++ .../host-catalogs/hosts/list-test.js | 27 ++++++++++--------- .../host-catalogs/hosts/selectors.js | 2 ++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/ui/admin/tests/acceptance/host-catalogs/hosts/create-test.js b/ui/admin/tests/acceptance/host-catalogs/hosts/create-test.js index f056b11b33..d5158b74ff 100644 --- a/ui/admin/tests/acceptance/host-catalogs/hosts/create-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/hosts/create-test.js @@ -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) { diff --git a/ui/admin/tests/acceptance/host-catalogs/hosts/list-test.js b/ui/admin/tests/acceptance/host-catalogs/hosts/list-test.js index d1660818f5..e56c4e09b9 100644 --- a/ui/admin/tests/acceptance/host-catalogs/hosts/list-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/hosts/list-test.js @@ -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, @@ -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); }); }); diff --git a/ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js b/ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js index ef033a4d40..d27a7e0bad 100644 --- a/ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js +++ b/ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js @@ -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 =