From 584e62cff3756ef07c7ae86642cfd71ba32c0ab4 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Fri, 13 Dec 2024 15:57:10 -0800 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20Refactor=20host=20delete?= =?UTF-8?q?=20test=20selectors=20(#2626)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor host-catalog host delete acceptance test selectors --- .../host-catalogs/hosts/create-test.js | 2 +- .../host-catalogs/hosts/delete-test.js | 40 ++++++++++--------- .../host-catalogs/hosts/selectors.js | 7 +++- 3 files changed, 27 insertions(+), 22 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 ccb2b23a2..f056b11b3 100644 --- a/ui/admin/tests/acceptance/host-catalogs/hosts/create-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/hosts/create-test.js @@ -105,7 +105,7 @@ module('Acceptance | host-catalogs | hosts | create', function (hooks) { 'create', ), ); - assert.dom(selectors.MANAGE_DROPDOWN).exists(); + assert.dom(selectors.MANAGE_DROPDOWN_HOST_CATALOG).exists(); }); test('Users cannot navigate to new host route without proper authorization', async function (assert) { diff --git a/ui/admin/tests/acceptance/host-catalogs/hosts/delete-test.js b/ui/admin/tests/acceptance/host-catalogs/hosts/delete-test.js index 1aeaf2405..670a3fcba 100644 --- a/ui/admin/tests/acceptance/host-catalogs/hosts/delete-test.js +++ b/ui/admin/tests/acceptance/host-catalogs/hosts/delete-test.js @@ -4,23 +4,21 @@ */ import { module, test } from 'qunit'; -import { visit, find, click } from '@ember/test-helpers'; +import { visit, click } from '@ember/test-helpers'; import { setupApplicationTest } from 'admin/tests/helpers'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import { Response } from 'miragejs'; import { resolve, reject } from 'rsvp'; import sinon from 'sinon'; 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 | delete', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); let getHostCount; - const MANAGE_DROPDOWN_SELECTOR = - '[data-test-manage-hosts-dropdown] button:first-child'; - const DELETE_ACTION_SELECTOR = - '[data-test-manage-hosts-dropdown] ul li button'; const instances = { scopes: { @@ -79,8 +77,9 @@ module('Acceptance | host-catalogs | hosts | delete', function (hooks) { test('can delete host', async function (assert) { const count = getHostCount(); await visit(urls.host); - await click(MANAGE_DROPDOWN_SELECTOR); - await click(DELETE_ACTION_SELECTOR); + + await click(selectors.MANAGE_DROPDOWN_HOST); + await click(selectors.MANAGE_DROPDOWN_HOST_DELETE); assert.strictEqual(getHostCount(), count - 1); }); @@ -88,9 +87,8 @@ module('Acceptance | host-catalogs | hosts | delete', function (hooks) { instances.host.authorized_actions = instances.host.authorized_actions.filter((item) => item !== 'delete'); await visit(urls.host); - assert.notOk( - find('.rose-layout-page-actions .rose-dropdown-button-danger'), - ); + + assert.dom(selectors.MANAGE_DROPDOWN_HOST).doesNotExist(); }); test('can accept delete host via dialog', async function (assert) { @@ -99,8 +97,10 @@ module('Acceptance | host-catalogs | hosts | delete', function (hooks) { confirmService.confirm = sinon.fake.returns(resolve()); const count = getHostCount(); await visit(urls.host); - await click(MANAGE_DROPDOWN_SELECTOR); - await click(DELETE_ACTION_SELECTOR); + + await click(selectors.MANAGE_DROPDOWN_HOST); + await click(selectors.MANAGE_DROPDOWN_HOST_DELETE); + assert.strictEqual(getHostCount(), count - 1); assert.ok(confirmService.confirm.calledOnce); }); @@ -111,8 +111,10 @@ module('Acceptance | host-catalogs | hosts | delete', function (hooks) { confirmService.confirm = sinon.fake.returns(reject()); const count = getHostCount(); await visit(urls.host); - await click(MANAGE_DROPDOWN_SELECTOR); - await click(DELETE_ACTION_SELECTOR); + + await click(selectors.MANAGE_DROPDOWN_HOST); + await click(selectors.MANAGE_DROPDOWN_HOST_DELETE); + assert.strictEqual(getHostCount(), count); assert.ok(confirmService.confirm.calledOnce); }); @@ -130,10 +132,10 @@ module('Acceptance | host-catalogs | hosts | delete', function (hooks) { ); }); await visit(urls.host); - await click(MANAGE_DROPDOWN_SELECTOR); - await click(DELETE_ACTION_SELECTOR); - assert - .dom('[data-test-toast-notification] .hds-alert__description') - .hasText('Oops.'); + + await click(selectors.MANAGE_DROPDOWN_HOST); + await click(selectors.MANAGE_DROPDOWN_HOST_DELETE); + + assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Oops.'); }); }); diff --git a/ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js b/ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js index 1e3dd8bf4..ef033a4d4 100644 --- a/ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js +++ b/ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js @@ -3,9 +3,12 @@ * SPDX-License-Identifier: BUSL-1.1 */ -export const MANAGE_DROPDOWN = +export const MANAGE_DROPDOWN_HOST_CATALOG = '[data-test-manage-host-catalogs-dropdown] button:first-child'; - +export const MANAGE_DROPDOWN_HOST = + '[data-test-manage-hosts-dropdown] button:first-child'; +export const MANAGE_DROPDOWN_HOST_DELETE = + '[data-test-manage-hosts-dropdown] ul li button'; export const FIELD_ADDRESS = '[name=address]'; export const FIELD_ADDRESS_VALUE = 'New address'; export const FIELD_ADDRESS_ERROR = '[data-test-error-message-address]';