@spectrum-web-components/number-field 0.3.7 → 0.3.8
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.
- package/package.json +5 -5
- package/test/benchmark/basic-test.js +18 -0
- package/test/benchmark/basic-test.js.map +1 -0
- package/test/helpers.js +66 -0
- package/test/helpers.js.map +1 -0
- package/test/inputs.test.js +385 -0
- package/test/inputs.test.js.map +1 -0
- package/test/number-field.test-vrt.js +15 -0
- package/test/number-field.test-vrt.js.map +1 -0
- package/test/number-field.test.js +1143 -0
- package/test/number-field.test.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/number-field",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@internationalized/number": "^3.0.2",
|
|
48
|
-
"@spectrum-web-components/action-button": "^0.8.
|
|
48
|
+
"@spectrum-web-components/action-button": "^0.8.2",
|
|
49
49
|
"@spectrum-web-components/base": "^0.5.4",
|
|
50
50
|
"@spectrum-web-components/icon": "^0.11.5",
|
|
51
51
|
"@spectrum-web-components/icons-ui": "^0.8.5",
|
|
52
|
-
"@spectrum-web-components/shared": "^0.13.
|
|
53
|
-
"@spectrum-web-components/textfield": "^0.11.
|
|
52
|
+
"@spectrum-web-components/shared": "^0.13.7",
|
|
53
|
+
"@spectrum-web-components/textfield": "^0.11.4",
|
|
54
54
|
"tslib": "^2.0.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"sideEffects": [
|
|
63
63
|
"./sp-*.js"
|
|
64
64
|
],
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "dd76f9532fdea946880147cc7645f113b998c326"
|
|
66
66
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 '@spectrum-web-components/number-field/sp-number-field.js';
|
|
13
|
+
import { html } from 'lit';
|
|
14
|
+
import { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';
|
|
15
|
+
measureFixtureCreation(html `
|
|
16
|
+
<sp-number-field></sp-number-field>
|
|
17
|
+
`);
|
|
18
|
+
//# sourceMappingURL=basic-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-test.js","sourceRoot":"","sources":["basic-test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,0DAA0D,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,sBAAsB,CAAC,IAAI,CAAA;;CAE1B,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport '@spectrum-web-components/number-field/sp-number-field.js';\nimport { html } from 'lit';\nimport { measureFixtureCreation } from '../../../../test/benchmark/helpers.js';\n\nmeasureFixtureCreation(html`\n <sp-number-field></sp-number-field>\n`);\n"]}
|
package/test/helpers.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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, fixture, nextFrame } from '@open-wc/testing';
|
|
14
|
+
import { sendMouse } from '../../../test/plugins/browser.js';
|
|
15
|
+
export async function getElFrom(test) {
|
|
16
|
+
const wrapped = await fixture(html `
|
|
17
|
+
<div style="--spectrum-alias-ui-icon-chevron-size-75: 20px;">
|
|
18
|
+
${test}
|
|
19
|
+
</div>
|
|
20
|
+
`);
|
|
21
|
+
const el = wrapped.querySelector('sp-number-field');
|
|
22
|
+
await elementUpdated(el);
|
|
23
|
+
return el;
|
|
24
|
+
}
|
|
25
|
+
export async function clickBySelector(el, selector, options = {}) {
|
|
26
|
+
const target = el.shadowRoot.querySelector(selector);
|
|
27
|
+
const targetRect = target.getBoundingClientRect();
|
|
28
|
+
await sendMouse({
|
|
29
|
+
steps: [
|
|
30
|
+
{
|
|
31
|
+
type: 'move',
|
|
32
|
+
position: [
|
|
33
|
+
targetRect.x + targetRect.width / 2,
|
|
34
|
+
targetRect.y + targetRect.height / 2,
|
|
35
|
+
],
|
|
36
|
+
options,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: 'down',
|
|
40
|
+
options,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
await nextFrame();
|
|
45
|
+
await sendMouse({
|
|
46
|
+
steps: [
|
|
47
|
+
{
|
|
48
|
+
type: 'up',
|
|
49
|
+
options,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
await elementUpdated(el);
|
|
54
|
+
}
|
|
55
|
+
export function createLanguageContext(lang) {
|
|
56
|
+
const langResolvers = [];
|
|
57
|
+
const createLangResolver = (event) => {
|
|
58
|
+
langResolvers.push(event.detail.callback);
|
|
59
|
+
resolveLanguage();
|
|
60
|
+
};
|
|
61
|
+
const resolveLanguage = () => {
|
|
62
|
+
langResolvers.forEach((resolver) => resolver(lang));
|
|
63
|
+
};
|
|
64
|
+
return createLangResolver;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,IAAI,EAAkB,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGtE,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAoB;IAChD,MAAM,OAAO,GAAG,MAAM,OAAO,CAAiB,IAAI,CAAA;;cAExC,IAAI;;KAEb,CAAC,CAAC;IACH,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,iBAAiB,CAAgB,CAAC;IACnE,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;IACzB,OAAO,EAAE,C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Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html, TemplateResult } from '@spectrum-web-components/base';\nimport { elementUpdated, fixture, nextFrame } from '@open-wc/testing';\nimport { ProvideLang } from '@spectrum-web-components/theme';\nimport { NumberField } from '../';\nimport { sendMouse } from '../../../test/plugins/browser.js';\n\nexport async function getElFrom(test: TemplateResult): Promise<NumberField> {\n const wrapped = await fixture<HTMLDivElement>(html`\n <div style=\"--spectrum-alias-ui-icon-chevron-size-75: 20px;\">\n ${test}\n </div>\n `);\n const el = wrapped.querySelector('sp-number-field') as NumberField;\n await elementUpdated(el);\n return el;\n}\n\nexport async function clickBySelector(\n el: NumberField,\n selector: string,\n options: { button?: 'left' | 'right' | 'middle' } = {}\n): Promise<void> {\n const target = el.shadowRoot.querySelector(selector) as HTMLElement;\n const targetRect = target.getBoundingClientRect();\n await sendMouse({\n steps: [\n {\n type: 'move',\n position: [\n targetRect.x + targetRect.width / 2,\n targetRect.y + targetRect.height / 2,\n ],\n options,\n },\n {\n type: 'down',\n options,\n },\n ],\n });\n await nextFrame();\n await sendMouse({\n steps: [\n {\n type: 'up',\n options,\n },\n ],\n });\n await elementUpdated(el);\n}\n\nexport function createLanguageContext(\n lang: string\n): (event: CustomEvent<ProvideLang>) => void {\n const langResolvers: ProvideLang['callback'][] = [];\n const createLangResolver = (event: CustomEvent<ProvideLang>): void => {\n langResolvers.push(event.detail.callback);\n resolveLanguage();\n };\n const resolveLanguage = (): void => {\n langResolvers.forEach((resolver) => resolver(lang));\n };\n return createLangResolver;\n}\n"]}
|
|
@@ -0,0 +1,385 @@
|
|
|
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 `
|
|
33
|
+
${Default()}
|
|
34
|
+
`);
|
|
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 `
|
|
45
|
+
${percents()}
|
|
46
|
+
`);
|
|
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 `
|
|
57
|
+
${Default()}
|
|
58
|
+
`);
|
|
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 `
|
|
72
|
+
${Default()}
|
|
73
|
+
`);
|
|
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 `
|
|
93
|
+
${Default()}
|
|
94
|
+
`);
|
|
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 `
|
|
105
|
+
${Default()}
|
|
106
|
+
`);
|
|
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 `
|
|
123
|
+
${Default()}
|
|
124
|
+
`);
|
|
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 `
|
|
135
|
+
${Default()}
|
|
136
|
+
`);
|
|
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 `
|
|
150
|
+
${Default()}
|
|
151
|
+
`);
|
|
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 `
|
|
165
|
+
${percents()}
|
|
166
|
+
`);
|
|
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 `
|
|
180
|
+
${currency({ value: 234.21 })}
|
|
181
|
+
`);
|
|
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 `
|
|
199
|
+
${Default()}
|
|
200
|
+
`);
|
|
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 `
|
|
221
|
+
${Default()}
|
|
222
|
+
`);
|
|
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 `
|
|
240
|
+
${Default()}
|
|
241
|
+
`);
|
|
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
|
+
});
|
|
256
|
+
});
|
|
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
|
+
});
|
|
273
|
+
});
|
|
274
|
+
describe('locale specific', () => {
|
|
275
|
+
it('can determine the group symbol', async () => {
|
|
276
|
+
const languageContext = createLanguageContext('es-ES');
|
|
277
|
+
const el = await getElFrom(html `
|
|
278
|
+
<div @sp-language-context=${languageContext}>${Default()}</div>
|
|
279
|
+
`);
|
|
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
|
+
});
|
|
293
|
+
});
|
|
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
|
+
});
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|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cAAc,CAAC,EAAE,CAAC,CAAC;YAEzB,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC5C,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,oBAAoB,EAAE,KAAK,IAAI,EAAE;YAChC,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YACpD,EAAE,CAAC,YAAY,CAAC,KAAK,GAAG,KAAK,CAAC;YAC9B,EAAE,CAAC,YAAY,CAAC,aAAa,CACzB,IAAI,KAAK,CAAC,OAAO,EAAE;gBACf,OAAO,EAAE,IAAI;gBACb,UAAU,EAAE,IAAI;gBAChB,QAAQ,EAAE,IAAI;aACjB,CAAC,CACL,CAAC;YACF,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;YAEzB,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1C,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { html } from '@spectrum-web-components/base';\nimport { elementUpdated, expect } from '@open-wc/testing';\nimport { createLanguageContext, getElFrom } from './helpers.js';\nimport polyfillCheck from '@formatjs/intl-numberformat/should-polyfill.js';\n\nimport '../sp-number-field.js';\nimport { remapMultiByteCharacters } from '../';\nimport {\n currency,\n decimals,\n Default,\n minMax,\n percents,\n} from '../stories/number-field.stories.js';\nimport { sendKeys } from '@web/test-runner-commands';\n\ndescribe('NumberField - inputs', () => {\n before(async () => {\n if (polyfillCheck.shouldPolyfill()) {\n await import('@formatjs/intl-numberformat/polyfill.js');\n }\n if (\n (Intl.NumberFormat as unknown as { polyfilled: boolean }).polyfilled\n ) {\n await import('@formatjs/intl-numberformat/locale-data/en.js');\n await import('@formatjs/intl-numberformat/locale-data/es.js');\n }\n });\n describe('keystroke prevention', () => {\n it('converts 2 byte characters, default', async () => {\n const el = await getElFrom(html`\n ${Default()}\n `);\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '3、567、890。1',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('3,567,890.1');\n });\n it('converts 2 byte characters, percents', async () => {\n const el = await getElFrom(html`\n ${percents()}\n `);\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '24%',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('24%');\n });\n it('prevents second \".\" in EN', async () => {\n const el = await getElFrom(html`\n ${Default()}\n `);\n el.formatOptions = {\n maximumFractionDigits: 2,\n };\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '1.1.1',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('1.11');\n });\n it('prevents text characters', async () => {\n const el = await getElFrom(html`\n ${Default()}\n `);\n el.formatOptions = {\n maximumFractionDigits: 1,\n };\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: 'D2.2',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('2.2');\n\n el.value = NaN;\n\n await sendKeys({\n type: '8u23.s7',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('823.7');\n });\n it('allows \"-\" to start', async () => {\n const el = await getElFrom(html`\n ${Default()}\n `);\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '-54',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('-54');\n });\n it('prevents \"-\" not at the start', async () => {\n const el = await getElFrom(html`\n ${Default()}\n `);\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '54-',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('54');\n\n el.value = NaN;\n\n await sendKeys({\n type: '5-4',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('54');\n });\n it('prevent \"+\" to start, normally', async () => {\n const el = await getElFrom(html`\n ${Default()}\n `);\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '+54',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('54');\n });\n it('allow \"+\" to start when \"signDisplay: always\"', async () => {\n const el = await getElFrom(html`\n ${Default()}\n `);\n await elementUpdated(el);\n el.formatOptions = {\n signDisplay: 'always',\n };\n el.focus();\n await sendKeys({\n type: '+54',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('+54');\n });\n it('prevents \"%\" when when not percents', async () => {\n const el = await getElFrom(html`\n ${Default()}\n `);\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '63%',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('63');\n el.blur();\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('63');\n });\n it('allows \"%\" when percents, and keeps \"%\" on blur', async () => {\n const el = await getElFrom(html`\n ${percents()}\n `);\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '63%',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('63%');\n el.blur();\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('63%');\n });\n it('prevents \"Backspace\" on curreny value text, and keeps currency value text of blur', async () => {\n const el = await getElFrom(html`\n ${currency({ value: 234.21 })}\n `);\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('EUR 234.21');\n\n el.focus();\n (\n el as unknown as {\n inputElement: HTMLInputElement;\n }\n ).inputElement.setSelectionRange(2, 2);\n await sendKeys({\n press: 'Backspace',\n });\n await elementUpdated(el);\n expect(\n (el as unknown as { inputElement: HTMLInputElement })\n .inputElement.value\n ).to.equal('EUR 234.21');\n el.blur();\n await elementUpdated(el);\n expect(\n (el as unknown as { inputElement: HTMLInputElement })\n .inputElement.value\n ).to.equal('EUR 234.21');\n });\n it('prevents \".\" when `maximumFractionDigits: 0`', async () => {\n const el = await getElFrom(html`\n ${Default()}\n `);\n await elementUpdated(el);\n el.formatOptions = {\n maximumFractionDigits: 0,\n };\n el.focus();\n await elementUpdated(el);\n await sendKeys({\n type: '5.2',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('52');\n await sendKeys({\n press: 'Enter',\n });\n await elementUpdated(el);\n expect(el.value).to.equal(52);\n });\n xit('allow arabic numerals entered', async () => {\n // Safari requires more polyfilling for this text\n const el = await getElFrom(html`\n ${Default()}\n `);\n await elementUpdated(el);\n\n el.focus();\n await elementUpdated(el);\n await sendKeys({\n type: '٢١',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('21');\n await sendKeys({\n press: 'Enter',\n });\n await elementUpdated(el);\n expect(el.value).to.equal(21);\n });\n xit('allow hanidec numerals entered', async () => {\n // Safari requires more polyfilling for this text\n const el = await getElFrom(html`\n ${Default()}\n `);\n await elementUpdated(el);\n\n el.focus();\n await elementUpdated(el);\n await sendKeys({\n type: '二一',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('21');\n await sendKeys({\n press: 'Enter',\n });\n await elementUpdated(el);\n expect(el.value).to.equal(21);\n });\n });\n describe('user suplied large numbers', () => {\n it('do not crash the Number Field', async () => {\n const el = await getElFrom(minMax(minMax.args));\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '12345678901234567890',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('255');\n await sendKeys({\n press: 'Enter',\n });\n await elementUpdated(el);\n expect(el.value).to.equal(255);\n });\n });\n describe('locale specific', () => {\n it('can determine the group symbol', async () => {\n const languageContext = createLanguageContext('es-ES');\n const el = await getElFrom(html`\n <div @sp-language-context=${languageContext}>${Default()}</div>\n `);\n await elementUpdated(el);\n\n el.focus();\n await sendKeys({\n type: '123.456.789',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('123.456.789');\n await sendKeys({\n press: 'Tab',\n });\n await elementUpdated(el);\n expect(el.formattedValue).to.equal('123.456.789');\n });\n });\n describe('2-byte characters', () => {\n const numbers = Object.keys(remapMultiByteCharacters);\n // only `1`-`0` can be accepted as single key inputs.\n numbers.splice(10);\n numbers.forEach((input) => {\n const actual = remapMultiByteCharacters[input];\n it(`accepts \"${input}\" as \"${actual}\"`, async () => {\n const el = await getElFrom(Default());\n el.focusElement.value = input;\n el.focusElement.dispatchEvent(\n new Event('input', {\n bubbles: true,\n cancelable: true,\n composed: true,\n })\n );\n await elementUpdated(el);\n\n expect(el.formattedValue).to.equal(actual);\n expect(el.value).to.equal(Number(actual));\n });\n });\n it('accepts \"、\" as \",\" and \"。\" as \".\"', async () => {\n const el = await getElFrom(Default(Default.args));\n el.focusElement.value = '1、234。56';\n el.focusElement.dispatchEvent(\n new Event('input', {\n bubbles: true,\n cancelable: true,\n composed: true,\n })\n );\n await elementUpdated(el);\n\n expect(el.formattedValue).to.equal('1,234.56');\n expect(el.value).to.equal(Number(1234.56));\n });\n it('accepts misplaced \"、\" and corrects them', async () => {\n const el = await getElFrom(Default(Default.args));\n const nextFocusableElement = document.createElement('input');\n el.insertAdjacentElement('afterend', nextFocusableElement);\n el.focus();\n await elementUpdated(el);\n\n el.focusElement.value = '12、3456、7。89';\n el.focusElement.dispatchEvent(\n new Event('input', {\n bubbles: true,\n cancelable: true,\n composed: true,\n })\n );\n await elementUpdated(el);\n\n expect(el.focusElement.value, 'visible').to.equal('12,3456,7.89');\n expect(el.formattedValue, 'tracked').to.equal('1,234,567.89');\n expect(el.value, 'value').to.equal(Number(1234567.89));\n\n await sendKeys({\n press: 'Tab',\n });\n await elementUpdated(el);\n expect(el.focusElement.value, 'visible').to.equal('1,234,567.89');\n expect(el.formattedValue, 'tracked').to.equal('1,234,567.89');\n expect(el.value, 'value').to.equal(Number(1234567.89));\n nextFocusableElement.remove();\n });\n it('accepts \"+\" as \"+\" and \"ー\" as \"-\"', async () => {\n const el = await getElFrom(decimals(decimals.args));\n el.focusElement.value = '+9。87';\n el.focusElement.dispatchEvent(\n new Event('input', {\n bubbles: true,\n cancelable: true,\n composed: true,\n })\n );\n await elementUpdated(el);\n\n expect(el.formattedValue).to.equal('+9.87');\n expect(el.value).to.equal(Number(9.87));\n\n el.focusElement.value = 'ー9.87';\n el.focusElement.dispatchEvent(\n new Event('input', {\n bubbles: true,\n cancelable: true,\n composed: true,\n })\n );\n await elementUpdated(el);\n\n expect(el.formattedValue).to.equal('-9.87');\n expect(el.value).to.equal(Number(-9.87));\n });\n it('accepts \"%\" as \"%\"', async () => {\n const el = await getElFrom(percents(percents.args));\n el.focusElement.value = '10%';\n el.focusElement.dispatchEvent(\n new Event('input', {\n bubbles: true,\n cancelable: true,\n composed: true,\n })\n );\n await elementUpdated(el);\n\n expect(el.formattedValue).to.equal('10%');\n expect(el.value).to.equal(Number(0.1));\n });\n });\n});\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 * as stories from '../stories/number-field.stories.js';
|
|
13
|
+
import { regressVisuals } from '../../../test/visual/test.js';
|
|
14
|
+
regressVisuals('NumberFieldStories', stories);
|
|
15
|
+
//# sourceMappingURL=number-field.test-vrt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-field.test-vrt.js","sourceRoot":"","sources":["number-field.test-vrt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,KAAK,OAAO,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,cAAc,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport * as stories from '../stories/number-field.stories.js';\nimport { regressVisuals } from '../../../test/visual/test.js';\n\nregressVisuals('NumberFieldStories', stories);\n"]}
|