@spectrum-web-components/number-field 0.3.13 → 0.4.1-devmode.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,385 +1,375 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
- import { html } from '@spectrum-web-components/base';
13
- import { elementUpdated, expect } from '@open-wc/testing';
14
- import { createLanguageContext, getElFrom } from './helpers.js';
15
- import polyfillCheck from '@formatjs/intl-numberformat/should-polyfill.js';
16
- import '../sp-number-field.js';
17
- import { remapMultiByteCharacters } from '../';
18
- import { currency, decimals, Default, minMax, percents, } from '../stories/number-field.stories.js';
19
- import { sendKeys } from '@web/test-runner-commands';
20
- describe('NumberField - inputs', () => {
21
- before(async () => {
22
- if (polyfillCheck.shouldPolyfill()) {
23
- await import('@formatjs/intl-numberformat/polyfill.js');
24
- }
25
- if (Intl.NumberFormat.polyfilled) {
26
- await import('@formatjs/intl-numberformat/locale-data/en.js');
27
- await import('@formatjs/intl-numberformat/locale-data/es.js');
28
- }
29
- });
30
- describe('keystroke prevention', () => {
31
- it('converts 2 byte characters, default', async () => {
32
- const el = await getElFrom(html `
1
+ import { html } from "@spectrum-web-components/base";
2
+ import { elementUpdated, expect } from "@open-wc/testing";
3
+ import { createLanguageContext, getElFrom } from "./helpers.js";
4
+ import polyfillCheck from "@formatjs/intl-numberformat/should-polyfill.js";
5
+ import "@spectrum-web-components/number-field/sp-number-field.js";
6
+ import { remapMultiByteCharacters } from "@spectrum-web-components/number-field";
7
+ import {
8
+ currency,
9
+ decimals,
10
+ Default,
11
+ minMax,
12
+ percents
13
+ } from "../stories/number-field.stories.js";
14
+ import { sendKeys } from "@web/test-runner-commands";
15
+ describe("NumberField - inputs", () => {
16
+ before(async () => {
17
+ if (polyfillCheck.shouldPolyfill()) {
18
+ await import("@formatjs/intl-numberformat/polyfill.js");
19
+ }
20
+ if (Intl.NumberFormat.polyfilled) {
21
+ await import("@formatjs/intl-numberformat/locale-data/en.js");
22
+ await import("@formatjs/intl-numberformat/locale-data/es.js");
23
+ }
24
+ });
25
+ describe("keystroke prevention", () => {
26
+ it("converts 2 byte characters, default", async () => {
27
+ const el = await getElFrom(html`
33
28
  ${Default()}
34
29
  `);
35
- await elementUpdated(el);
36
- el.focus();
37
- await sendKeys({
38
- type: '3、567、890。1',
39
- });
40
- await elementUpdated(el);
41
- expect(el.formattedValue).to.equal('3,567,890.1');
42
- });
43
- it('converts 2 byte characters, percents', async () => {
44
- const el = await getElFrom(html `
30
+ await elementUpdated(el);
31
+ el.focus();
32
+ await sendKeys({
33
+ type: "\uFF13\u3001\uFF15\uFF16\uFF17\u3001\uFF18\uFF19\uFF10\u3002\uFF11"
34
+ });
35
+ await elementUpdated(el);
36
+ expect(el.formattedValue).to.equal("3,567,890.1");
37
+ });
38
+ it("converts 2 byte characters, percents", async () => {
39
+ const el = await getElFrom(html`
45
40
  ${percents()}
46
41
  `);
47
- await elementUpdated(el);
48
- el.focus();
49
- await sendKeys({
50
- type: '24%',
51
- });
52
- await elementUpdated(el);
53
- expect(el.formattedValue).to.equal('24%');
54
- });
55
- it('prevents second "." in EN', async () => {
56
- const el = await getElFrom(html `
42
+ await elementUpdated(el);
43
+ el.focus();
44
+ await sendKeys({
45
+ type: "\uFF12\uFF14\uFF05"
46
+ });
47
+ await elementUpdated(el);
48
+ expect(el.formattedValue).to.equal("24%");
49
+ });
50
+ it('prevents second "." in EN', async () => {
51
+ const el = await getElFrom(html`
57
52
  ${Default()}
58
53
  `);
59
- el.formatOptions = {
60
- maximumFractionDigits: 2,
61
- };
62
- await elementUpdated(el);
63
- el.focus();
64
- await sendKeys({
65
- type: '1.1.1',
66
- });
67
- await elementUpdated(el);
68
- expect(el.formattedValue).to.equal('1.11');
69
- });
70
- it('prevents text characters', async () => {
71
- const el = await getElFrom(html `
54
+ el.formatOptions = {
55
+ maximumFractionDigits: 2
56
+ };
57
+ await elementUpdated(el);
58
+ el.focus();
59
+ await sendKeys({
60
+ type: "1.1.1"
61
+ });
62
+ await elementUpdated(el);
63
+ expect(el.formattedValue).to.equal("1.11");
64
+ });
65
+ it("prevents text characters", async () => {
66
+ const el = await getElFrom(html`
72
67
  ${Default()}
73
68
  `);
74
- el.formatOptions = {
75
- maximumFractionDigits: 1,
76
- };
77
- await elementUpdated(el);
78
- el.focus();
79
- await sendKeys({
80
- type: 'D2.2',
81
- });
82
- await elementUpdated(el);
83
- expect(el.formattedValue).to.equal('2.2');
84
- el.value = NaN;
85
- await sendKeys({
86
- type: '8u23.s7',
87
- });
88
- await elementUpdated(el);
89
- expect(el.formattedValue).to.equal('823.7');
90
- });
91
- it('allows "-" to start', async () => {
92
- const el = await getElFrom(html `
69
+ el.formatOptions = {
70
+ maximumFractionDigits: 1
71
+ };
72
+ await elementUpdated(el);
73
+ el.focus();
74
+ await sendKeys({
75
+ type: "D2.2"
76
+ });
77
+ await elementUpdated(el);
78
+ expect(el.formattedValue).to.equal("2.2");
79
+ el.value = NaN;
80
+ await sendKeys({
81
+ type: "8u23.s7"
82
+ });
83
+ await elementUpdated(el);
84
+ expect(el.formattedValue).to.equal("823.7");
85
+ });
86
+ it('allows "-" to start', async () => {
87
+ const el = await getElFrom(html`
93
88
  ${Default()}
94
89
  `);
95
- await elementUpdated(el);
96
- el.focus();
97
- await sendKeys({
98
- type: '-54',
99
- });
100
- await elementUpdated(el);
101
- expect(el.formattedValue).to.equal('-54');
102
- });
103
- it('prevents "-" not at the start', async () => {
104
- const el = await getElFrom(html `
90
+ await elementUpdated(el);
91
+ el.focus();
92
+ await sendKeys({
93
+ type: "-54"
94
+ });
95
+ await elementUpdated(el);
96
+ expect(el.formattedValue).to.equal("-54");
97
+ });
98
+ it('prevents "-" not at the start', async () => {
99
+ const el = await getElFrom(html`
105
100
  ${Default()}
106
101
  `);
107
- await elementUpdated(el);
108
- el.focus();
109
- await sendKeys({
110
- type: '54-',
111
- });
112
- await elementUpdated(el);
113
- expect(el.formattedValue).to.equal('54');
114
- el.value = NaN;
115
- await sendKeys({
116
- type: '5-4',
117
- });
118
- await elementUpdated(el);
119
- expect(el.formattedValue).to.equal('54');
120
- });
121
- it('prevent "+" to start, normally', async () => {
122
- const el = await getElFrom(html `
102
+ await elementUpdated(el);
103
+ el.focus();
104
+ await sendKeys({
105
+ type: "54-"
106
+ });
107
+ await elementUpdated(el);
108
+ expect(el.formattedValue).to.equal("54");
109
+ el.value = NaN;
110
+ await sendKeys({
111
+ type: "5-4"
112
+ });
113
+ await elementUpdated(el);
114
+ expect(el.formattedValue).to.equal("54");
115
+ });
116
+ it('prevent "+" to start, normally', async () => {
117
+ const el = await getElFrom(html`
123
118
  ${Default()}
124
119
  `);
125
- await elementUpdated(el);
126
- el.focus();
127
- await sendKeys({
128
- type: '+54',
129
- });
130
- await elementUpdated(el);
131
- expect(el.formattedValue).to.equal('54');
132
- });
133
- it('allow "+" to start when "signDisplay: always"', async () => {
134
- const el = await getElFrom(html `
120
+ await elementUpdated(el);
121
+ el.focus();
122
+ await sendKeys({
123
+ type: "+54"
124
+ });
125
+ await elementUpdated(el);
126
+ expect(el.formattedValue).to.equal("54");
127
+ });
128
+ it('allow "+" to start when "signDisplay: always"', async () => {
129
+ const el = await getElFrom(html`
135
130
  ${Default()}
136
131
  `);
137
- await elementUpdated(el);
138
- el.formatOptions = {
139
- signDisplay: 'always',
140
- };
141
- el.focus();
142
- await sendKeys({
143
- type: '+54',
144
- });
145
- await elementUpdated(el);
146
- expect(el.formattedValue).to.equal('+54');
147
- });
148
- it('prevents "%" when when not percents', async () => {
149
- const el = await getElFrom(html `
132
+ await elementUpdated(el);
133
+ el.formatOptions = {
134
+ signDisplay: "always"
135
+ };
136
+ el.focus();
137
+ await sendKeys({
138
+ type: "+54"
139
+ });
140
+ await elementUpdated(el);
141
+ expect(el.formattedValue).to.equal("+54");
142
+ });
143
+ it('prevents "%" when when not percents', async () => {
144
+ const el = await getElFrom(html`
150
145
  ${Default()}
151
146
  `);
152
- await elementUpdated(el);
153
- el.focus();
154
- await sendKeys({
155
- type: '63%',
156
- });
157
- await elementUpdated(el);
158
- expect(el.formattedValue).to.equal('63');
159
- el.blur();
160
- await elementUpdated(el);
161
- expect(el.formattedValue).to.equal('63');
162
- });
163
- it('allows "%" when percents, and keeps "%" on blur', async () => {
164
- const el = await getElFrom(html `
147
+ await elementUpdated(el);
148
+ el.focus();
149
+ await sendKeys({
150
+ type: "63%"
151
+ });
152
+ await elementUpdated(el);
153
+ expect(el.formattedValue).to.equal("63");
154
+ el.blur();
155
+ await elementUpdated(el);
156
+ expect(el.formattedValue).to.equal("63");
157
+ });
158
+ it('allows "%" when percents, and keeps "%" on blur', async () => {
159
+ const el = await getElFrom(html`
165
160
  ${percents()}
166
161
  `);
167
- await elementUpdated(el);
168
- el.focus();
169
- await sendKeys({
170
- type: '63%',
171
- });
172
- await elementUpdated(el);
173
- expect(el.formattedValue).to.equal('63%');
174
- el.blur();
175
- await elementUpdated(el);
176
- expect(el.formattedValue).to.equal('63%');
177
- });
178
- it('prevents "Backspace" on curreny value text, and keeps currency value text of blur', async () => {
179
- const el = await getElFrom(html `
162
+ await elementUpdated(el);
163
+ el.focus();
164
+ await sendKeys({
165
+ type: "63%"
166
+ });
167
+ await elementUpdated(el);
168
+ expect(el.formattedValue).to.equal("63%");
169
+ el.blur();
170
+ await elementUpdated(el);
171
+ expect(el.formattedValue).to.equal("63%");
172
+ });
173
+ it('prevents "Backspace" on curreny value text, and keeps currency value text of blur', async () => {
174
+ const el = await getElFrom(html`
180
175
  ${currency({ value: 234.21 })}
181
176
  `);
182
- await elementUpdated(el);
183
- expect(el.formattedValue).to.equal('EUR 234.21');
184
- el.focus();
185
- el.inputElement.setSelectionRange(2, 2);
186
- await sendKeys({
187
- press: 'Backspace',
188
- });
189
- await elementUpdated(el);
190
- expect(el
191
- .inputElement.value).to.equal('EUR 234.21');
192
- el.blur();
193
- await elementUpdated(el);
194
- expect(el
195
- .inputElement.value).to.equal('EUR 234.21');
196
- });
197
- it('prevents "." when `maximumFractionDigits: 0`', async () => {
198
- const el = await getElFrom(html `
177
+ await elementUpdated(el);
178
+ expect(el.formattedValue).to.equal("EUR\xA0234.21");
179
+ el.focus();
180
+ el.inputElement.setSelectionRange(2, 2);
181
+ await sendKeys({
182
+ press: "Backspace"
183
+ });
184
+ await elementUpdated(el);
185
+ expect(el.inputElement.value).to.equal("EUR\xA0234.21");
186
+ el.blur();
187
+ await elementUpdated(el);
188
+ expect(el.inputElement.value).to.equal("EUR\xA0234.21");
189
+ });
190
+ it('prevents "." when `maximumFractionDigits: 0`', async () => {
191
+ const el = await getElFrom(html`
199
192
  ${Default()}
200
193
  `);
201
- await elementUpdated(el);
202
- el.formatOptions = {
203
- maximumFractionDigits: 0,
204
- };
205
- el.focus();
206
- await elementUpdated(el);
207
- await sendKeys({
208
- type: '5.2',
209
- });
210
- await elementUpdated(el);
211
- expect(el.formattedValue).to.equal('52');
212
- await sendKeys({
213
- press: 'Enter',
214
- });
215
- await elementUpdated(el);
216
- expect(el.value).to.equal(52);
217
- });
218
- xit('allow arabic numerals entered', async () => {
219
- // Safari requires more polyfilling for this text
220
- const el = await getElFrom(html `
194
+ await elementUpdated(el);
195
+ el.formatOptions = {
196
+ maximumFractionDigits: 0
197
+ };
198
+ el.focus();
199
+ await elementUpdated(el);
200
+ await sendKeys({
201
+ type: "5.2"
202
+ });
203
+ await elementUpdated(el);
204
+ expect(el.formattedValue).to.equal("52");
205
+ await sendKeys({
206
+ press: "Enter"
207
+ });
208
+ await elementUpdated(el);
209
+ expect(el.value).to.equal(52);
210
+ });
211
+ xit("allow arabic numerals entered", async () => {
212
+ const el = await getElFrom(html`
221
213
  ${Default()}
222
214
  `);
223
- await elementUpdated(el);
224
- el.focus();
225
- await elementUpdated(el);
226
- await sendKeys({
227
- type: '٢١',
228
- });
229
- await elementUpdated(el);
230
- expect(el.formattedValue).to.equal('21');
231
- await sendKeys({
232
- press: 'Enter',
233
- });
234
- await elementUpdated(el);
235
- expect(el.value).to.equal(21);
236
- });
237
- xit('allow hanidec numerals entered', async () => {
238
- // Safari requires more polyfilling for this text
239
- const el = await getElFrom(html `
215
+ await elementUpdated(el);
216
+ el.focus();
217
+ await elementUpdated(el);
218
+ await sendKeys({
219
+ type: "\u0662\u0661"
220
+ });
221
+ await elementUpdated(el);
222
+ expect(el.formattedValue).to.equal("21");
223
+ await sendKeys({
224
+ press: "Enter"
225
+ });
226
+ await elementUpdated(el);
227
+ expect(el.value).to.equal(21);
228
+ });
229
+ xit("allow hanidec numerals entered", async () => {
230
+ const el = await getElFrom(html`
240
231
  ${Default()}
241
232
  `);
242
- await elementUpdated(el);
243
- el.focus();
244
- await elementUpdated(el);
245
- await sendKeys({
246
- type: '二一',
247
- });
248
- await elementUpdated(el);
249
- expect(el.formattedValue).to.equal('21');
250
- await sendKeys({
251
- press: 'Enter',
252
- });
253
- await elementUpdated(el);
254
- expect(el.value).to.equal(21);
255
- });
233
+ await elementUpdated(el);
234
+ el.focus();
235
+ await elementUpdated(el);
236
+ await sendKeys({
237
+ type: "\u4E8C\u4E00"
238
+ });
239
+ await elementUpdated(el);
240
+ expect(el.formattedValue).to.equal("21");
241
+ await sendKeys({
242
+ press: "Enter"
243
+ });
244
+ await elementUpdated(el);
245
+ expect(el.value).to.equal(21);
256
246
  });
257
- describe('user suplied large numbers', () => {
258
- it('do not crash the Number Field', async () => {
259
- const el = await getElFrom(minMax(minMax.args));
260
- await elementUpdated(el);
261
- el.focus();
262
- await sendKeys({
263
- type: '12345678901234567890',
264
- });
265
- await elementUpdated(el);
266
- expect(el.formattedValue).to.equal('255');
267
- await sendKeys({
268
- press: 'Enter',
269
- });
270
- await elementUpdated(el);
271
- expect(el.value).to.equal(255);
272
- });
247
+ });
248
+ describe("user suplied large numbers", () => {
249
+ it("do not crash the Number Field", async () => {
250
+ const el = await getElFrom(minMax(minMax.args));
251
+ await elementUpdated(el);
252
+ el.focus();
253
+ await sendKeys({
254
+ type: "12345678901234567890"
255
+ });
256
+ await elementUpdated(el);
257
+ expect(el.formattedValue).to.equal("255");
258
+ await sendKeys({
259
+ press: "Enter"
260
+ });
261
+ await elementUpdated(el);
262
+ expect(el.value).to.equal(255);
273
263
  });
274
- describe('locale specific', () => {
275
- it('can determine the group symbol', async () => {
276
- const languageContext = createLanguageContext('es-ES');
277
- const el = await getElFrom(html `
264
+ });
265
+ describe("locale specific", () => {
266
+ it("can determine the group symbol", async () => {
267
+ const languageContext = createLanguageContext("es-ES");
268
+ const el = await getElFrom(html`
278
269
  <div @sp-language-context=${languageContext}>${Default()}</div>
279
270
  `);
280
- await elementUpdated(el);
281
- el.focus();
282
- await sendKeys({
283
- type: '123.456.789',
284
- });
285
- await elementUpdated(el);
286
- expect(el.formattedValue).to.equal('123.456.789');
287
- await sendKeys({
288
- press: 'Tab',
289
- });
290
- await elementUpdated(el);
291
- expect(el.formattedValue).to.equal('123.456.789');
292
- });
271
+ await elementUpdated(el);
272
+ el.focus();
273
+ await sendKeys({
274
+ type: "123.456.789"
275
+ });
276
+ await elementUpdated(el);
277
+ expect(el.formattedValue).to.equal("123.456.789");
278
+ await sendKeys({
279
+ press: "Tab"
280
+ });
281
+ await elementUpdated(el);
282
+ expect(el.formattedValue).to.equal("123.456.789");
283
+ });
284
+ });
285
+ describe("2-byte characters", () => {
286
+ const numbers = Object.keys(remapMultiByteCharacters);
287
+ numbers.splice(10);
288
+ numbers.forEach((input) => {
289
+ const actual = remapMultiByteCharacters[input];
290
+ it(`accepts "${input}" as "${actual}"`, async () => {
291
+ const el = await getElFrom(Default());
292
+ el.focusElement.value = input;
293
+ el.focusElement.dispatchEvent(new Event("input", {
294
+ bubbles: true,
295
+ cancelable: true,
296
+ composed: true
297
+ }));
298
+ await elementUpdated(el);
299
+ expect(el.formattedValue).to.equal(actual);
300
+ expect(el.value).to.equal(Number(actual));
301
+ });
302
+ });
303
+ it('accepts "\u3001" as "," and "\u3002" as "."', async () => {
304
+ const el = await getElFrom(Default(Default.args));
305
+ el.focusElement.value = "\uFF11\u3001\uFF12\uFF13\uFF14\u3002\uFF156";
306
+ el.focusElement.dispatchEvent(new Event("input", {
307
+ bubbles: true,
308
+ cancelable: true,
309
+ composed: true
310
+ }));
311
+ await elementUpdated(el);
312
+ expect(el.formattedValue).to.equal("1,234.56");
313
+ expect(el.value).to.equal(Number(1234.56));
314
+ });
315
+ it('accepts misplaced "\u3001" and corrects them', async () => {
316
+ const el = await getElFrom(Default(Default.args));
317
+ const nextFocusableElement = document.createElement("input");
318
+ el.insertAdjacentElement("afterend", nextFocusableElement);
319
+ el.focus();
320
+ await elementUpdated(el);
321
+ el.focusElement.value = "\uFF11\uFF12\u3001\uFF13\uFF14\uFF15\uFF16\u3001\uFF17\u3002\uFF18\uFF19";
322
+ el.focusElement.dispatchEvent(new Event("input", {
323
+ bubbles: true,
324
+ cancelable: true,
325
+ composed: true
326
+ }));
327
+ await elementUpdated(el);
328
+ expect(el.focusElement.value, "visible").to.equal("12,3456,7.89");
329
+ expect(el.formattedValue, "tracked").to.equal("1,234,567.89");
330
+ expect(el.value, "value").to.equal(Number(123456789e-2));
331
+ await sendKeys({
332
+ press: "Tab"
333
+ });
334
+ await elementUpdated(el);
335
+ expect(el.focusElement.value, "visible").to.equal("1,234,567.89");
336
+ expect(el.formattedValue, "tracked").to.equal("1,234,567.89");
337
+ expect(el.value, "value").to.equal(Number(123456789e-2));
338
+ nextFocusableElement.remove();
339
+ });
340
+ it('accepts "\uFF0B" as "+" and "\u30FC" as "-"', async () => {
341
+ const el = await getElFrom(decimals(decimals.args));
342
+ el.focusElement.value = "\uFF0B\uFF19\u3002\uFF18\uFF17";
343
+ el.focusElement.dispatchEvent(new Event("input", {
344
+ bubbles: true,
345
+ cancelable: true,
346
+ composed: true
347
+ }));
348
+ await elementUpdated(el);
349
+ expect(el.formattedValue).to.equal("+9.87");
350
+ expect(el.value).to.equal(Number(9.87));
351
+ el.focusElement.value = "\u30FC\uFF19\uFF0E\uFF18\uFF17";
352
+ el.focusElement.dispatchEvent(new Event("input", {
353
+ bubbles: true,
354
+ cancelable: true,
355
+ composed: true
356
+ }));
357
+ await elementUpdated(el);
358
+ expect(el.formattedValue).to.equal("-9.87");
359
+ expect(el.value).to.equal(Number(-9.87));
293
360
  });
294
- describe('2-byte characters', () => {
295
- const numbers = Object.keys(remapMultiByteCharacters);
296
- // only `1`-`0` can be accepted as single key inputs.
297
- numbers.splice(10);
298
- numbers.forEach((input) => {
299
- const actual = remapMultiByteCharacters[input];
300
- it(`accepts "${input}" as "${actual}"`, async () => {
301
- const el = await getElFrom(Default());
302
- el.focusElement.value = input;
303
- el.focusElement.dispatchEvent(new Event('input', {
304
- bubbles: true,
305
- cancelable: true,
306
- composed: true,
307
- }));
308
- await elementUpdated(el);
309
- expect(el.formattedValue).to.equal(actual);
310
- expect(el.value).to.equal(Number(actual));
311
- });
312
- });
313
- it('accepts "、" as "," and "。" as "."', async () => {
314
- const el = await getElFrom(Default(Default.args));
315
- el.focusElement.value = '1、234。56';
316
- el.focusElement.dispatchEvent(new Event('input', {
317
- bubbles: true,
318
- cancelable: true,
319
- composed: true,
320
- }));
321
- await elementUpdated(el);
322
- expect(el.formattedValue).to.equal('1,234.56');
323
- expect(el.value).to.equal(Number(1234.56));
324
- });
325
- it('accepts misplaced "、" and corrects them', async () => {
326
- const el = await getElFrom(Default(Default.args));
327
- const nextFocusableElement = document.createElement('input');
328
- el.insertAdjacentElement('afterend', nextFocusableElement);
329
- el.focus();
330
- await elementUpdated(el);
331
- el.focusElement.value = '12、3456、7。89';
332
- el.focusElement.dispatchEvent(new Event('input', {
333
- bubbles: true,
334
- cancelable: true,
335
- composed: true,
336
- }));
337
- await elementUpdated(el);
338
- expect(el.focusElement.value, 'visible').to.equal('12,3456,7.89');
339
- expect(el.formattedValue, 'tracked').to.equal('1,234,567.89');
340
- expect(el.value, 'value').to.equal(Number(1234567.89));
341
- await sendKeys({
342
- press: 'Tab',
343
- });
344
- await elementUpdated(el);
345
- expect(el.focusElement.value, 'visible').to.equal('1,234,567.89');
346
- expect(el.formattedValue, 'tracked').to.equal('1,234,567.89');
347
- expect(el.value, 'value').to.equal(Number(1234567.89));
348
- nextFocusableElement.remove();
349
- });
350
- it('accepts "+" as "+" and "ー" as "-"', async () => {
351
- const el = await getElFrom(decimals(decimals.args));
352
- el.focusElement.value = '+9。87';
353
- el.focusElement.dispatchEvent(new Event('input', {
354
- bubbles: true,
355
- cancelable: true,
356
- composed: true,
357
- }));
358
- await elementUpdated(el);
359
- expect(el.formattedValue).to.equal('+9.87');
360
- expect(el.value).to.equal(Number(9.87));
361
- el.focusElement.value = 'ー9.87';
362
- el.focusElement.dispatchEvent(new Event('input', {
363
- bubbles: true,
364
- cancelable: true,
365
- composed: true,
366
- }));
367
- await elementUpdated(el);
368
- expect(el.formattedValue).to.equal('-9.87');
369
- expect(el.value).to.equal(Number(-9.87));
370
- });
371
- it('accepts "%" as "%"', async () => {
372
- const el = await getElFrom(percents(percents.args));
373
- el.focusElement.value = '10%';
374
- el.focusElement.dispatchEvent(new Event('input', {
375
- bubbles: true,
376
- cancelable: true,
377
- composed: true,
378
- }));
379
- await elementUpdated(el);
380
- expect(el.formattedValue).to.equal('10%');
381
- expect(el.value).to.equal(Number(0.1));
382
- });
361
+ it('accepts "\uFF05" as "%"', async () => {
362
+ const el = await getElFrom(percents(percents.args));
363
+ el.focusElement.value = "\uFF11\uFF10\uFF05";
364
+ el.focusElement.dispatchEvent(new Event("input", {
365
+ bubbles: true,
366
+ cancelable: true,
367
+ composed: true
368
+ }));
369
+ await elementUpdated(el);
370
+ expect(el.formattedValue).to.equal("10%");
371
+ expect(el.value).to.equal(Number(0.1));
383
372
  });
373
+ });
384
374
  });
385
- //# sourceMappingURL=inputs.test.js.map
375
+ //# sourceMappingURL=inputs.test.js.map