Files
threshold-ui/ui/admin/tests/acceptance/host-catalogs/host-sets/delete-test.js
T
hashicc dc9376a460 (HACK WEEK 2025) a11y-audit-ignore codemod (#2946)
* chore: 🤖 add ember-a11y-ignore tool

* chore: 🤖 fix handling existing setRunOptions imports

* chore: 🤖 move codemod to support folder

* chore: 🤖 fix edge case for handling property key names

* chore: 🤖 handle case where multiple of same violation in test

This fixes a bug where multiple cases of the same violation would end up
with multiple entries

* chore: 🤖 ignore axe rules that are currently failing in admin

* chore: 🤖 ignore axe rules that are currently failing in desktop

* docs: ✏️ add a comment explaining the codemod

* chore: 🤖 include test.each cases for a11y ignores

* fix: 🐛 handle test.each test cases for a11y ignore codemod
2025-08-19 10:51:44 -05:00

182 lines
5.6 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
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 commonSelectors from 'admin/tests/helpers/selectors';
import * as selectors from './selectors';
import { setRunOptions } from 'ember-a11y-testing/test-support';
module('Acceptance | host-catalogs | host sets | delete', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let getHostSetCount;
const instances = {
scopes: {
global: null,
org: null,
project: null,
hostCatalog: null,
host: null,
},
};
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
hostCatalogs: null,
hostCatalog: null,
hostSets: null,
hostSet: null,
unknownHostSet: null,
newHostSet: null,
};
hooks.beforeEach(async function () {
// Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.hostCatalog = this.server.create('host-catalog', {
scope: instances.scopes.project,
});
instances.hostSet = this.server.create('host-set', {
scope: instances.scopes.project,
hostCatalog: instances.hostCatalog,
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.hostCatalogs = `${urls.projectScope}/host-catalogs`;
urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`;
urls.hostSets = `${urls.hostCatalog}/host-sets`;
urls.hostSet = `${urls.hostSets}/${instances.hostSet.id}`;
urls.unknownHostSet = `${urls.hostSets}/foo`;
urls.newHostSet = `${urls.hostSets}/new`;
// Generate resource couner
getHostSetCount = () => this.server.schema.hostSets.all().models.length;
await authenticateSession({});
});
test('can delete host', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
const count = getHostSetCount();
await visit(urls.hostSet);
await click(selectors.MANAGE_DROPDOWN_HOST_SETS);
await click(selectors.MANAGE_DROPDOWN_HOST_SETS_DELETE);
assert.strictEqual(getHostSetCount(), count - 1);
});
test('can accept delete host set via dialog', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(resolve());
const count = getHostSetCount();
await visit(urls.hostSet);
await click(selectors.MANAGE_DROPDOWN_HOST_SETS);
await click(selectors.MANAGE_DROPDOWN_HOST_SETS_DELETE);
assert.strictEqual(getHostSetCount(), count - 1);
assert.ok(confirmService.confirm.calledOnce);
});
test('cannot delete host set without proper authorization', async function (assert) {
instances.hostSet.authorized_actions =
instances.hostSet.authorized_actions.filter((item) => item !== 'delete');
await visit(urls.hostSet);
await click(selectors.MANAGE_DROPDOWN_HOST_SETS);
assert.dom(selectors.MANAGE_DROPDOWN_HOST_SETS_DELETE).doesNotExist();
});
test('cannot cancel delete host set via dialog', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(reject());
const count = getHostSetCount();
await visit(urls.hostSet);
await click(selectors.MANAGE_DROPDOWN_HOST_SETS);
await click(selectors.MANAGE_DROPDOWN_HOST_SETS_DELETE);
assert.strictEqual(getHostSetCount(), count);
assert.ok(confirmService.confirm.calledOnce);
});
test('deleting a host set which errors displays error messages', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
this.server.del('/host-sets/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
},
);
});
await visit(urls.hostSet);
await click(selectors.MANAGE_DROPDOWN_HOST_SETS);
await click(selectors.MANAGE_DROPDOWN_HOST_SETS_DELETE);
assert.dom(commonSelectors.ALERT_TOAST_BODY).hasText('Oops.');
});
});