vault/ui/tests/integration/components/unsaved-changes-modal-test.js
Vault Automation b057aac746
[VAULT-43339] 1/2 Chore update TS (#13050) (#13105)
* Initial ts updgrade

* Migrate linked-block to ts to squash ts errors

* [VAULT-43339] 2/2 Update vault-reporting and add ember-intl (#13062)

* Update vault-reporting and add ember-intl

* Add setupIntl for rendering tests

Co-authored-by: Jim Wright <jim.wright@hashicorp.com>
2026-03-17 15:52:40 -07:00

44 lines
1.8 KiB
JavaScript

/**
* Copyright IBM Corp. 2016, 2025
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupRenderingTest } from 'vault/tests/helpers';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { GENERAL } from 'vault/tests/helpers/general-selectors';
module('Integration | Component | UnsavedChangesModal', function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.unsavedChanges = this.owner.lookup('service:unsavedChanges');
this.unsavedChanges.showModal = true;
const initialState = { title: 'Title 1', description: 'Old description' };
const currentState = { title: 'Title 1', description: 'New description' };
this.unsavedChanges.initialState = initialState;
this.unsavedChanges.currentState = currentState;
this.save = () => 'saved!';
this.discard = () => 'discarded!';
});
test('it shows unsaved changes modal', async function (assert) {
await render(hbs`<UnsavedChangesModal @onSave={{this.save}} @onDiscard={{this.discard}} />`);
assert.dom(GENERAL.modal.header('unsaved-changes')).hasText('Unsaved changes');
assert
.dom(GENERAL.modal.body('unsaved-changes'))
.hasText(`You've made changes to the following: Description Would you like to apply them?`);
});
test('it shows unsaved changes modal with custom changedFields', async function (assert) {
await render(
hbs`<UnsavedChangesModal @onSave={{this.save}} @onDiscard={{this.discard}} @changedFields={{this.changedFields}}/>`
);
assert.dom(GENERAL.modal.header('unsaved-changes')).hasText('Unsaved changes');
assert
.dom(GENERAL.modal.body('unsaved-changes'))
.hasText(`You've made changes to the following: Description Would you like to apply them?`);
});
});