@muonic/muon 0.0.2-beta.0

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.
Files changed (124) hide show
  1. package/.nycrc +17 -0
  2. package/.versionrc +3 -0
  3. package/CHANGELOG.md +389 -0
  4. package/components/card/index.js +1 -0
  5. package/components/card/src/card-component.js +43 -0
  6. package/components/card/src/card-styles.css +25 -0
  7. package/components/card/src/config-tokens.json +11 -0
  8. package/components/card/src/design-tokens.json +34 -0
  9. package/components/card/story.js +52 -0
  10. package/components/cta/index.js +1 -0
  11. package/components/cta/src/config-tokens.json +11 -0
  12. package/components/cta/src/cta-component.js +174 -0
  13. package/components/cta/src/cta-styles.css +105 -0
  14. package/components/cta/src/design-tokens.json +132 -0
  15. package/components/cta/story.js +99 -0
  16. package/components/detail/index.js +1 -0
  17. package/components/detail/src/config-tokens.json +11 -0
  18. package/components/detail/src/design-tokens.json +102 -0
  19. package/components/detail/src/detail-component.js +27 -0
  20. package/components/detail/src/detail-styles.css +83 -0
  21. package/components/detail/story.js +33 -0
  22. package/components/form/index.js +1 -0
  23. package/components/form/src/config-tokens.json +11 -0
  24. package/components/form/src/design-tokens.json +9 -0
  25. package/components/form/src/form-component.js +197 -0
  26. package/components/form/src/form-styles.css +10 -0
  27. package/components/form/story.js +71 -0
  28. package/components/icon/index.js +1 -0
  29. package/components/icon/src/config-tokens.json +31 -0
  30. package/components/icon/src/design-tokens.json +8 -0
  31. package/components/icon/src/icon-component.js +91 -0
  32. package/components/icon/src/icon-styles.css +26 -0
  33. package/components/icon/story.js +26 -0
  34. package/components/image/index.js +1 -0
  35. package/components/image/src/config-tokens.json +26 -0
  36. package/components/image/src/image-component.js +96 -0
  37. package/components/image/src/image-styles.css +71 -0
  38. package/components/image/story.js +31 -0
  39. package/components/inputter/index.js +1 -0
  40. package/components/inputter/src/config-tokens.json +14 -0
  41. package/components/inputter/src/design-tokens.json +308 -0
  42. package/components/inputter/src/inputter-component.js +227 -0
  43. package/components/inputter/src/inputter-styles-detail.css +59 -0
  44. package/components/inputter/src/inputter-styles.css +305 -0
  45. package/components/inputter/src/inputter-styles.slotted.css +64 -0
  46. package/components/inputter/story.js +243 -0
  47. package/css/accessibility.css +3 -0
  48. package/css/default.css +9 -0
  49. package/css/global.css +8 -0
  50. package/directives/image-loader-directive.js +116 -0
  51. package/directives/svg-loader-directive.js +94 -0
  52. package/index.js +52 -0
  53. package/mixins/card-mixin.js +27 -0
  54. package/mixins/detail-mixin.js +128 -0
  55. package/mixins/form-associate-mixin.js +36 -0
  56. package/mixins/form-element-mixin.js +378 -0
  57. package/mixins/image-holder-mixin.js +20 -0
  58. package/mixins/mask-mixin.js +159 -0
  59. package/mixins/validation-mixin.js +272 -0
  60. package/muon-element/index.js +97 -0
  61. package/package.json +72 -0
  62. package/rollup.config.mjs +30 -0
  63. package/scripts/build/storybook/index.mjs +11 -0
  64. package/scripts/build/storybook/run.mjs +47 -0
  65. package/scripts/rollup-plugins.mjs +116 -0
  66. package/scripts/serve/index.mjs +11 -0
  67. package/scripts/serve/run.mjs +27 -0
  68. package/scripts/style-dictionary.mjs +64 -0
  69. package/scripts/utils/config.mjs +30 -0
  70. package/scripts/utils/index.mjs +283 -0
  71. package/storybook/find-stories.js +36 -0
  72. package/storybook/server.config.mjs +19 -0
  73. package/storybook/stories.js +86 -0
  74. package/storybook/tokens/color.js +87 -0
  75. package/storybook/tokens/font.js +52 -0
  76. package/storybook/tokens/spacer.js +48 -0
  77. package/tests/README.md +3 -0
  78. package/tests/components/card/__snapshots__/card.test.snap.js +70 -0
  79. package/tests/components/card/card.test.js +81 -0
  80. package/tests/components/cta/__snapshots__/cta.test.snap.js +246 -0
  81. package/tests/components/cta/cta.test.js +212 -0
  82. package/tests/components/form/__snapshots__/form.test.snap.js +115 -0
  83. package/tests/components/form/form.test.js +336 -0
  84. package/tests/components/icon/__snapshots__/icon.test.snap.js +95 -0
  85. package/tests/components/icon/icon.test.js +197 -0
  86. package/tests/components/image/__snapshots__/image.test.snap.js +205 -0
  87. package/tests/components/image/image.test.js +314 -0
  88. package/tests/components/image/images/15.png +0 -0
  89. package/tests/components/image/images/150.png +0 -0
  90. package/tests/components/inputter/__snapshots__/inputter.test.snap.js +357 -0
  91. package/tests/components/inputter/inputter.test.js +427 -0
  92. package/tests/helpers/index.js +30 -0
  93. package/tests/mixins/__snapshots__/card.test.snap.js +35 -0
  94. package/tests/mixins/__snapshots__/detail.test.snap.js +237 -0
  95. package/tests/mixins/__snapshots__/form-element.test.snap.js +137 -0
  96. package/tests/mixins/__snapshots__/mask.test.snap.js +53 -0
  97. package/tests/mixins/__snapshots__/validation.test.snap.js +297 -0
  98. package/tests/mixins/card.test.js +63 -0
  99. package/tests/mixins/detail.test.js +223 -0
  100. package/tests/mixins/form-element.test.js +473 -0
  101. package/tests/mixins/mask.test.js +261 -0
  102. package/tests/mixins/muon-element.test.js +52 -0
  103. package/tests/mixins/validation.test.js +423 -0
  104. package/tests/runner/commands.mjs +19 -0
  105. package/tests/scripts/utils/card-component.js +26 -0
  106. package/tests/scripts/utils/muon.config.test.json +13 -0
  107. package/tests/scripts/utils/single.component.config.json +5 -0
  108. package/tests/scripts/utils/test-runner.mjs +1 -0
  109. package/tests/scripts/utils/utils-test.mjs +284 -0
  110. package/tests/utils/validation.functions.test.js +199 -0
  111. package/tokens/theme/color.json +482 -0
  112. package/tokens/theme/font.json +61 -0
  113. package/tokens/theme/size.json +27 -0
  114. package/tokens/theme/spacer.json +73 -0
  115. package/tokens/utils/formats/reference.js +17 -0
  116. package/tokens/utils/modular-scale.js +33 -0
  117. package/tokens/utils/templates/font-face.css.template +30 -0
  118. package/tokens/utils/transforms/color.js +27 -0
  119. package/tokens/utils/transforms/string.js +6 -0
  120. package/tokens/utils/validation.json +76 -0
  121. package/utils/scroll/index.js +31 -0
  122. package/utils/validation/index.js +205 -0
  123. package/web-test-runner.browserstack.config.mjs +123 -0
  124. package/web-test-runner.config.mjs +44 -0
