2018-09-25 16:28:26 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2021-08-24 14:59:37 +00:00
|
|
|
import { render, focus, triggerKeyEvent } from '@ember/test-helpers';
|
2018-06-14 18:52:00 +00:00
|
|
|
import { create } from 'ember-cli-page-object';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import maskedInput from 'vault/tests/pages/components/masked-input';
|
|
|
|
|
|
|
|
const component = create(maskedInput);
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
module('Integration | Component | masked input', function(hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('it renders', async function(assert) {
|
|
|
|
await render(hbs`{{masked-input}}`);
|
2021-04-22 14:58:37 +00:00
|
|
|
assert.dom('[data-test-masked-input]').exists('shows expiration beacon');
|
2018-09-25 16:28:26 +00:00
|
|
|
});
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('it renders a textarea', async function(assert) {
|
|
|
|
await render(hbs`{{masked-input}}`);
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.ok(component.textareaIsPresent);
|
|
|
|
});
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2021-04-22 14:58:37 +00:00
|
|
|
test('it renders an input with obscure font', async function(assert) {
|
|
|
|
await render(hbs`{{masked-input}}`);
|
|
|
|
|
|
|
|
assert.dom('[data-test-textarea]').hasClass('masked-font', 'loading class with correct font');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it renders obscure font when displayOnly', async function(assert) {
|
|
|
|
this.set('value', 'value');
|
|
|
|
await render(hbs`{{masked-input displayOnly=true value=value}}`);
|
|
|
|
|
|
|
|
assert.dom('.masked-value').hasClass('masked-font', 'loading class with correct font');
|
2020-10-07 16:27:41 +00:00
|
|
|
});
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('it does not render a textarea when displayOnly is true', async function(assert) {
|
|
|
|
await render(hbs`{{masked-input displayOnly=true}}`);
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.notOk(component.textareaIsPresent);
|
|
|
|
});
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-10-31 17:13:57 +00:00
|
|
|
test('it renders a copy button when allowCopy is true', async function(assert) {
|
|
|
|
await render(hbs`{{masked-input allowCopy=true}}`);
|
|
|
|
|
|
|
|
assert.ok(component.copyButtonIsPresent);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('it does not render a copy button when allowCopy is false', async function(assert) {
|
|
|
|
await render(hbs`{{masked-input allowCopy=false}}`);
|
|
|
|
|
|
|
|
assert.notOk(component.copyButtonIsPresent);
|
|
|
|
});
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('it unmasks text when button is clicked', async function(assert) {
|
|
|
|
this.set('value', 'value');
|
|
|
|
await render(hbs`{{masked-input value=value}}`);
|
|
|
|
await component.toggleMasked();
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2021-04-22 14:58:37 +00:00
|
|
|
assert.dom('.masked-value').doesNotHaveClass('masked-font');
|
2018-09-25 16:28:26 +00:00
|
|
|
});
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('it remasks text when button is clicked', async function(assert) {
|
|
|
|
this.set('value', 'value');
|
|
|
|
await render(hbs`{{masked-input value=value}}`);
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await component.toggleMasked();
|
|
|
|
await component.toggleMasked();
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2021-04-22 14:58:37 +00:00
|
|
|
assert.dom('.masked-value').hasClass('masked-font');
|
2018-09-25 16:28:26 +00:00
|
|
|
});
|
2020-10-07 16:27:41 +00:00
|
|
|
|
2021-04-22 14:58:37 +00:00
|
|
|
test('it shortens long outputs when displayOnly and masked', async function(assert) {
|
|
|
|
this.set('value', '123456789-123456789-123456789');
|
|
|
|
await render(hbs`{{masked-input value=value displayOnly=true}}`);
|
|
|
|
let maskedValue = document.querySelector('.masked-value').innerText;
|
|
|
|
assert.equal(maskedValue.length, 20);
|
|
|
|
|
2020-10-07 16:27:41 +00:00
|
|
|
await component.toggleMasked();
|
2021-04-22 14:58:37 +00:00
|
|
|
let unMaskedValue = document.querySelector('.masked-value').innerText;
|
|
|
|
assert.equal(unMaskedValue.length, this.value.length);
|
|
|
|
});
|
2020-10-07 16:27:41 +00:00
|
|
|
|
2021-04-22 14:58:37 +00:00
|
|
|
test('it does not unmask text on focus', async function(assert) {
|
|
|
|
this.set('value', '123456789-123456789-123456789');
|
|
|
|
await render(hbs`{{masked-input value=value}}`);
|
|
|
|
assert.dom('.masked-value').hasClass('masked-font');
|
|
|
|
await focus('.masked-value');
|
|
|
|
assert.dom('.masked-value').hasClass('masked-font');
|
2020-10-07 16:27:41 +00:00
|
|
|
});
|
2021-08-24 14:59:37 +00:00
|
|
|
|
|
|
|
test('it does not remove value on tab', async function(assert) {
|
|
|
|
this.set('value', 'hello');
|
|
|
|
await render(hbs`{{masked-input value=value}}`);
|
|
|
|
await triggerKeyEvent('[data-test-textarea]', 'keydown', 9);
|
|
|
|
await component.toggleMasked();
|
|
|
|
let unMaskedValue = document.querySelector('.masked-value').value;
|
|
|
|
assert.equal(unMaskedValue, this.value);
|
|
|
|
});
|
2018-06-14 18:52:00 +00:00
|
|
|
});
|