@userfrosting/sprinkle-core 6.0.0-beta.7 → 6.0.0-beta.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/dist/Page401Unauthorized-Dkz0W0kI.js +11 -0
- package/dist/Page403Forbidden-CZrvZLe3.js +11 -0
- package/dist/Page404NotFound-C7Y20KCv.js +11 -0
- package/dist/PageError-wq0-2ksY.js +11 -0
- package/dist/_plugin-vue_export-helper-CHgC5LLL.js +9 -0
- package/dist/composables/index.d.ts +4 -0
- package/dist/composables/useAxiosInterceptor.d.ts +10 -0
- package/dist/composables/useCsrf.d.ts +18 -0
- package/dist/composables/useRuleSchemaAdapter.d.ts +7 -0
- package/dist/composables/useSprunjer.d.ts +2 -0
- package/dist/composables.js +151 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +15 -0
- package/{app/assets/interfaces/ApiResponse.ts → dist/interfaces/ApiResponse.d.ts} +5 -6
- package/{app/assets/interfaces/DictionaryApi.ts → dist/interfaces/DictionaryApi.d.ts} +9 -11
- package/dist/interfaces/alerts.d.ts +8 -0
- package/{app/assets/interfaces/common.ts → dist/interfaces/common.d.ts} +1 -1
- package/dist/interfaces/index.d.ts +13 -0
- package/{app/assets/interfaces/severity.ts → dist/interfaces/severity.d.ts} +9 -9
- package/dist/interfaces/sprunjer.d.ts +51 -0
- package/{app/assets/interfaces/sprunjerApi.ts → dist/interfaces/sprunjerApi.d.ts} +12 -15
- package/dist/interfaces.js +5 -0
- package/dist/routes/index.d.ts +16 -0
- package/dist/routes.js +41 -0
- package/dist/severity-DwLpzIij.js +4 -0
- package/{app/assets/stores/Helpers/PluralRules.ts → dist/stores/Helpers/PluralRules.d.ts} +17 -114
- package/dist/stores/index.d.ts +4 -0
- package/dist/stores/useAlertsStore.d.ts +29 -0
- package/dist/stores/useConfigStore.d.ts +11 -0
- package/dist/stores/usePageMeta.d.ts +51 -0
- package/dist/stores/useTranslator.d.ts +66 -0
- package/dist/stores.js +7 -0
- package/dist/useAlertsStore-BnSfoOG2.js +179 -0
- package/dist/useAxiosInterceptor-DTHSvv-f.js +68 -0
- package/dist/views/Page401Unauthorized.vue.d.ts +2 -0
- package/dist/views/Page403Forbidden.vue.d.ts +2 -0
- package/dist/views/Page404NotFound.vue.d.ts +2 -0
- package/dist/views/PageError.vue.d.ts +2 -0
- package/package.json +36 -8
- package/app/assets/composables/index.ts +0 -4
- package/app/assets/composables/useAxiosInterceptor.ts +0 -30
- package/app/assets/composables/useCsrf.ts +0 -129
- package/app/assets/composables/useRuleSchemaAdapter.ts +0 -205
- package/app/assets/composables/useSprunjer.ts +0 -188
- package/app/assets/index.d.ts +0 -8
- package/app/assets/index.ts +0 -40
- package/app/assets/interfaces/alerts.ts +0 -16
- package/app/assets/interfaces/index.ts +0 -30
- package/app/assets/interfaces/sprunjer.ts +0 -60
- package/app/assets/routes/index.ts +0 -44
- package/app/assets/stores/index.ts +0 -4
- package/app/assets/stores/useAlertsStore.ts +0 -30
- package/app/assets/stores/useConfigStore.ts +0 -30
- package/app/assets/stores/usePageMeta.ts +0 -114
- package/app/assets/stores/useTranslator.ts +0 -293
- package/app/assets/tests/composables/useCsrf.test.ts +0 -212
- package/app/assets/tests/composables/useRuleSchemaAdapter.test.ts +0 -657
- package/app/assets/tests/interfaces/alerts.test.ts +0 -43
- package/app/assets/tests/plugin.test.ts +0 -29
- package/app/assets/tests/stores/Helpers/PluralRules.test.ts +0 -440
- package/app/assets/tests/stores/config.test.ts +0 -42
- package/app/assets/tests/stores/useTranslator.test.ts +0 -373
- package/app/assets/views/Page401Unauthorized.vue +0 -3
- package/app/assets/views/Page403Forbidden.vue +0 -3
- package/app/assets/views/Page404NotFound.vue +0 -3
- package/app/assets/views/PageError.vue +0 -3
|
@@ -1,657 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, vi, afterEach } from 'vitest'
|
|
2
|
-
import { useRuleSchemaAdapter } from '../../composables/useRuleSchemaAdapter'
|
|
3
|
-
import { useRegle } from '@regle/core'
|
|
4
|
-
|
|
5
|
-
// Mock the translator store
|
|
6
|
-
const translateMock = vi.fn((key: string) => key || '')
|
|
7
|
-
vi.mock('@userfrosting/sprinkle-core/stores', () => ({
|
|
8
|
-
useTranslator: () => ({
|
|
9
|
-
translate: translateMock
|
|
10
|
-
})
|
|
11
|
-
}))
|
|
12
|
-
|
|
13
|
-
describe('useRuleSchemaAdapter', () => {
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
vi.clearAllMocks()
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
test('should parse a basic schema', () => {
|
|
19
|
-
const yamlInput = {
|
|
20
|
-
foo: {
|
|
21
|
-
validators: {
|
|
22
|
-
length: {
|
|
23
|
-
min: 1,
|
|
24
|
-
max: 132
|
|
25
|
-
},
|
|
26
|
-
required: true
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const { r$ } = useRegle(
|
|
32
|
-
{
|
|
33
|
-
foo: ''
|
|
34
|
-
},
|
|
35
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
expect(r$.foo).toBeDefined()
|
|
39
|
-
expect(r$.foo.$rules.required).toBeDefined()
|
|
40
|
-
expect(r$.foo.$rules.minLength).toBeDefined()
|
|
41
|
-
expect(r$.foo.$rules.maxLength).toBeDefined()
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('should parse a schema with a custom message', () => {
|
|
45
|
-
const yamlInput = {
|
|
46
|
-
name: {
|
|
47
|
-
validators: {
|
|
48
|
-
length: {
|
|
49
|
-
min: 2,
|
|
50
|
-
max: 20
|
|
51
|
-
},
|
|
52
|
-
required: true
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
email: {
|
|
56
|
-
validators: {
|
|
57
|
-
length: {
|
|
58
|
-
min: 1,
|
|
59
|
-
max: 30
|
|
60
|
-
},
|
|
61
|
-
email: true
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const { r$ } = useRegle(
|
|
67
|
-
{
|
|
68
|
-
name: '',
|
|
69
|
-
email: ''
|
|
70
|
-
},
|
|
71
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
expect(r$.name).toBeDefined()
|
|
75
|
-
expect(r$.name.$rules.required).toBeDefined()
|
|
76
|
-
expect(r$.name.$rules.minLength).toBeDefined()
|
|
77
|
-
expect(r$.name.$rules.maxLength).toBeDefined()
|
|
78
|
-
expect(r$.email).toBeDefined()
|
|
79
|
-
expect(r$.email.$rules.required).not.toBeDefined()
|
|
80
|
-
expect(r$.email.$rules.minLength).toBeDefined()
|
|
81
|
-
expect(r$.email.$rules.maxLength).toBeDefined()
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
test('should parse a bad schema without errors', () => {
|
|
85
|
-
// N.B.: The schema is missing the 'validators' key
|
|
86
|
-
const yamlInput = {
|
|
87
|
-
foo: {
|
|
88
|
-
length: {
|
|
89
|
-
min: 1,
|
|
90
|
-
max: 132
|
|
91
|
-
},
|
|
92
|
-
required: true
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const { r$ } = useRegle(
|
|
97
|
-
{
|
|
98
|
-
foo: ''
|
|
99
|
-
},
|
|
100
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
expect(r$.foo).toBeDefined()
|
|
104
|
-
expect(r$.foo.$rules.required).not.toBeDefined()
|
|
105
|
-
expect(r$.foo.$rules.minLength).not.toBeDefined()
|
|
106
|
-
expect(r$.foo.$rules.maxLength).not.toBeDefined()
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
test('required rule', () => {
|
|
110
|
-
const yamlInput = {
|
|
111
|
-
first_name: {
|
|
112
|
-
validators: {
|
|
113
|
-
required: {
|
|
114
|
-
label: '&FIRST_NAME',
|
|
115
|
-
message: 'VALIDATE.REQUIRED'
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
last_name: {
|
|
120
|
-
validators: {
|
|
121
|
-
required: true
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const { r$ } = useRegle(
|
|
127
|
-
{
|
|
128
|
-
first_name: '',
|
|
129
|
-
last_name: ''
|
|
130
|
-
},
|
|
131
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
// Set translator expectations
|
|
135
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.REQUIRED', {
|
|
136
|
-
label: '&FIRST_NAME'
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
expect(r$.first_name.$rules.required.$message).toBe('VALIDATE.REQUIRED') // Custom message
|
|
140
|
-
expect(r$.last_name.$rules.required.$message).toBe('This field is required') // Default message
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
test('email rule', () => {
|
|
144
|
-
const yamlInput = {
|
|
145
|
-
email: {
|
|
146
|
-
validators: {
|
|
147
|
-
email: {
|
|
148
|
-
message: 'VALIDATE.INVALID_EMAIL'
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
email2: {
|
|
153
|
-
validators: {
|
|
154
|
-
email: true
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const { r$ } = useRegle(
|
|
160
|
-
{
|
|
161
|
-
email: '',
|
|
162
|
-
email2: ''
|
|
163
|
-
},
|
|
164
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
// Set translator expectations
|
|
168
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.INVALID_EMAIL', {})
|
|
169
|
-
|
|
170
|
-
expect(r$.email.$rules.email.$message).toBe('VALIDATE.INVALID_EMAIL') // Custom message
|
|
171
|
-
expect(r$.email2.$rules.email.$message).toBe('This field is not valid') // Default message
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
test('length rule', () => {
|
|
175
|
-
const yamlInput = {
|
|
176
|
-
tooShort: {
|
|
177
|
-
validators: {
|
|
178
|
-
length: {
|
|
179
|
-
min: 5
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
tooLong: {
|
|
184
|
-
validators: {
|
|
185
|
-
length: {
|
|
186
|
-
max: 2
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
tooShortWithMessage: {
|
|
191
|
-
validators: {
|
|
192
|
-
length: {
|
|
193
|
-
min: 5,
|
|
194
|
-
message: 'VALIDATE.LENGTH_RANGE'
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
tooLongWithMessage: {
|
|
199
|
-
validators: {
|
|
200
|
-
length: {
|
|
201
|
-
max: 2,
|
|
202
|
-
message: 'VALIDATE.LENGTH_RANGE'
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const { r$ } = useRegle(
|
|
209
|
-
{
|
|
210
|
-
tooShort: '1',
|
|
211
|
-
tooLong: '123',
|
|
212
|
-
tooShortWithMessage: '1',
|
|
213
|
-
tooLongWithMessage: '123'
|
|
214
|
-
},
|
|
215
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
// Set translator expectations
|
|
219
|
-
expect(translateMock).toHaveBeenNthCalledWith(1, 'VALIDATE.LENGTH_RANGE', { min: 5 })
|
|
220
|
-
expect(translateMock).toHaveBeenNthCalledWith(2, 'VALIDATE.LENGTH_RANGE', { max: 2 })
|
|
221
|
-
|
|
222
|
-
expect(r$.tooShort.$silentErrors).toEqual(['The value length should be at least 5']) // Custom message
|
|
223
|
-
expect(r$.tooLong.$silentErrors).toEqual(['The value length should not exceed 2']) // Default message
|
|
224
|
-
expect(r$.tooShortWithMessage.$silentErrors).toEqual(['VALIDATE.LENGTH_RANGE']) // Custom message
|
|
225
|
-
expect(r$.tooLongWithMessage.$silentErrors).toEqual(['VALIDATE.LENGTH_RANGE']) // Default message
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
test('integer rule', () => {
|
|
229
|
-
const yamlInput = {
|
|
230
|
-
foo: {
|
|
231
|
-
validators: {
|
|
232
|
-
integer: true
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
bar: {
|
|
236
|
-
validators: {
|
|
237
|
-
integer: {
|
|
238
|
-
message: 'VALIDATE.INVALID_INTEGER'
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
},
|
|
242
|
-
foobar: {
|
|
243
|
-
validators: {
|
|
244
|
-
integer: true
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const { r$ } = useRegle(
|
|
250
|
-
{
|
|
251
|
-
foo: 'one',
|
|
252
|
-
bar: 'two',
|
|
253
|
-
foobar: 92
|
|
254
|
-
},
|
|
255
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
256
|
-
)
|
|
257
|
-
|
|
258
|
-
// Set translator expectations
|
|
259
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.INVALID_INTEGER', {})
|
|
260
|
-
|
|
261
|
-
expect(r$.foo.$silentErrors).toEqual(['The value must be an integer']) // Custom message
|
|
262
|
-
expect(r$.bar.$silentErrors).toEqual(['VALIDATE.INVALID_INTEGER']) // Default message
|
|
263
|
-
expect(r$.foobar.$silentErrors).toEqual([]) // Valid
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
test('member_of rule', () => {
|
|
267
|
-
const yamlInput = {
|
|
268
|
-
genus: {
|
|
269
|
-
validators: {
|
|
270
|
-
member_of: {
|
|
271
|
-
values: ['Megascops', 'Bubo', 'Glaucidium', 'Tyto', 'Athene'],
|
|
272
|
-
message: 'Sorry, that is not one of the permitted genuses.'
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
owls: {
|
|
277
|
-
validators: {
|
|
278
|
-
member_of: {
|
|
279
|
-
values: ['Foo', 'Bar']
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
},
|
|
283
|
-
valid: {
|
|
284
|
-
validators: {
|
|
285
|
-
member_of: {
|
|
286
|
-
values: ['Foo', 'Bar']
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const { r$ } = useRegle(
|
|
293
|
-
{
|
|
294
|
-
genus: 'Foo',
|
|
295
|
-
owls: 'Hedwig',
|
|
296
|
-
valid: 'Foo'
|
|
297
|
-
},
|
|
298
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
299
|
-
)
|
|
300
|
-
|
|
301
|
-
// Set translator expectations
|
|
302
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith(
|
|
303
|
-
'Sorry, that is not one of the permitted genuses.',
|
|
304
|
-
{
|
|
305
|
-
values: ['Megascops', 'Bubo', 'Glaucidium', 'Tyto', 'Athene']
|
|
306
|
-
}
|
|
307
|
-
)
|
|
308
|
-
|
|
309
|
-
expect(r$.genus.$silentErrors).toEqual(['Sorry, that is not one of the permitted genuses.']) // Custom message
|
|
310
|
-
expect(r$.owls.$silentErrors).toEqual([
|
|
311
|
-
'The value should be one of those options: Foo, Bar.'
|
|
312
|
-
]) // Default message
|
|
313
|
-
expect(r$.valid.$silentErrors).toEqual([]) // Valid
|
|
314
|
-
})
|
|
315
|
-
|
|
316
|
-
test('not_member_of rule', () => {
|
|
317
|
-
const yamlInput = {
|
|
318
|
-
genus: {
|
|
319
|
-
validators: {
|
|
320
|
-
not_member_of: {
|
|
321
|
-
values: ['Megascops', 'Bubo', 'Glaucidium', 'Tyto', 'Athene'],
|
|
322
|
-
message: 'VALIDATE.NOT_MEMBER_OF'
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
owls: {
|
|
327
|
-
validators: {
|
|
328
|
-
not_member_of: {
|
|
329
|
-
values: ['Foo', 'Bar']
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
},
|
|
333
|
-
valid: {
|
|
334
|
-
validators: {
|
|
335
|
-
not_member_of: {
|
|
336
|
-
values: ['Foo', 'Bar']
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const { r$ } = useRegle(
|
|
343
|
-
{
|
|
344
|
-
genus: 'Megascops',
|
|
345
|
-
owls: 'Foo',
|
|
346
|
-
valid: 'Hedwig'
|
|
347
|
-
},
|
|
348
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
349
|
-
)
|
|
350
|
-
|
|
351
|
-
// Set translator expectations
|
|
352
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.NOT_MEMBER_OF', {
|
|
353
|
-
values: ['Megascops', 'Bubo', 'Glaucidium', 'Tyto', 'Athene']
|
|
354
|
-
})
|
|
355
|
-
|
|
356
|
-
expect(r$.genus.$silentErrors).toEqual(['VALIDATE.NOT_MEMBER_OF']) // Custom message
|
|
357
|
-
expect(r$.owls.$silentErrors).toEqual(['Error']) // Default message
|
|
358
|
-
expect(r$.valid.$silentErrors).toEqual([]) // Valid
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
test('no_leading_whitespace rule', () => {
|
|
362
|
-
const yamlInput = {
|
|
363
|
-
withMessage: {
|
|
364
|
-
validators: {
|
|
365
|
-
no_leading_whitespace: {
|
|
366
|
-
label: '&USERNAME',
|
|
367
|
-
message: 'VALIDATE.NO_LEAD_WS'
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
defaultMessage: {
|
|
372
|
-
validators: {
|
|
373
|
-
no_leading_whitespace: true
|
|
374
|
-
}
|
|
375
|
-
},
|
|
376
|
-
valid: {
|
|
377
|
-
validators: {
|
|
378
|
-
no_leading_whitespace: true
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
const { r$ } = useRegle(
|
|
384
|
-
{
|
|
385
|
-
withMessage: ' Foo',
|
|
386
|
-
defaultMessage: ' Foo',
|
|
387
|
-
valid: 'Foo'
|
|
388
|
-
},
|
|
389
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
// Set translator expectations
|
|
393
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.NO_LEAD_WS', {
|
|
394
|
-
label: '&USERNAME'
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
expect(r$.withMessage.$silentErrors).toEqual(['VALIDATE.NO_LEAD_WS']) // Custom message
|
|
398
|
-
expect(r$.defaultMessage.$silentErrors).toEqual([
|
|
399
|
-
'The value does not match the required pattern'
|
|
400
|
-
]) // Default message
|
|
401
|
-
expect(r$.valid.$silentErrors).toEqual([]) // Valid
|
|
402
|
-
})
|
|
403
|
-
|
|
404
|
-
test('no_trailing_whitespace rule', () => {
|
|
405
|
-
const yamlInput = {
|
|
406
|
-
withMessage: {
|
|
407
|
-
validators: {
|
|
408
|
-
no_trailing_whitespace: {
|
|
409
|
-
label: '&USERNAME',
|
|
410
|
-
message: 'VALIDATE.NO_TRAIL_WS'
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
},
|
|
414
|
-
defaultMessage: {
|
|
415
|
-
validators: {
|
|
416
|
-
no_trailing_whitespace: true
|
|
417
|
-
}
|
|
418
|
-
},
|
|
419
|
-
valid: {
|
|
420
|
-
validators: {
|
|
421
|
-
no_trailing_whitespace: true
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
const { r$ } = useRegle(
|
|
427
|
-
{
|
|
428
|
-
withMessage: 'Foo ',
|
|
429
|
-
defaultMessage: 'Foo ',
|
|
430
|
-
valid: 'Foo'
|
|
431
|
-
},
|
|
432
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
433
|
-
)
|
|
434
|
-
|
|
435
|
-
// Set translator expectations
|
|
436
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.NO_TRAIL_WS', {
|
|
437
|
-
label: '&USERNAME'
|
|
438
|
-
})
|
|
439
|
-
|
|
440
|
-
expect(r$.withMessage.$silentErrors).toEqual(['VALIDATE.NO_TRAIL_WS']) // Custom message
|
|
441
|
-
expect(r$.defaultMessage.$silentErrors).toEqual([
|
|
442
|
-
'The value does not match the required pattern'
|
|
443
|
-
]) // Default message
|
|
444
|
-
expect(r$.valid.$silentErrors).toEqual([]) // Valid
|
|
445
|
-
})
|
|
446
|
-
|
|
447
|
-
test('numeric rule', () => {
|
|
448
|
-
const yamlInput = {
|
|
449
|
-
withMessage: {
|
|
450
|
-
validators: {
|
|
451
|
-
numeric: {
|
|
452
|
-
message: 'VALIDATE.INVALID_NUMERIC'
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
},
|
|
456
|
-
defaultMessage: {
|
|
457
|
-
validators: {
|
|
458
|
-
numeric: true
|
|
459
|
-
}
|
|
460
|
-
},
|
|
461
|
-
valid: {
|
|
462
|
-
validators: {
|
|
463
|
-
numeric: true
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
const { r$ } = useRegle(
|
|
469
|
-
{
|
|
470
|
-
withMessage: 'Foo',
|
|
471
|
-
defaultMessage: 'Foo',
|
|
472
|
-
valid: '10.2'
|
|
473
|
-
},
|
|
474
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
475
|
-
)
|
|
476
|
-
|
|
477
|
-
// Set translator expectations
|
|
478
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.INVALID_NUMERIC', {})
|
|
479
|
-
|
|
480
|
-
expect(r$.withMessage.$silentErrors).toEqual(['VALIDATE.INVALID_NUMERIC']) // Custom message
|
|
481
|
-
expect(r$.defaultMessage.$silentErrors).toEqual(['The value must be numeric']) // Default message
|
|
482
|
-
expect(r$.valid.$silentErrors).toEqual([]) // Valid
|
|
483
|
-
})
|
|
484
|
-
|
|
485
|
-
test('range rule', () => {
|
|
486
|
-
const yamlInput = {
|
|
487
|
-
withMessage: {
|
|
488
|
-
validators: {
|
|
489
|
-
range: {
|
|
490
|
-
min: 0,
|
|
491
|
-
max: 10,
|
|
492
|
-
message: 'VALIDATE.INVALID_RANGE'
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
},
|
|
496
|
-
defaultMessage: {
|
|
497
|
-
validators: {
|
|
498
|
-
range: {
|
|
499
|
-
min: 0,
|
|
500
|
-
max: 10
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
},
|
|
504
|
-
valid: {
|
|
505
|
-
validators: {
|
|
506
|
-
range: {
|
|
507
|
-
min: 0,
|
|
508
|
-
max: 10
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
const { r$ } = useRegle(
|
|
515
|
-
{
|
|
516
|
-
withMessage: 92,
|
|
517
|
-
defaultMessage: 92,
|
|
518
|
-
valid: 9
|
|
519
|
-
},
|
|
520
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
521
|
-
)
|
|
522
|
-
|
|
523
|
-
// Set translator expectations
|
|
524
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.INVALID_RANGE', {
|
|
525
|
-
min: 0,
|
|
526
|
-
max: 10
|
|
527
|
-
})
|
|
528
|
-
|
|
529
|
-
expect(r$.withMessage.$silentErrors).toEqual(['VALIDATE.INVALID_RANGE']) // Custom message
|
|
530
|
-
expect(r$.defaultMessage.$silentErrors).toEqual(['The value must be between 0 and 10']) // Default message
|
|
531
|
-
expect(r$.valid.$silentErrors).toEqual([]) // Valid
|
|
532
|
-
})
|
|
533
|
-
|
|
534
|
-
test('regex rule', () => {
|
|
535
|
-
const yamlInput = {
|
|
536
|
-
withMessage: {
|
|
537
|
-
validators: {
|
|
538
|
-
regex: {
|
|
539
|
-
regex: '^who(o*)$',
|
|
540
|
-
message: 'VALIDATE.INVALID_VALUE'
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
},
|
|
544
|
-
defaultMessage: {
|
|
545
|
-
validators: {
|
|
546
|
-
regex: {
|
|
547
|
-
regex: '^who(o*)$'
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
},
|
|
551
|
-
valid: {
|
|
552
|
-
validators: {
|
|
553
|
-
regex: {
|
|
554
|
-
regex: '^who(o*)$'
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
const { r$ } = useRegle(
|
|
561
|
-
{
|
|
562
|
-
withMessage: 'hum',
|
|
563
|
-
defaultMessage: 'hello',
|
|
564
|
-
valid: 'whooo'
|
|
565
|
-
},
|
|
566
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
567
|
-
)
|
|
568
|
-
r$.$validate()
|
|
569
|
-
|
|
570
|
-
// Set translator expectations
|
|
571
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.INVALID_VALUE', {
|
|
572
|
-
regex: '^who(o*)$'
|
|
573
|
-
})
|
|
574
|
-
|
|
575
|
-
expect(r$.withMessage.$errors).toEqual(['VALIDATE.INVALID_VALUE']) // Custom message
|
|
576
|
-
expect(r$.defaultMessage.$errors).toEqual(['The value does not match the required pattern']) // Default message
|
|
577
|
-
expect(r$.valid.$correct).toEqual(true) // Valid
|
|
578
|
-
})
|
|
579
|
-
|
|
580
|
-
test('uri rule', () => {
|
|
581
|
-
const yamlInput = {
|
|
582
|
-
withMessage: {
|
|
583
|
-
validators: {
|
|
584
|
-
uri: {
|
|
585
|
-
message: 'VALIDATE.INVALID_URL'
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
},
|
|
589
|
-
defaultMessage: {
|
|
590
|
-
validators: {
|
|
591
|
-
uri: true
|
|
592
|
-
}
|
|
593
|
-
},
|
|
594
|
-
valid: {
|
|
595
|
-
validators: {
|
|
596
|
-
uri: true
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
const { r$ } = useRegle(
|
|
602
|
-
{
|
|
603
|
-
withMessage: 'foo',
|
|
604
|
-
defaultMessage: 'bar@example.com',
|
|
605
|
-
valid: 'http://example.com'
|
|
606
|
-
},
|
|
607
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
608
|
-
)
|
|
609
|
-
|
|
610
|
-
// Set translator expectations
|
|
611
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.INVALID_URL', {})
|
|
612
|
-
|
|
613
|
-
expect(r$.withMessage.$silentErrors).toEqual(['VALIDATE.INVALID_URL']) // Custom message
|
|
614
|
-
expect(r$.defaultMessage.$silentErrors).toEqual(['The value is not a valid URL address']) // Default message
|
|
615
|
-
expect(r$.valid.$silentErrors).toEqual([]) // Valid
|
|
616
|
-
})
|
|
617
|
-
|
|
618
|
-
test('username rule', () => {
|
|
619
|
-
const yamlInput = {
|
|
620
|
-
withMessage: {
|
|
621
|
-
validators: {
|
|
622
|
-
username: {
|
|
623
|
-
message: 'VALIDATE.INVALID_USERNAME'
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
},
|
|
627
|
-
defaultMessage: {
|
|
628
|
-
validators: {
|
|
629
|
-
username: true
|
|
630
|
-
}
|
|
631
|
-
},
|
|
632
|
-
valid: {
|
|
633
|
-
validators: {
|
|
634
|
-
username: true
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
const { r$ } = useRegle(
|
|
640
|
-
{
|
|
641
|
-
withMessage: 'My Name',
|
|
642
|
-
defaultMessage: 'bar@example.com',
|
|
643
|
-
valid: 'foo.bar-bax_123'
|
|
644
|
-
},
|
|
645
|
-
useRuleSchemaAdapter().adapt(yamlInput)
|
|
646
|
-
)
|
|
647
|
-
|
|
648
|
-
// Set translator expectations
|
|
649
|
-
expect(translateMock).toHaveBeenCalledExactlyOnceWith('VALIDATE.INVALID_USERNAME', {})
|
|
650
|
-
|
|
651
|
-
expect(r$.withMessage.$silentErrors).toEqual(['VALIDATE.INVALID_USERNAME']) // Custom message
|
|
652
|
-
expect(r$.defaultMessage.$silentErrors).toEqual([
|
|
653
|
-
'The value does not match the required pattern'
|
|
654
|
-
]) // Default message
|
|
655
|
-
expect(r$.valid.$silentErrors).toEqual([]) // Valid
|
|
656
|
-
})
|
|
657
|
-
})
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import { type AlertInterface, Severity } from '../../interfaces'
|
|
3
|
-
|
|
4
|
-
describe('AlertInterface', () => {
|
|
5
|
-
test('should create an alert with title and description', () => {
|
|
6
|
-
const alert: AlertInterface = {
|
|
7
|
-
title: 'Test Alert',
|
|
8
|
-
description: 'This is a test alert'
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
expect(alert.title).toBe('Test Alert')
|
|
12
|
-
expect(alert.description).toBe('This is a test alert')
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('should create an alert with style', () => {
|
|
16
|
-
const alert: AlertInterface = {
|
|
17
|
-
style: Severity.Success
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
expect(alert.style).toBe(Severity.Success)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('should create an alert with close button and hide icon', () => {
|
|
24
|
-
const alert: AlertInterface = {
|
|
25
|
-
closeBtn: true,
|
|
26
|
-
hideIcon: true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
expect(alert.closeBtn).toBe(true)
|
|
30
|
-
expect(alert.hideIcon).toBe(true)
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
describe('Severity', () => {
|
|
35
|
-
test('should have the correct values', () => {
|
|
36
|
-
expect(Severity.Primary).toBe('Primary')
|
|
37
|
-
expect(Severity.Secondary).toBe('Secondary')
|
|
38
|
-
expect(Severity.Success).toBe('Success')
|
|
39
|
-
expect(Severity.Warning).toBe('Warning')
|
|
40
|
-
expect(Severity.Danger).toBe('Danger')
|
|
41
|
-
expect(Severity.Info).toBe('Info')
|
|
42
|
-
})
|
|
43
|
-
})
|