|
1 | 1 | import { hbs } from 'ember-cli-htmlbars';
|
2 | 2 | import { module, test } from 'qunit';
|
3 | 3 | import { setupRenderingTest } from 'ember-qunit';
|
4 |
| -import { render, setupOnerror, triggerKeyEvent } from '@ember/test-helpers'; |
| 4 | +import { render, setupOnerror, triggerEvent, triggerKeyEvent } from '@ember/test-helpers'; |
5 | 5 | import click from '@ember/test-helpers/dom/click';
|
6 | 6 | import sinon from 'sinon';
|
7 | 7 | import findAll from '@ember/test-helpers/dom/find-all';
|
8 | 8 | import typeIn from '@ember/test-helpers/dom/type-in';
|
9 | 9 | import settled from '@ember/test-helpers/settled';
|
10 | 10 |
|
11 |
| -module('Integration | Component | o-s-s/phone-number', function (hooks) { |
| 11 | +module('Integration | Component | o-s-s/phone-number-input', function (hooks) { |
12 | 12 | setupRenderingTest(hooks);
|
13 | 13 |
|
14 | 14 | hooks.beforeEach(function () {
|
@@ -115,6 +115,58 @@ module('Integration | Component | o-s-s/phone-number', function (hooks) {
|
115 | 115 | });
|
116 | 116 | });
|
117 | 117 |
|
| 118 | + module('When the paste event is received', function (hooks) { |
| 119 | + hooks.beforeEach(function () { |
| 120 | + this.onChange = () => {}; |
| 121 | + this.onValidation = sinon.spy(); |
| 122 | + this.number = '1234567890'; |
| 123 | + }); |
| 124 | + |
| 125 | + test('The value stored in the clipboard is inserted in the input', async function (assert) { |
| 126 | + await render( |
| 127 | + hbs`<OSS::PhoneNumberInput @prefix="" @number={{this.number}} @onChange={{this.onChange}} @validates={{this.onValidation}} />` |
| 128 | + ); |
| 129 | + assert.dom('input').hasValue('1234567890'); |
| 130 | + await triggerEvent('input', 'paste', { |
| 131 | + clipboardData: { |
| 132 | + getData: sinon.stub().returns('123') |
| 133 | + } |
| 134 | + }); |
| 135 | + |
| 136 | + assert.dom('input').hasValue('1234567890123'); |
| 137 | + }); |
| 138 | + |
| 139 | + test('The non-numeric characters are escaped', async function (assert) { |
| 140 | + await render( |
| 141 | + hbs`<OSS::PhoneNumberInput @prefix="" @number={{this.number}} @onChange={{this.onChange}} @validates={{this.onValidation}} />` |
| 142 | + ); |
| 143 | + assert.dom('input').hasValue('1234567890'); |
| 144 | + await triggerEvent('input', 'paste', { |
| 145 | + clipboardData: { |
| 146 | + getData: sinon.stub().returns('1withletter0') |
| 147 | + } |
| 148 | + }); |
| 149 | + |
| 150 | + assert.dom('input').hasValue('123456789010'); |
| 151 | + }); |
| 152 | + |
| 153 | + test('When selection is applied, it replaces the selection', async function (assert) { |
| 154 | + await render( |
| 155 | + hbs`<OSS::PhoneNumberInput @prefix="" @number={{this.number}} @onChange={{this.onChange}} @validates={{this.onValidation}} />` |
| 156 | + ); |
| 157 | + assert.dom('input').hasValue('1234567890'); |
| 158 | + let input = document.querySelector('input.ember-text-field') as HTMLInputElement; |
| 159 | + input.setSelectionRange(4, 6); |
| 160 | + await triggerEvent('input', 'paste', { |
| 161 | + clipboardData: { |
| 162 | + getData: sinon.stub().returns('0') |
| 163 | + } |
| 164 | + }); |
| 165 | + |
| 166 | + assert.dom('input').hasValue('123407890'); |
| 167 | + }); |
| 168 | + }); |
| 169 | + |
118 | 170 | module('@hasError parameter', () => {
|
119 | 171 | test('A red border is displayed if the parameter is true', async function (assert) {
|
120 | 172 | await render(hbs`<OSS::PhoneNumberInput @prefix="" @number="" @hasError={{true}}
|
|
0 commit comments