@webitel/ui-datalist 26.8.26 → 26.8.28
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 +1 -1
- package/src/modules/card/composables/__tests__/useCardValidation.spec.ts +43 -2
- package/src/modules/card/composables/__tests__/useTimeRangesValidation.spec.ts +149 -0
- package/src/modules/card/composables/useTimeRangesValidation.ts +38 -0
- package/src/modules/card/index.ts +1 -0
- package/types/.tsbuildinfo +1 -1
- package/types/modules/card/composables/useTimeRangesValidation.d.ts +8 -0
- package/types/modules/card/index.d.ts +1 -0
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { useRegleSchema } from '@regle/schemas';
|
|
2
2
|
import { getQueueDefaults } from '@webitel/api-services/api';
|
|
3
3
|
import { QueueType } from '@webitel/api-services/enums';
|
|
4
|
-
import {
|
|
4
|
+
import { getDefaultsFromZodSchema } from '@webitel/api-services/utils';
|
|
5
|
+
import {
|
|
6
|
+
caseCloseFieldsChecks,
|
|
7
|
+
caseSchema,
|
|
8
|
+
queueSchema,
|
|
9
|
+
} from '@webitel/api-services/validations';
|
|
5
10
|
import { describe, expect, it } from 'vitest';
|
|
6
|
-
import { effectScope, ref } from 'vue';
|
|
11
|
+
import { effectScope, nextTick, ref } from 'vue';
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* A card whose required-ness comes from a root `superRefine` — the queue, whose
|
|
@@ -93,3 +98,39 @@ describe('card validation of a root-level required rule', () => {
|
|
|
93
98
|
expect(rootError).toBe(false);
|
|
94
99
|
});
|
|
95
100
|
});
|
|
101
|
+
|
|
102
|
+
describe('card validation of the close reason on a new final case', () => {
|
|
103
|
+
const caseCardSchema = caseSchema
|
|
104
|
+
.passthrough()
|
|
105
|
+
.check(...caseCloseFieldsChecks);
|
|
106
|
+
|
|
107
|
+
it('reports the missing close reason on the field', async () => {
|
|
108
|
+
const state = ref(getDefaultsFromZodSchema(caseCardSchema, {}) as never);
|
|
109
|
+
const scope = effectScope(true);
|
|
110
|
+
// biome-ignore lint/suspicious/noExplicitAny: regle's inferred state type
|
|
111
|
+
let r$: any;
|
|
112
|
+
|
|
113
|
+
scope.run(() => {
|
|
114
|
+
({ r$ } = useRegleSchema(state, caseCardSchema as never, {
|
|
115
|
+
autoDirty: true,
|
|
116
|
+
syncState: {
|
|
117
|
+
onValidate: true,
|
|
118
|
+
},
|
|
119
|
+
}));
|
|
120
|
+
});
|
|
121
|
+
await nextTick();
|
|
122
|
+
|
|
123
|
+
(state.value as Record<string, unknown>).statusCondition = {
|
|
124
|
+
id: '1',
|
|
125
|
+
final: true,
|
|
126
|
+
};
|
|
127
|
+
await nextTick();
|
|
128
|
+
|
|
129
|
+
const result = await r$.$validate();
|
|
130
|
+
|
|
131
|
+
expect(result.valid).toBe(false);
|
|
132
|
+
expect(r$.$fields.closeReason.$error).toBe(true);
|
|
133
|
+
expect(r$.$fields.closeReason.$errors).toHaveLength(1);
|
|
134
|
+
expect(r$.$fields.closeResult.$error).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils';
|
|
2
|
+
import {
|
|
3
|
+
getCalendarDayRangeErrors,
|
|
4
|
+
getResourceGroupTimeRangeErrors,
|
|
5
|
+
} from '@webitel/api-services/validations';
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
import { defineComponent, ref } from 'vue';
|
|
8
|
+
|
|
9
|
+
import { useTimeRangesValidation } from '../useTimeRangesValidation';
|
|
10
|
+
|
|
11
|
+
type CalendarDay = {
|
|
12
|
+
day: number;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const row = (day: number, start: number, end: number): CalendarDay => ({
|
|
19
|
+
day,
|
|
20
|
+
disabled: false,
|
|
21
|
+
start,
|
|
22
|
+
end,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const setup = (rows: CalendarDay[]) => {
|
|
26
|
+
const dataList = ref(rows);
|
|
27
|
+
|
|
28
|
+
const Comp = defineComponent({
|
|
29
|
+
setup: () => useTimeRangesValidation(dataList, getCalendarDayRangeErrors),
|
|
30
|
+
template: '<div />',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
dataList,
|
|
35
|
+
...(mount(Comp).vm as unknown as ReturnType<
|
|
36
|
+
typeof useTimeRangesValidation
|
|
37
|
+
>),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe('useTimeRangesValidation with calendar days', () => {
|
|
42
|
+
it('marks nothing for rows that do not overlap', () => {
|
|
43
|
+
const { getRangeValidation } = setup([
|
|
44
|
+
row(0, 540, 541),
|
|
45
|
+
row(0, 600, 660),
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
expect(getRangeValidation(0, 'start')).toBeUndefined();
|
|
49
|
+
expect(getRangeValidation(1, 'end')).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('marks both ends of a row that starts after it ends', () => {
|
|
53
|
+
const { getRangeValidation } = setup([
|
|
54
|
+
row(0, 600, 540),
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
expect(getRangeValidation(0, 'start')).toEqual({
|
|
58
|
+
$error: true,
|
|
59
|
+
$errors: [
|
|
60
|
+
'Time From cannot be greater than To',
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
expect(getRangeValidation(0, 'end')?.$error).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('marks every row of an overlap, and clears once it is resolved', () => {
|
|
67
|
+
const { dataList, getRangeValidation } = setup([
|
|
68
|
+
row(0, 540, 720),
|
|
69
|
+
row(0, 600, 780),
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
expect(getRangeValidation(0, 'start')?.$errors).toEqual([
|
|
73
|
+
'Time intervals on the same day cannot overlap',
|
|
74
|
+
]);
|
|
75
|
+
expect(getRangeValidation(1, 'start')?.$error).toBe(true);
|
|
76
|
+
|
|
77
|
+
dataList.value[1].start = 900;
|
|
78
|
+
dataList.value[1].end = 960;
|
|
79
|
+
|
|
80
|
+
expect(getRangeValidation(0, 'start')).toBeUndefined();
|
|
81
|
+
expect(getRangeValidation(1, 'start')).toBeUndefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('marks a time outside the day', () => {
|
|
85
|
+
const { getRangeValidation } = setup([
|
|
86
|
+
row(0, 0, 24 * 60),
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
expect(getRangeValidation(0, 'end')?.$errors).toEqual([
|
|
90
|
+
'Hours must be from 00 to 23',
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('useTimeRangesValidation with resource group ranges', () => {
|
|
96
|
+
const setupRanges = (
|
|
97
|
+
rows: {
|
|
98
|
+
start: number;
|
|
99
|
+
end: number;
|
|
100
|
+
}[],
|
|
101
|
+
) => {
|
|
102
|
+
const ranges = ref(rows);
|
|
103
|
+
|
|
104
|
+
const Comp = defineComponent({
|
|
105
|
+
setup: () =>
|
|
106
|
+
useTimeRangesValidation(ranges, getResourceGroupTimeRangeErrors),
|
|
107
|
+
template: '<div />',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
ranges,
|
|
112
|
+
...(mount(Comp).vm as unknown as ReturnType<
|
|
113
|
+
typeof useTimeRangesValidation
|
|
114
|
+
>),
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
it('marks both ends of a reversed range', () => {
|
|
119
|
+
const { getRangeValidation } = setupRanges([
|
|
120
|
+
{
|
|
121
|
+
start: 600,
|
|
122
|
+
end: 540,
|
|
123
|
+
},
|
|
124
|
+
]);
|
|
125
|
+
|
|
126
|
+
expect(getRangeValidation(0, 'start')?.$error).toBe(true);
|
|
127
|
+
expect(getRangeValidation(0, 'end')?.$error).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('marks intersecting ranges regardless of day', () => {
|
|
131
|
+
const { ranges, getRangeValidation } = setupRanges([
|
|
132
|
+
{
|
|
133
|
+
start: 540,
|
|
134
|
+
end: 720,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
start: 600,
|
|
138
|
+
end: 780,
|
|
139
|
+
},
|
|
140
|
+
]);
|
|
141
|
+
|
|
142
|
+
expect(getRangeValidation(1, 'end')?.$error).toBe(true);
|
|
143
|
+
|
|
144
|
+
ranges.value[1].start = 900;
|
|
145
|
+
ranges.value[1].end = 960;
|
|
146
|
+
|
|
147
|
+
expect(getRangeValidation(0, 'start')).toBeUndefined();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { TimeRangeError } from '@webitel/api-services/validations';
|
|
2
|
+
import { computed, type MaybeRefOrGetter, toValue } from 'vue';
|
|
3
|
+
import { useI18n } from 'vue-i18n';
|
|
4
|
+
|
|
5
|
+
export function useTimeRangesValidation(
|
|
6
|
+
items: MaybeRefOrGetter<unknown>,
|
|
7
|
+
getErrors: (items: unknown) => TimeRangeError[],
|
|
8
|
+
) {
|
|
9
|
+
const { t } = useI18n();
|
|
10
|
+
|
|
11
|
+
const errors = computed(() => {
|
|
12
|
+
const byField = new Map<string, string>();
|
|
13
|
+
|
|
14
|
+
for (const { index, prop, key } of getErrors(toValue(items))) {
|
|
15
|
+
const field = `${index}.${prop}`;
|
|
16
|
+
if (!byField.has(field)) byField.set(field, key);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return byField;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const getRangeValidation = (index: number, prop: string) => {
|
|
23
|
+
const key = errors.value.get(`${index}.${prop}`);
|
|
24
|
+
|
|
25
|
+
if (!key) return undefined;
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
$error: true,
|
|
29
|
+
$errors: [
|
|
30
|
+
t(`validation.${key}`),
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
getRangeValidation,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -4,5 +4,6 @@ export * from './composables/useCardListNavigation';
|
|
|
4
4
|
export * from './composables/useCardStoreProvider';
|
|
5
5
|
export * from './composables/useCardTabs';
|
|
6
6
|
export * from './composables/useNestedCardComponent';
|
|
7
|
+
export * from './composables/useTimeRangesValidation';
|
|
7
8
|
export * from './stores/createCardStore';
|
|
8
9
|
export * from './types/CardValidationFields.types';
|