2018-09-25 16:28:26 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render } 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
|
|
|
const hasClass = (classString = '', classToFind) => {
|
|
|
|
return classString.split(' ').includes(classToFind);
|
|
|
|
};
|
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}}`);
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.ok(hasClass(component.wrapperClass, 'masked'));
|
|
|
|
});
|
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
|
|
|
|
2020-10-07 16:27:41 +00:00
|
|
|
test('it renders an input with type password when maskWhileTyping is true', async function(assert) {
|
|
|
|
await render(hbs`{{masked-input maskWhileTyping=true}}`);
|
|
|
|
assert.ok(component.inputIsPresent);
|
|
|
|
assert.equal(
|
|
|
|
this.element.querySelector('input').getAttribute('type'),
|
|
|
|
'password',
|
|
|
|
'default type equals password'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
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 on focus', async function(assert) {
|
|
|
|
this.set('value', 'value');
|
|
|
|
await render(hbs`{{masked-input value=value}}`);
|
|
|
|
assert.ok(hasClass(component.wrapperClass, 'masked'));
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await component.focusField();
|
|
|
|
assert.notOk(hasClass(component.wrapperClass, 'masked'));
|
|
|
|
});
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('it remasks text on blur', 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
|
|
|
assert.ok(hasClass(component.wrapperClass, 'masked'));
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await component.focusField();
|
|
|
|
await component.blurField();
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.ok(hasClass(component.wrapperClass, 'masked'));
|
|
|
|
});
|
2018-06-14 18:52:00 +00:00
|
|
|
|
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}}`);
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.ok(hasClass(component.wrapperClass, 'masked'));
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
await component.toggleMasked();
|
2018-06-14 18:52:00 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.notOk(hasClass(component.wrapperClass, 'masked'));
|
|
|
|
});
|
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
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.ok(hasClass(component.wrapperClass, 'masked'));
|
|
|
|
});
|
2020-10-07 16:27:41 +00:00
|
|
|
|
|
|
|
test('it changes type to text when unmasked button is clicked', async function(assert) {
|
|
|
|
this.set('value', 'value');
|
|
|
|
await render(hbs`{{masked-input value=value maskWhileTyping=true}}`);
|
|
|
|
await component.toggleMasked();
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
this.element.querySelector('input').getAttribute('type'),
|
|
|
|
'text',
|
|
|
|
'when unmasked type changes to text'
|
|
|
|
);
|
|
|
|
});
|
2018-06-14 18:52:00 +00:00
|
|
|
});
|