Skip to content

Commit

Permalink
test: 💍 Refactor host delete test selectors (#2626)
Browse files Browse the repository at this point in the history
Refactor host-catalog host delete acceptance test selectors
  • Loading branch information
calcaide authored Dec 13, 2024
1 parent 6d2f1dc commit 584e62c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
40 changes: 21 additions & 19 deletions ui/admin/tests/acceptance/host-catalogs/hosts/delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -79,18 +77,18 @@ 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);
});

test('cannot delete a host without proper authorization', async function (assert) {
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) {
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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.');
});
});
7 changes: 5 additions & 2 deletions ui/admin/tests/acceptance/host-catalogs/hosts/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]';

0 comments on commit 584e62c

Please sign in to comment.