mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-13 18:17:02 +02:00
* UI: Part 1 - hds adoption replace <Modal> (#23363) * replace policy-form modal * replace clients/attribution modal * clients/config modal * scope form odal * remove button type * include toolbar to match other example templates * rotate credentials modal * add toolbar button class for hds buttons * transformation-edit modal * add back test selector * add route arg to button! * update link status * fix link-status tests * remove prevent default * update db tests * update tests * use page alert for hcp link status banner * fix scopy button selector * fix sidebar test * change to neutral banner * UI: Part 2 - hds adoption replace <Modal> (#23398) * upgrade HDS library (adds support for snippet containers * cleanup flight icons * replace transit key action modals * re-add deps as devDeps * remove line * address transit tests * UI: Part 3 - hds adoption replace <Modal> (#23415) * cleanup css * cleanup extra type attr * masked input download modal * use Hds::Button in download button" * fix size of modal * tiny icon fix * refactor download button to always render download icon * update tests * UI: Part 3.5 - hds adoption replace <Modal> (#23448) * replication-promote modal * replication component modals * replication add secondary modal * move update text for diff * UI: Part 4 - hds adoption replace <Modal> (#23451) * k8 configure modal * kv delete modal * ldap modals * pki modals * add trash icon * move deps * UI: Part 5 - hds adoption replace <Modal> (#23471) * replace confirmation modals --------- * UI: Part 6 - hds adoption replace <Modal> (#23484) * search select with modal * policy search select modal * replace date dropdown for client dashboard * change padding to top * update policy example args * lolllll test typo wow * update dropdown tests * shamir flow modals! * add one more container * update test selectors * UI: Final hds adoption replace <Modal> cleanup PR (#23522) * search select with modal * policy search select modal * replace date dropdown for client dashboard * change padding to top * update policy example args * lolllll test typo wow * update dropdown tests * shamir flow modals! * add one more container * update test selectors * remove wormhole and modal component * fix selectors * uninstall wormhole * remove shamir-modal-flow class * fix confirm modal test * fix pki and kv test * fix toolbar selector kv * client and download button test * fix-confirmation-modal-padding * fix replication modal tests so relevant modal opens (#23540) * more confirmation modal tests * adds changelog
134 lines
5.6 KiB
JavaScript
134 lines
5.6 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { module, test } from 'qunit';
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
import { render, focus, triggerKeyEvent, typeIn, fillIn, click } from '@ember/test-helpers';
|
|
import { create } from 'ember-cli-page-object';
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
import sinon from 'sinon';
|
|
import maskedInput from 'vault/tests/pages/components/masked-input';
|
|
|
|
const component = create(maskedInput);
|
|
|
|
module('Integration | Component | masked input', function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
hooks.beforeEach(function () {
|
|
this.flashMessages = this.owner.lookup('service:flash-messages');
|
|
this.flashMessages.registerTypes(['success', 'danger']);
|
|
this.flashSuccessSpy = sinon.spy(this.flashMessages, 'success');
|
|
this.flashDangerSpy = sinon.spy(this.flashMessages, 'danger');
|
|
});
|
|
|
|
test('it renders', async function (assert) {
|
|
await render(hbs`<MaskedInput />`);
|
|
assert.dom('[data-test-masked-input]').exists('shows masked input');
|
|
assert.ok(component.textareaIsPresent);
|
|
assert.dom('[data-test-textarea]').hasClass('masked-font', 'it renders an input with obscure font');
|
|
assert.notOk(component.copyButtonIsPresent, 'does not render copy button by default');
|
|
assert.notOk(component.downloadButtonIsPresent, 'does not render download button by default');
|
|
|
|
await component.toggleMasked();
|
|
assert.dom('.masked-value').doesNotHaveClass('masked-font', 'it unmasks when show button is clicked');
|
|
await component.toggleMasked();
|
|
assert.dom('.masked-value').hasClass('masked-font', 'it remasks text when button is clicked');
|
|
});
|
|
|
|
test('it renders correctly when displayOnly', async function (assert) {
|
|
this.set('value', 'value');
|
|
await render(hbs`<MaskedInput @displayOnly={{true}} @value={{this.value}} />`);
|
|
|
|
assert.dom('.masked-value').hasClass('masked-font', 'value has obscured font');
|
|
assert.notOk(component.textareaIsPresent, 'it does not render a textarea when displayOnly is true');
|
|
});
|
|
|
|
test('it renders a copy button when allowCopy is true', async function (assert) {
|
|
await render(hbs`<MaskedInput @allowCopy={{true}} />`);
|
|
assert.ok(component.copyButtonIsPresent);
|
|
});
|
|
|
|
test('it renders a download button when allowDownload is true', async function (assert) {
|
|
await render(hbs`<MaskedInput @allowDownload={{true}} /> `);
|
|
assert.ok(component.downloadIconIsPresent);
|
|
|
|
await click('[data-test-download-icon]');
|
|
assert.ok(component.downloadButtonIsPresent, 'clicking download icon opens modal with download button');
|
|
|
|
assert;
|
|
});
|
|
|
|
test('it shortens all outputs when displayOnly and masked', async function (assert) {
|
|
this.set('value', '123456789-123456789-123456789');
|
|
await render(hbs`<MaskedInput @value={{this.value}} @displayOnly={{true}} />`);
|
|
const maskedValue = document.querySelector('.masked-value').innerText;
|
|
assert.strictEqual(maskedValue.length, 11);
|
|
|
|
await component.toggleMasked();
|
|
const unMaskedValue = document.querySelector('.masked-value').innerText;
|
|
assert.strictEqual(unMaskedValue.length, this.value.length);
|
|
});
|
|
|
|
test('it does not unmask text on focus', async function (assert) {
|
|
this.set('value', '123456789-123456789-123456789');
|
|
await render(hbs`<MaskedInput @value={{this.value}} />`);
|
|
assert.dom('.masked-value').hasClass('masked-font');
|
|
await focus('.masked-value');
|
|
assert.dom('.masked-value').hasClass('masked-font');
|
|
});
|
|
|
|
test('it calls onChange events with the correct values', async function (assert) {
|
|
const changeSpy = sinon.spy();
|
|
this.set('value', 'before');
|
|
this.set('onChange', changeSpy);
|
|
await render(hbs`<MaskedInput @value={{this.value}} @onChange={{this.onChange}} />`);
|
|
await fillIn('[data-test-textarea]', 'after');
|
|
assert.true(changeSpy.calledWith('after'));
|
|
});
|
|
|
|
test('it calls onKeyUp events with the correct values', async function (assert) {
|
|
const keyupSpy = sinon.spy();
|
|
this.set('value', '');
|
|
this.set('onKeyUp', keyupSpy);
|
|
await render(hbs`<MaskedInput @name="foo" @value={{this.value}} @onKeyUp={{this.onKeyUp}} />`);
|
|
await typeIn('[data-test-textarea]', 'baz');
|
|
assert.true(keyupSpy.calledThrice, 'calls for each letter of typing');
|
|
assert.true(keyupSpy.firstCall.calledWithExactly('foo', 'b'));
|
|
assert.true(keyupSpy.secondCall.calledWithExactly('foo', 'ba'));
|
|
assert.true(keyupSpy.thirdCall.calledWithExactly('foo', 'baz'));
|
|
});
|
|
|
|
test('it does not remove value on tab', async function (assert) {
|
|
this.set('value', 'hello');
|
|
await render(hbs`<MaskedInput @value={{this.value}} />`);
|
|
await triggerKeyEvent('[data-test-textarea]', 'keydown', 9);
|
|
await component.toggleMasked();
|
|
const unMaskedValue = document.querySelector('.masked-value').value;
|
|
assert.strictEqual(unMaskedValue, this.value);
|
|
});
|
|
|
|
test('it renders a minus icon when an empty string is provided as a value', async function (assert) {
|
|
await render(hbs`
|
|
<MaskedInput
|
|
@name="key"
|
|
@value=""
|
|
@displayOnly={{true}}
|
|
@allowCopy={{true}}
|
|
@allowDownload={{true}}
|
|
/>
|
|
`);
|
|
assert.dom('[data-test-masked-input]').exists('shows masked input');
|
|
assert.ok(component.copyButtonIsPresent);
|
|
assert.ok(component.downloadIconIsPresent);
|
|
assert.dom('[data-test-button="toggle-masked"]').exists('shows toggle mask button');
|
|
|
|
await component.toggleMasked();
|
|
assert.dom('.masked-value').doesNotHaveClass('masked-font', 'it unmasks when show button is clicked');
|
|
assert
|
|
.dom('[data-test-icon="minus"]')
|
|
.exists('shows minus icon when unmasked because value is empty string');
|
|
});
|
|
});
|