@@ -0,0 +1,284 @@
1
+ import testRunner from 'ava';
2
+ import sinon from 'sinon';
3
+ import appRoot from 'app-root-path';
4
+ import fs from 'fs';
5
+ import path from 'path';
6
+ import { fileURLToPath } from 'url';
7
+ import esmock from 'esmock';
8
+ import * as utilsLibrary from '../../../scripts/utils/index.mjs';
9
+
10
+ testRunner('filterPathToCustomElements default', async (t) => {
11
+ const componentList = await utilsLibrary.filterPathToCustomElements('all');
12
+ t.is(componentList, '*');
13
+ });
14
+
15
+ testRunner('filterPathToCustomElements default array', async (t) => {
16
+ const componentList = await utilsLibrary.filterPathToCustomElements(['all']);
17
+ t.is(componentList, '*');
18
+ });
19
+
20
+ testRunner('filterPathToCustomElements single component', async (t) => {
21
+ const componentList = await utilsLibrary.filterPathToCustomElements('inputter');
22
+ t.is(componentList, 'inputter');
23
+ });
24
+
25
+ testRunner('filterPathToCustomElements single component in array', async (t) => {
26
+ const componentList = await utilsLibrary.filterPathToCustomElements(['inputter']);
27
+ t.is(componentList, 'inputter');
28
+ });
29
+
30
+ testRunner('filterPathToCustomElements multiple component', async (t) => {
31
+ const componentList = await utilsLibrary.filterPathToCustomElements(['inputter', 'image']);
32
+ t.is(componentList, '{inputter,image}');
33
+ });
34
+
35
+ testRunner('getConfig default file and root', async (t) => {
36
+ const config = utilsLibrary.getConfig();
37
+ t.true(config !== undefined);
38
+ });
39
+
40
+ testRunner('getConfig new file default root', async (t) => {
41
+ const config = utilsLibrary.getConfig('browserstack.json');
42
+ t.true(config !== undefined);
43
+ });
44
+
45
+ testRunner('getConfig config file not exist', async (t) => {
46
+ const stub = sinon.stub(process, 'exit');
47
+ utilsLibrary.getConfig('test.json');
48
+ t.true(process.exit.called);
49
+ t.true(process.exit.calledWith(1));
50
+ stub.restore();
51
+ });
52
+
53
+ testRunner('getConfig config file', async (t) => {
54
+ const config = utilsLibrary.getConfig('tests/scripts/utils/muon.config.test.json');
55
+ t.true(config !== undefined);
56
+ });
57
+
58
+ const componentsDefinitionMacro = async (t, expected) => {
59
+ const componentDefinition = await utilsLibrary.componentDefiner();
60
+ t.true(componentDefinition !== undefined);
61
+ t.true(componentDefinition.indexOf(`import '@webcomponents/scoped-custom-element-registry';`) > -1);
62
+ Object.keys(expected).forEach((component) => {
63
+ t.true(componentDefinition.indexOf(`import { ${expected[component]} } from '${process.cwd()}/components/${component}/src/${component}-component.js';`) > -1);
64
+ t.true(componentDefinition.indexOf(`customElements.define('muon-${component}', ${expected[component]});`) > -1);
65
+ });
66
+ };
67
+ componentsDefinitionMacro.title = (providedTitle, expected) => `${providedTitle} => ${Object.keys(expected)}`;
68
+
69
+ testRunner('componentDefiner', componentsDefinitionMacro, { card: 'Card', cta: 'Cta', detail: 'Detail', form: 'Form', icon: 'Icon', inputter: 'Inputter', image: 'Image' });
70
+
71
+ testRunner('getAliasPath glob', async (t) => {
72
+ const alias = utilsLibrary.getAliasPaths('glob');
73
+
74
+ t.deepEqual(alias, {
75
+ '@muon/components/*': [`${appRoot}/node_modules/@muonic/muon/components/*`],
76
+ '@muon/mixins/*': [`${appRoot}/node_modules/@muonic/muon/mixins/*`],
77
+ '@muon/directives/*': [`${appRoot}/node_modules/@muonic/muon/directives/*`],
78
+ '@muon/utils/*': [`${appRoot}/node_modules/@muonic/muon/utils/*`],
79
+ '@muon/tokens': [`${appRoot}/node_modules/@muonic/muon/build/tokens/es6/muon-tokens`]
80
+ });
81
+ });
82
+
83
+ testRunner('getAliasPath regex', async (t) => {
84
+ const alias = utilsLibrary.getAliasPaths('regex');
85
+ t.deepEqual(alias, [
86
+ {
87
+ find: /^@muon\/components\/(.*)$/,
88
+ replacement: '@muonic/muon/components/$1'
89
+ },
90
+ {
91
+ find: /^@muon\/mixins\/(.*)$/,
92
+ replacement: '@muonic/muon/mixins/$1'
93
+ },
94
+ {
95
+ find: /^@muon\/directives\/(.*)$/,
96
+ replacement: '@muonic/muon/directives/$1'
97
+ },
98
+ {
99
+ find: /^@muon\/utils\/(.*)$/,
100
+ replacement: '@muonic/muon/utils/$1'
101
+ },
102
+ {
103
+ find: /^@muon\/tokens$/,
104
+ replacement: '@muonic/muon/build/tokens/es6/muon-tokens'
105
+ }
106
+ ]);
107
+ });
108
+
109
+ testRunner('getAliasPath invalid', async (t) => {
110
+ const alias = utilsLibrary.getAliasPaths('invalid');
111
+ t.true(alias === undefined);
112
+ });
113
+
114
+ testRunner('getAliasPath config alias regex', async (t) => {
115
+ const stub = await esmock('../../../scripts/utils/index.mjs', {
116
+ '../../../scripts/utils/config.mjs': {
117
+ getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/muon.config.test.json').toString())
118
+ }
119
+ });
120
+ const alias = stub.getAliasPaths('regex');
121
+ t.true(alias !== undefined);
122
+ t.deepEqual(alias, [
123
+ {
124
+ find: /^@muon\/utils\/validation$/,
125
+ replacement: `${process.cwd()}/utils/validation`
126
+ },
127
+ {
128
+ find: /^@muon\/components\/(.*)$/,
129
+ replacement: '@muonic/muon/components/$1'
130
+ },
131
+ {
132
+ find: /^@muon\/mixins\/(.*)$/,
133
+ replacement: '@muonic/muon/mixins/$1'
134
+ },
135
+ {
136
+ find: /^@muon\/directives\/(.*)$/,
137
+ replacement: '@muonic/muon/directives/$1'
138
+ },
139
+ {
140
+ find: /^@muon\/utils\/(.*)$/,
141
+ replacement: '@muonic/muon/utils/$1'
142
+ },
143
+ {
144
+ find: /^@muon\/tokens$/,
145
+ replacement: '@muonic/muon/build/tokens/es6/muon-tokens'
146
+ }
147
+ ]);
148
+ });
149
+
150
+ testRunner('getAliasPath config alias glob', async (t) => {
151
+ const stub = await esmock('../../../scripts/utils/index.mjs', {
152
+ '../../../scripts/utils/config.mjs': {
153
+ getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/muon.config.test.json').toString())
154
+ }
155
+ });
156
+ const alias = stub.getAliasPaths('glob');
157
+ t.true(alias !== undefined);
158
+ t.deepEqual(alias, {
159
+ '@muon/utils/validation': ['./utils/validation'],
160
+ '@muon/components/*': [
161
+ `${appRoot}/node_modules/@muonic/muon/components/*`
162
+ ],
163
+ '@muon/mixins/*': [
164
+ `${appRoot}/node_modules/@muonic/muon/mixins/*`
165
+ ],
166
+ '@muon/directives/*': [
167
+ `${appRoot}/node_modules/@muonic/muon/directives/*`
168
+ ],
169
+ '@muon/utils/*': [
170
+ `${appRoot}/node_modules/@muonic/muon/utils/*`
171
+ ],
172
+ '@muon/tokens': [
173
+ `${appRoot}/node_modules/@muonic/muon/build/tokens/es6/muon-tokens`
174
+ ]
175
+ });
176
+ });
177
+
178
+ testRunner('sourceFilesAnalyzer', async (t) => {
179
+ const result = await utilsLibrary.sourceFilesAnalyzer();
180
+ const jsonResult = JSON.parse(result);
181
+
182
+ const components = ['card', 'cta', 'detail', 'form', 'icon', 'image', 'inputter', 'inputter-detail'];
183
+ const propertiesMap = {
184
+ card: ['standardTemplate', 'image', 'alt', 'background', 'type'],
185
+ cta: ['href', 'standardTemplate', 'submitTemplate', 'resetTemplate', 'loading', 'loadingMessage', 'disabled', 'icon', 'type'],
186
+ detail: ['icon', 'standardTemplate', 'open', 'type'],
187
+ form: ['standardTemplate', 'type'],
188
+ icon: ['size', 'sizes', 'iconSize', 'standardTemplate', 'name', 'category', 'allSizes', 'url', 'describe', 'type'],
189
+ image: ['src', 'placeholderImage', 'standardTemplate', 'background', 'backgroundsize', 'alt', 'ratio', 'placeholder', 'loading', 'type'],
190
+ inputter: ['helper', 'slottedStyles', 'isHelperOpen', 'isPristine', 'isDirty', 'validity', 'validationMessage', 'validation', 'disableNative', 'showMessage', 'name', 'value', 'labelID', 'heading', 'mask', 'separator', 'type'],
191
+ 'inputter-detail': ['icon', 'standardTemplate', 'open', 'type']
192
+ };
193
+ t.deepEqual(jsonResult.tags?.map((tag) => tag.name), components);
194
+
195
+ components.forEach((component) => {
196
+ t.deepEqual(jsonResult.tags.filter((tag) => tag.name === component)[0].properties?.map(
197
+ (property) => property.name), propertiesMap[component]);
198
+ });
199
+ jsonResult.tags?.map((tag) => {
200
+ t.true(tag.description !== undefined, `${tag.name} description is not present`);
201
+ });
202
+ });
203
+
204
+ testRunner('sourceFilesAnalyzer error', async (t) => {
205
+ const stub = await esmock('../../../scripts/utils/index.mjs', {
206
+ '../../../scripts/utils/config.mjs': {
207
+ getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/muon.config.test.json').toString())
208
+ }
209
+ });
210
+ const sinonStub = sinon.stub(process, 'exit');
211
+ await stub.sourceFilesAnalyzer();
212
+ t.true(process.exit.called);
213
+ t.true(process.exit.calledWith(1));
214
+ sinonStub.restore();
215
+ });
216
+
217
+ testRunner('sourceFilesAnalyzer single file', async (t) => {
218
+ const stub = await esmock('../../../scripts/utils/index.mjs', {
219
+ '../../../scripts/utils/config.mjs': {
220
+ getConfig: (configFile) => JSON.parse(fs.readFileSync('tests/scripts/utils/single.component.config.json').toString())
221
+ }
222
+ });
223
+ const result = await stub.sourceFilesAnalyzer();
224
+ const jsonResult = JSON.parse(result);
225
+
226
+ const components = ['card'];
227
+ const propertiesMap = {
228
+ card: ['standardTemplate', 'image', 'alt', 'background', 'type'],
229
+ };
230
+ t.deepEqual(jsonResult.tags?.map((tag) => tag.name), components);
231
+
232
+ components.forEach((component) => {
233
+ t.deepEqual(jsonResult.tags.filter((tag) => tag.name === component)[0].properties?.map(
234
+ (property) => property.name), propertiesMap[component]);
235
+ });
236
+ jsonResult.tags?.map((tag) => {
237
+ t.true(tag.description !== undefined, `${tag.name} description is not present`);
238
+ });
239
+ });
240
+
241
+ testRunner('create tokens', async (t) => {
242
+ await utilsLibrary.createTokens();
243
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'css', 'mn-fonts.css')), 'font css file not exist');
244
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'es6', 'muon-tokens-module.js')), 'muon-tokens-module.js don\'t exist');
245
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'es6', 'muon-tokens.js')), 'muon-tokens.js don\'t exist');
246
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'es6', 'muon-tokens.mjs')), 'muon-tokens.mjs don\'t exist');
247
+ t.true(fs.existsSync(path.join(process.cwd(), 'build', 'tokens', 'json', 'muon-tokens-reference.json')), 'muon-tokens-reference.json don\'t exist');
248
+ });
249
+
250
+ testRunner('getDestination', async (t) => {
251
+ const destination = utilsLibrary.getDestination();
252
+ t.is(destination, 'dist');
253
+ });
254
+
255
+ testRunner('runner', async (t) => {
256
+ const __filename = fileURLToPath(import.meta.url);
257
+ const __dirname = path.dirname(__filename);
258
+ utilsLibrary.runner(path.join(__dirname, 'test-runner.mjs'));
259
+ t.pass();
260
+ });
261
+
262
+ testRunner('cleanup on rollup', async (t) => {
263
+ const destination = utilsLibrary.getDestination();
264
+ const cemPath = path.join(destination, 'custom-elements.json');
265
+ if (!fs.existsSync(destination)) {
266
+ fs.mkdirSync(destination);
267
+ }
268
+ fs.openSync(cemPath, 'w');
269
+ t.true(fs.existsSync(destination));
270
+ t.true(fs.existsSync(cemPath));
271
+ utilsLibrary.cleanup(destination, true);
272
+ t.true(fs.existsSync(destination));
273
+ t.false(fs.existsSync(cemPath));
274
+ });
275
+
276
+ testRunner('cleanup on serve', async (t) => {
277
+ const destination = utilsLibrary.getDestination();
278
+ if (!fs.existsSync(destination)) {
279
+ fs.mkdirSync(destination);
280
+ }
281
+ t.true(fs.existsSync(destination));
282
+ utilsLibrary.cleanup(destination);
283
+ t.true(fs.existsSync(destination));
284
+ });
@@ -0,0 +1,199 @@
1
+ /* eslint-disable no-undef */
2
+ import { expect, fixture, html } from '@open-wc/testing';
3
+ import customValidations from '@muonic/muon/utils/validation';
4
+
5
+ describe('validation', () => {
6
+ it('isRequired', () => {
7
+ let validation = customValidations.isRequired(null, '');
8
+ expect(validation).to.equal('This field is required', 'validation has correct value');
9
+
10
+ validation = customValidations.isRequired(null, 'fdgdfdf');
11
+ expect(validation).to.equal(false, 'validation has correct value');
12
+ });
13
+
14
+ it('isNumber', async () => {
15
+ let inputElement = {};
16
+ let validation = customValidations.isNumber(inputElement, '');
17
+ expect(validation).to.equal(false, 'validation has correct value');
18
+
19
+ inputElement = { separator: '-' };
20
+ validation = customValidations.isNumber(inputElement, 'fdgd-fdf');
21
+ expect(validation).to.equal('Needs to be a number', 'validation has correct value');
22
+
23
+ validation = customValidations.isNumber(inputElement, '343');
24
+ expect(validation).to.equal(false, 'validation has correct value');
25
+
26
+ validation = customValidations.isNumber(inputElement, '343-23');
27
+ expect(validation).to.equal(false, 'validation has correct value');
28
+ });
29
+
30
+ it('isInteger', async () => {
31
+ let inputElement = {};
32
+ let validation = customValidations.isInteger(inputElement, '');
33
+ expect(validation).to.equal(false, 'validation has correct value');
34
+
35
+ inputElement = { separator: '-' };
36
+ validation = customValidations.isInteger(inputElement, 'fdgdf-df');
37
+ expect(validation).to.equal('Needs to be a whole number', 'validation has correct value');
38
+
39
+ validation = customValidations.isInteger(inputElement, 'Infinity');
40
+ expect(validation).to.equal('Needs to be a whole number', 'validation has correct value');
41
+
42
+ validation = customValidations.isInteger(inputElement, '343-67');
43
+ expect(validation).to.equal(false, 'validation has correct value');
44
+ });
45
+
46
+ it('isEmail', async () => {
47
+ let inputElement = await fixture(html`<input></input>`);
48
+ let validation = customValidations.isEmail(inputElement, '');
49
+ expect(validation).to.equal(false, 'validation has correct value');
50
+
51
+ inputElement = await fixture(html`<input></input>`);
52
+ validation = customValidations.isEmail(inputElement, 'fdgdf-df');
53
+ expect(validation).to.equal('Your email does not look right', 'validation has correct value');
54
+
55
+ validation = customValidations.isEmail(inputElement, 'djfgdfg');
56
+ expect(validation).to.equal('Your email does not look right', 'validation has correct value');
57
+
58
+ validation = customValidations.isEmail(inputElement, 'fjjdf.dfgd@dfd.com');
59
+ expect(validation).to.equal(false, 'validation has correct value');
60
+ });
61
+
62
+ it('minLength', async () => {
63
+ let inputElement = {};
64
+ let validation = customValidations.minLength(inputElement, '', 2);
65
+ expect(validation).to.equal(false, 'validation has correct value');
66
+
67
+ validation = customValidations.minLength(inputElement, '353434', 6);
68
+ expect(validation).to.equal(false, 'validation has correct value');
69
+
70
+ validation = customValidations.minLength(inputElement, 'f', 2);
71
+ expect(validation).to.equal('Length must be at least 2 characters', 'validation has correct value');
72
+
73
+ inputElement = { separator: '-' };
74
+ validation = customValidations.minLength(inputElement, 'djfg-dfg', 8);
75
+ expect(validation).to.equal('Length must be at least 8 characters', 'validation has correct value');
76
+
77
+ validation = customValidations.minLength(inputElement, 'djfg-dfg8', 8);
78
+ expect(validation).to.equal(false, 'validation has correct value');
79
+ });
80
+
81
+ it('maxLength', async () => {
82
+ let inputElement = {};
83
+ let validation = customValidations.maxLength(inputElement, '', 2);
84
+ expect(validation).to.equal(false, 'validation has correct value');
85
+
86
+ validation = customValidations.maxLength(inputElement, '353434', 6);
87
+ expect(validation).to.equal(false, 'validation has correct value');
88
+
89
+ validation = customValidations.maxLength(inputElement, 'djf-gdf-gdjd', 10);
90
+ expect(validation).to.equal('Length must be no longer than 10 characters', 'validation has correct value');
91
+
92
+ inputElement = { separator: '-' };
93
+ validation = customValidations.maxLength(inputElement, '353-434', 6);
94
+ expect(validation).to.equal(false, 'validation has correct value');
95
+
96
+ validation = customValidations.maxLength(inputElement, 'fer', 2);
97
+ expect(validation).to.equal('Length must be no longer than 2 characters', 'validation has correct value');
98
+ });
99
+
100
+ it('isBetween', async () => {
101
+ let inputElement = {};
102
+ let validation = customValidations.isBetween(inputElement, '', 2, 8);
103
+ expect(validation).to.equal(false, 'validation has correct value');
104
+
105
+ validation = customValidations.isBetween(inputElement, 's', 2, 8);
106
+ expect(validation).to.equal('Length must be between 2 and 8 characters', 'validation has correct value');
107
+
108
+ validation = customValidations.isBetween(inputElement, 'df', 2, 8);
109
+ expect(validation).to.equal(false, 'validation has correct value');
110
+
111
+ validation = customValidations.isBetween(inputElement, 'dfedfdfd', 2, 8);
112
+ expect(validation).to.equal(false, 'validation has correct value');
113
+
114
+ validation = customValidations.isBetween(inputElement, 'dfdfgdsfgsdfasd', 2, 8);
115
+ expect(validation).to.equal('Length must be between 2 and 8 characters', 'validation has correct value');
116
+
117
+ inputElement = { separator: '-' };
118
+ validation = customValidations.isBetween(inputElement, 'd-', 2, 8);
119
+ expect(validation).to.equal('Length must be between 2 and 8 characters', 'validation has correct value');
120
+
121
+ validation = customValidations.isBetween(inputElement, 'd-jfg-dfg', 2, 8);
122
+ expect(validation).to.equal(false, 'validation has correct value');
123
+ });
124
+
125
+ it('isDate', async () => {
126
+ const inputElement = {};
127
+ let validation = customValidations.isDate(inputElement, '');
128
+ expect(validation).to.equal('', 'validation has correct value');
129
+
130
+ validation = customValidations.isDate(inputElement, '23/10/2021');
131
+ expect(validation).to.equal('', 'validation has correct value');
132
+
133
+ validation = customValidations.isDate(inputElement, '2021-10-23');
134
+ expect(validation).to.equal('', 'validation has correct value');
135
+
136
+ validation = customValidations.isDate(inputElement, '36-10-2021');
137
+ expect(validation).to.equal('Your date does not look right', 'validation has correct value');
138
+
139
+ validation = customValidations.isDate(inputElement, '23/3d/2021');
140
+ expect(validation).to.equal('Your date does not look right', 'validation has correct value');
141
+
142
+ validation = customValidations.isDate(inputElement, '2f/03/2021');
143
+ expect(validation).to.equal('Your date does not look right', 'validation has correct value');
144
+
145
+ validation = customValidations.isDate(inputElement, '12/12/20');
146
+ expect(validation).to.equal('Your date does not look right', 'validation has correct value');
147
+
148
+ validation = customValidations.isDate(inputElement, '2021-23-10');
149
+ expect(validation).to.equal('Your date does not look right', 'validation has correct value');
150
+ });
151
+
152
+ it('minDate', async () => {
153
+ const inputElement = {};
154
+ let validation = customValidations.minDate(inputElement, '', '');
155
+ expect(validation).to.equal('', 'validation has correct value');
156
+
157
+ validation = customValidations.minDate(inputElement, '21/12/2021', '11/12/2021');
158
+ expect(validation).to.equal('', 'validation has correct value');
159
+
160
+ validation = customValidations.minDate(inputElement, '09/12/2021', '11/12/2021');
161
+ expect(validation).to.equal('Date must be on or after 11/12/2021', 'validation has correct value');
162
+ });
163
+
164
+ it('maxDate', async () => {
165
+ const inputElement = {};
166
+ let validation = customValidations.maxDate(inputElement, '', '');
167
+ expect(validation).to.equal('', 'validation has correct value');
168
+
169
+ validation = customValidations.maxDate(inputElement, '09/12/2021', '11/12/2021');
170
+ expect(validation).to.equal('', 'validation has correct value');
171
+
172
+ validation = customValidations.maxDate(inputElement, '21/12/2021', '11/12/2021');
173
+ expect(validation).to.equal('Date must be on or before 11/12/2021', 'validation has correct value');
174
+ });
175
+
176
+ it('hasNumbers', async () => {
177
+ const inputElement = {};
178
+ let validation = customValidations.hasNumbers(inputElement, '');
179
+ expect(validation).to.equal('', 'validation has correct value');
180
+
181
+ validation = customValidations.hasNumbers(inputElement, 'rgdfgdf');
182
+ expect(validation).to.equal('Must include at least one number', 'validation has correct value');
183
+
184
+ validation = customValidations.hasNumbers(inputElement, 'fgdf3gd');
185
+ expect(validation).to.equal('', 'validation has correct value');
186
+ });
187
+
188
+ it('hasLetters', async () => {
189
+ const inputElement = {};
190
+ let validation = customValidations.hasLetters(inputElement, '');
191
+ expect(validation).to.equal('', 'validation has correct value');
192
+
193
+ validation = customValidations.hasLetters(inputElement, '43232');
194
+ expect(validation).to.equal('Must include at least one letter', 'validation has correct value');
195
+
196
+ validation = customValidations.hasLetters(inputElement, '232d23');
197
+ expect(validation).to.equal('', 'validation has correct value');
198
+ });
199
+ });