@muonic/muon 0.0.2-beta.43 → 0.0.2-beta.45
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/CHANGELOG.md +9 -0
- package/mixins/form-associate-mixin.js +1 -1
- package/mixins/mask-mixin.js +6 -0
- package/package.json +2 -1
- package/scripts/utils/index.mjs +10 -2
- package/tests/components/inputter/__snapshots__/inputter.test.snap.js +18 -0
- package/tests/components/inputter/inputter.test.js +57 -0
- package/tests/scripts/utils/utils-test.mjs +2 -2
- package/tests/utils/validation.functions.test.js +30 -1
- package/utils/validation/index.js +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.0.2-beta.45](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.44...v0.0.2-beta.45) (2023-09-18)
|
|
6
|
+
|
|
7
|
+
### [0.0.2-beta.44](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.43...v0.0.2-beta.44) (2023-09-15)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* ignoreSeparator inputter property ([769e872](https://github.com/centrica-engineering/muon/commit/769e872137986ffd9beaa76d4271d75d6833b2b1))
|
|
13
|
+
|
|
5
14
|
### [0.0.2-beta.43](https://github.com/centrica-engineering/muon/compare/v0.0.2-beta.42...v0.0.2-beta.43) (2023-09-07)
|
|
6
15
|
|
|
7
16
|
|
package/mixins/mask-mixin.js
CHANGED
|
@@ -19,6 +19,11 @@ export const MaskMixin = dedupeMixin((superclass) =>
|
|
|
19
19
|
|
|
20
20
|
separator: {
|
|
21
21
|
type: String
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
ignoreSeparator: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
attribute: 'ignore-separator'
|
|
22
27
|
}
|
|
23
28
|
};
|
|
24
29
|
}
|
|
@@ -28,6 +33,7 @@ export const MaskMixin = dedupeMixin((superclass) =>
|
|
|
28
33
|
|
|
29
34
|
this.mask = '';
|
|
30
35
|
this.separator = '';
|
|
36
|
+
this.ignoreSeparator = false;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
firstUpdated() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muonic/muon",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.45",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"command-line-args": "5.2.1",
|
|
36
36
|
"cssnano": "6.0.1",
|
|
37
37
|
"deepmerge": "4.3.1",
|
|
38
|
+
"element-internals-polyfill": "^1.3.8",
|
|
38
39
|
"glob": "10.2.2",
|
|
39
40
|
"glob-to-regexp": "0.4.1",
|
|
40
41
|
"lit": "2.8.0",
|
package/scripts/utils/index.mjs
CHANGED
|
@@ -305,9 +305,17 @@ const componentDefiner = async () => {
|
|
|
305
305
|
});
|
|
306
306
|
|
|
307
307
|
componentDefinition += `
|
|
308
|
-
|
|
308
|
+
function defineComponents() {
|
|
309
309
|
${definingCompnents.join('')}
|
|
310
|
-
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (document.readyState === 'loading') {
|
|
313
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
314
|
+
defineComponents();
|
|
315
|
+
});
|
|
316
|
+
} else {
|
|
317
|
+
defineComponents();
|
|
318
|
+
}
|
|
311
319
|
`;
|
|
312
320
|
|
|
313
321
|
return componentDefinition;
|
|
@@ -219,3 +219,21 @@ snapshots["Inputter date standard date"] =
|
|
|
219
219
|
`;
|
|
220
220
|
/* end snapshot Inputter date standard date */
|
|
221
221
|
|
|
222
|
+
snapshots["Inputter text mask & separator text"] =
|
|
223
|
+
`<div class="has-mask inputter type-text">
|
|
224
|
+
<slot name="label">
|
|
225
|
+
</slot>
|
|
226
|
+
<div class="wrapper">
|
|
227
|
+
<slot>
|
|
228
|
+
</slot>
|
|
229
|
+
<div
|
|
230
|
+
aria-hidden="true"
|
|
231
|
+
class="input-mask"
|
|
232
|
+
>
|
|
233
|
+
00-00
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
`;
|
|
238
|
+
/* end snapshot Inputter text mask & separator text */
|
|
239
|
+
|
|
@@ -262,6 +262,63 @@ describe('Inputter', () => {
|
|
|
262
262
|
inputMask = shadowRoot.querySelector('.input-mask');
|
|
263
263
|
expect(inputMask.textContent).to.be.equal(' 0', '`input-mask` has correct value');
|
|
264
264
|
});
|
|
265
|
+
|
|
266
|
+
it('mask & separator text', async () => {
|
|
267
|
+
const inputter = await fixture(html`
|
|
268
|
+
<${tag} mask="00-00" separator="-" ignore-separator="" validation=["isRequired","minLength(4)"]>
|
|
269
|
+
<label slot="label">input label</label>
|
|
270
|
+
<input type="text" value=""/>
|
|
271
|
+
</${tag}>`);
|
|
272
|
+
const shadowRoot = inputter.shadowRoot;
|
|
273
|
+
|
|
274
|
+
await defaultChecks(inputter);
|
|
275
|
+
const changeEventSpy = sinon.spy();
|
|
276
|
+
inputter.addEventListener('change', changeEventSpy);
|
|
277
|
+
|
|
278
|
+
expect(inputter.type).to.equal('standard', 'default type is set');
|
|
279
|
+
expect(inputter.separator).to.be.equal('-', 'seperator should be present');
|
|
280
|
+
expect(inputter.id).to.not.be.null; // eslint-disable-line no-unused-expressions
|
|
281
|
+
|
|
282
|
+
const mask = shadowRoot.querySelector('.has-mask');
|
|
283
|
+
expect(mask).to.not.be.null; // eslint-disable-line no-unused-expressions
|
|
284
|
+
|
|
285
|
+
let inputMask = shadowRoot.querySelector('.input-mask');
|
|
286
|
+
expect(inputMask).to.not.be.null; // eslint-disable-line no-unused-expressions
|
|
287
|
+
|
|
288
|
+
const inputElement = inputter.querySelector('input');
|
|
289
|
+
await fillIn(inputElement, '0', 'input');
|
|
290
|
+
|
|
291
|
+
await inputter.updateComplete;
|
|
292
|
+
expect(changeEventSpy.callCount).to.equal(1, '`change` event fired');
|
|
293
|
+
expect(changeEventSpy.lastCall.args[0].detail.value).to.equal('0', '`change` event has value `0`');
|
|
294
|
+
let validation = shadowRoot.querySelector('.validation');
|
|
295
|
+
expect(validation).to.be.not.null; // eslint-disable-line no-unused-expressions
|
|
296
|
+
|
|
297
|
+
await fillIn(inputElement, '', 'input');
|
|
298
|
+
await inputter.updateComplete;
|
|
299
|
+
expect(changeEventSpy.callCount).to.equal(2, '`change` event fired');
|
|
300
|
+
expect(changeEventSpy.lastCall.args[0].detail.value).to.equal('', '`change` event has value ``');
|
|
301
|
+
validation = shadowRoot.querySelector('.validation');
|
|
302
|
+
expect(validation).to.not.be.null; // eslint-disable-line no-unused-expressions
|
|
303
|
+
expect(getComputedStyle(validation).color).to.equal('rgb(227, 102, 14)', 'validation has correct color');
|
|
304
|
+
|
|
305
|
+
const validationMessage = shadowRoot.querySelector('.validation .message');
|
|
306
|
+
expect(validationMessage).to.not.be.null; // eslint-disable-line no-unused-expressions
|
|
307
|
+
expect(validationMessage.textContent.trim()).to.equal('This field is required.', 'validation message has correct value');
|
|
308
|
+
|
|
309
|
+
const validationIcon = shadowRoot.querySelector('.validation .icon');
|
|
310
|
+
expect(validationIcon).to.not.be.null; // eslint-disable-line no-unused-expressions
|
|
311
|
+
expect(validationIcon.name).to.equal('exclamation-circle', 'validation icon has correct value');
|
|
312
|
+
|
|
313
|
+
await fillIn(inputElement, '123', 'input');
|
|
314
|
+
await inputter.updateComplete;
|
|
315
|
+
expect(changeEventSpy.callCount).to.equal(3, '`change` event fired');
|
|
316
|
+
expect(changeEventSpy.lastCall.args[0].detail.value).to.equal('12-3', '`change` event has value `12-3`');
|
|
317
|
+
expect(validationMessage.textContent.trim()).to.equal('Length must be at least 4 characters.', 'validation message has correct value');
|
|
318
|
+
|
|
319
|
+
inputMask = shadowRoot.querySelector('.input-mask');
|
|
320
|
+
expect(inputMask.textContent).to.be.equal(' 0', '`input-mask` has correct value');
|
|
321
|
+
});
|
|
265
322
|
});
|
|
266
323
|
|
|
267
324
|
describe('radio', async () => {
|
|
@@ -204,7 +204,7 @@ testRunner('sourceFilesAnalyzer', async (t) => {
|
|
|
204
204
|
'muon-form': ['standardTemplate', 'type'],
|
|
205
205
|
'muon-icon': ['size', 'classes', 'inlineStyles', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'describe', 'type'],
|
|
206
206
|
'muon-image': ['src', 'classes', 'inlineStyles', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
|
|
207
|
-
'muon-inputter': ['helper', 'classes', 'inlineStyles', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
|
|
207
|
+
'muon-inputter': ['helper', 'classes', 'inlineStyles', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'ignoreSeparator', 'type'],
|
|
208
208
|
'inputter-detail': ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type']
|
|
209
209
|
};
|
|
210
210
|
t.deepEqual(jsonResult.tags?.map((tag) => tag.name).sort(), components.sort());
|
|
@@ -230,7 +230,7 @@ testRunner('sourceFilesAnalyzer with prefix override', async (t) => {
|
|
|
230
230
|
const components = ['muon-cta', 'muon-inputter', 'inputter-detail', 'mnx-cta'];
|
|
231
231
|
const propertiesMap = {
|
|
232
232
|
'muon-cta': ['href', 'classes', 'inlineStyles', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
|
|
233
|
-
'muon-inputter': ['helper', 'classes', 'inlineStyles', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
|
|
233
|
+
'muon-inputter': ['helper', 'classes', 'inlineStyles', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'ignoreSeparator', 'type'],
|
|
234
234
|
'inputter-detail': ['icon', 'classes', 'inlineStyles', 'standardTemplate', 'open', 'type'],
|
|
235
235
|
'mnx-cta': ['enabled', 'type']
|
|
236
236
|
};
|
|
@@ -23,6 +23,13 @@ describe('validation', () => {
|
|
|
23
23
|
validation = customValidations.isNumber(inputElement, '343');
|
|
24
24
|
expect(validation).to.equal(false, 'validation has correct value');
|
|
25
25
|
|
|
26
|
+
validation = customValidations.isNumber(inputElement, '343-23');
|
|
27
|
+
expect(validation).to.equal('Needs to be a number', 'validation has correct value');
|
|
28
|
+
|
|
29
|
+
inputElement = { separator: '-', ignoreSeparator: true };
|
|
30
|
+
validation = customValidations.isNumber(inputElement, 'fdgd-fdf');
|
|
31
|
+
expect(validation).to.equal('Needs to be a number', 'validation has correct value');
|
|
32
|
+
|
|
26
33
|
validation = customValidations.isNumber(inputElement, '343-23');
|
|
27
34
|
expect(validation).to.equal(false, 'validation has correct value');
|
|
28
35
|
});
|
|
@@ -39,6 +46,10 @@ describe('validation', () => {
|
|
|
39
46
|
validation = customValidations.isInteger(inputElement, 'Infinity');
|
|
40
47
|
expect(validation).to.equal('Needs to be a whole number', 'validation has correct value');
|
|
41
48
|
|
|
49
|
+
validation = customValidations.isInteger(inputElement, '343-67');
|
|
50
|
+
expect(validation).to.equal('Needs to be a whole number', 'validation has correct value');
|
|
51
|
+
|
|
52
|
+
inputElement = { separator: '-', ignoreSeparator: true };
|
|
42
53
|
validation = customValidations.isInteger(inputElement, '343-67');
|
|
43
54
|
expect(validation).to.equal(false, 'validation has correct value');
|
|
44
55
|
});
|
|
@@ -72,6 +83,13 @@ describe('validation', () => {
|
|
|
72
83
|
|
|
73
84
|
inputElement = { separator: '-' };
|
|
74
85
|
validation = customValidations.minLength(inputElement, 'djfg-dfg', 8);
|
|
86
|
+
expect(validation).to.equal(false, 'validation has correct value');
|
|
87
|
+
|
|
88
|
+
validation = customValidations.minLength(inputElement, 'djfg-dfg8', 8);
|
|
89
|
+
expect(validation).to.equal(false, 'validation has correct value');
|
|
90
|
+
|
|
91
|
+
inputElement = { separator: '-', ignoreSeparator: true };
|
|
92
|
+
validation = customValidations.minLength(inputElement, 'djfg-dfg', 8);
|
|
75
93
|
expect(validation).to.equal('Length must be at least 8 characters', 'validation has correct value');
|
|
76
94
|
|
|
77
95
|
validation = customValidations.minLength(inputElement, 'djfg-dfg8', 8);
|
|
@@ -91,10 +109,14 @@ describe('validation', () => {
|
|
|
91
109
|
|
|
92
110
|
inputElement = { separator: '-' };
|
|
93
111
|
validation = customValidations.maxLength(inputElement, '353-434', 6);
|
|
94
|
-
expect(validation).to.equal(
|
|
112
|
+
expect(validation).to.equal('Length must be no longer than 6 characters', 'validation has correct value');
|
|
95
113
|
|
|
96
114
|
validation = customValidations.maxLength(inputElement, 'fer', 2);
|
|
97
115
|
expect(validation).to.equal('Length must be no longer than 2 characters', 'validation has correct value');
|
|
116
|
+
|
|
117
|
+
inputElement = { separator: '-', ignoreSeparator: true };
|
|
118
|
+
validation = customValidations.maxLength(inputElement, '353-434', 6);
|
|
119
|
+
expect(validation).to.equal(false, 'validation has correct value');
|
|
98
120
|
});
|
|
99
121
|
|
|
100
122
|
it('isBetween', async () => {
|
|
@@ -116,6 +138,13 @@ describe('validation', () => {
|
|
|
116
138
|
|
|
117
139
|
inputElement = { separator: '-' };
|
|
118
140
|
validation = customValidations.isBetween(inputElement, 'd-', 2, 8);
|
|
141
|
+
expect(validation).to.equal(false, 'validation has correct value');
|
|
142
|
+
|
|
143
|
+
validation = customValidations.isBetween(inputElement, 'd-jfg-dfg', 2, 8);
|
|
144
|
+
expect(validation).to.equal('Length must be between 2 and 8 characters', 'validation has correct value');
|
|
145
|
+
|
|
146
|
+
inputElement = { separator: '-', ignoreSeparator: true };
|
|
147
|
+
validation = customValidations.isBetween(inputElement, 'd-', 2, 8);
|
|
119
148
|
expect(validation).to.equal('Length must be between 2 and 8 characters', 'validation has correct value');
|
|
120
149
|
|
|
121
150
|
validation = customValidations.isBetween(inputElement, 'd-jfg-dfg', 2, 8);
|
|
@@ -31,14 +31,14 @@ const isRequired = (inputter, value) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const isNumber = (inputter, value) => {
|
|
34
|
-
const number = inputter.
|
|
34
|
+
const number = inputter.ignoreSeparator ? withoutChar(value, inputter.separator) : value;
|
|
35
35
|
const val = Number(number);
|
|
36
36
|
const isNum = typeof val === 'number' && !isNaN(val);
|
|
37
37
|
return value.length > 0 && !isNum && VALIDATION_IS_NUMBER_MESSAGE;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
const isInteger = (inputter, value) => {
|
|
41
|
-
const number = inputter.
|
|
41
|
+
const number = inputter.ignoreSeparator ? withoutChar(value, inputter.separator) : value;
|
|
42
42
|
const val = Number(number);
|
|
43
43
|
const isInt = typeof val === 'number' && isFinite(val) && Math.floor(val) === val;
|
|
44
44
|
|
|
@@ -51,17 +51,17 @@ const isEmail = (inputter, value) => {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
const minLength = (inputter, value, min) => {
|
|
54
|
-
const str = inputter.
|
|
54
|
+
const str = inputter.ignoreSeparator ? withoutChar(value, inputter.separator) : value;
|
|
55
55
|
return value.length > 0 && str.length < min && VALIDATION_MIN_LENGTH_MESSAGE.replace('$min', min);
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
const maxLength = (inputter, value, max) => {
|
|
59
|
-
const str = inputter.
|
|
59
|
+
const str = inputter.ignoreSeparator ? withoutChar(value, inputter.separator) : value;
|
|
60
60
|
return value.length > 0 && str.length > max && VALIDATION_MAX_LENGTH_MESSAGE.replace('$max', max);
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
const isBetween = (inputter, value, min, max) => {
|
|
64
|
-
const str = inputter.
|
|
64
|
+
const str = inputter.ignoreSeparator ? withoutChar(value, inputter.separator) : value;
|
|
65
65
|
return value.length > 0 && (str.length < min || str.length > max) && VALIDATION_IS_BETWEEN_MESSAGE.replace('$min', min).replace('$max', max);
|
|
66
66
|
};
|
|
67
67
|
|