/** * Copyright (c) HashiCorp, Inc. * SPDX-License-Identifier: BUSL-1.1 */ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { render, click, find } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; import sinon from 'sinon'; import { setRunOptions } from 'ember-a11y-testing/test-support'; const SELECTORS = { modalToggle: '[data-test-confirm-action-trigger]', title: '[data-test-confirm-action-title]', message: '[data-test-confirm-action-message]', confirm: '[data-test-confirm-button]', cancel: '[data-test-confirm-cancel-button]', }; module('Integration | Component | confirm-action', function (hooks) { setupRenderingTest(hooks); hooks.beforeEach(function () { this.onConfirm = sinon.spy(); }); test('it renders defaults and calls onConfirmAction', async function (assert) { await render(hbs` `); assert.dom(SELECTORS.modalToggle).hasText('DELETE', 'renders button text'); await click(SELECTORS.modalToggle); // hasClass assertion wasn't working so this is the workaround assert.strictEqual( find('#confirm-action-modal').className, 'hds-modal hds-modal--size-small hds-modal--color-critical has-text-left', 'renders critical modal color by default' ); assert.strictEqual( find(SELECTORS.confirm).className, 'hds-button hds-button--size-medium hds-button--color-critical', 'renders critical confirm button' ); assert.dom(SELECTORS.title).hasText('Are you sure?', 'renders default title'); assert .dom(SELECTORS.message) .hasText('You will not be able to recover it later.', 'renders default body text'); await click(SELECTORS.cancel); assert.false(this.onConfirm.called, 'does not call the action when Cancel is clicked'); await click(SELECTORS.modalToggle); await click(SELECTORS.confirm); assert.true(this.onConfirm.called, 'calls the action when Confirm is clicked'); assert.dom(SELECTORS.title).doesNotExist('modal closes after confirm is clicked'); }); test('it renders isInDropdown defaults and calls onConfirmAction', async function (assert) { setRunOptions({ rules: { // this component breaks this rule because it expects to be rendered within