@webitel/ui-datalist 26.8.12 → 26.8.13
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
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { reactive } from 'vue';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
createFiltersManager,
|
|
7
|
+
type IFiltersManager,
|
|
8
|
+
} from '../../../classes/FiltersManager';
|
|
9
|
+
import DynamicFilterSearch from '../dynamic-filter-search.vue';
|
|
10
|
+
|
|
11
|
+
const searchModeOptions = [
|
|
12
|
+
{
|
|
13
|
+
value: 'name',
|
|
14
|
+
text: 'Name',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
value: 'about',
|
|
18
|
+
text: 'About',
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const newFiltersManager = () =>
|
|
23
|
+
reactive(createFiltersManager()) as IFiltersManager;
|
|
24
|
+
|
|
25
|
+
const mountSearch = (
|
|
26
|
+
filtersManager: IFiltersManager,
|
|
27
|
+
props: Record<string, unknown> = {},
|
|
28
|
+
) =>
|
|
29
|
+
shallowMount(DynamicFilterSearch, {
|
|
30
|
+
props: {
|
|
31
|
+
filtersManager,
|
|
32
|
+
...props,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/* wt-search-bar is an async component, shallowMount renders it as the root stub */
|
|
37
|
+
const searchBarValue = (wrapper: ReturnType<typeof mountSearch>) =>
|
|
38
|
+
wrapper.attributes('value');
|
|
39
|
+
|
|
40
|
+
describe('dynamic-filter-search', () => {
|
|
41
|
+
it('restores the value of the filter of the current search mode', async () => {
|
|
42
|
+
const filtersManager = newFiltersManager();
|
|
43
|
+
|
|
44
|
+
const wrapper = mountSearch(filtersManager, {
|
|
45
|
+
searchModeOptions,
|
|
46
|
+
searchMode: 'name',
|
|
47
|
+
isFiltersRestoring: true,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
filtersManager.addFilter({
|
|
51
|
+
name: 'name',
|
|
52
|
+
value: 'john',
|
|
53
|
+
});
|
|
54
|
+
await wrapper.setProps({
|
|
55
|
+
isFiltersRestoring: false,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(searchBarValue(wrapper)).toBe('john');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('switches the search mode to the restored search filter', async () => {
|
|
62
|
+
const filtersManager = newFiltersManager();
|
|
63
|
+
|
|
64
|
+
const wrapper = mountSearch(filtersManager, {
|
|
65
|
+
searchModeOptions,
|
|
66
|
+
searchMode: '',
|
|
67
|
+
isFiltersRestoring: true,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
filtersManager.addFilter({
|
|
71
|
+
name: 'about',
|
|
72
|
+
value: 'manager',
|
|
73
|
+
});
|
|
74
|
+
await wrapper.setProps({
|
|
75
|
+
isFiltersRestoring: false,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(searchBarValue(wrapper)).toBe('manager');
|
|
79
|
+
expect(wrapper.emitted('update:searchMode')?.at(-1)).toEqual([
|
|
80
|
+
'about',
|
|
81
|
+
]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('restores the value of a single search filter', () => {
|
|
85
|
+
const filtersManager = newFiltersManager();
|
|
86
|
+
filtersManager.addFilter({
|
|
87
|
+
name: 'q',
|
|
88
|
+
value: 'john',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const wrapper = mountSearch(filtersManager, {
|
|
92
|
+
singleSearchName: 'q',
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(searchBarValue(wrapper)).toBe('john');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -155,12 +155,14 @@ watch(
|
|
|
155
155
|
(next) => {
|
|
156
156
|
if (next) return;
|
|
157
157
|
|
|
158
|
-
const searchModes =
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
const searchModes = hasSearchModes.value
|
|
159
|
+
? (props.searchModeOptions?.map((option) => option.value) ?? [])
|
|
160
|
+
: [
|
|
161
|
+
defaultSearchName,
|
|
162
|
+
];
|
|
163
|
+
|
|
161
164
|
if (hasSearchModes.value && !searchMode.value) {
|
|
162
|
-
searchMode.value =
|
|
163
|
-
props.searchModeOptions?.map((option) => option.value)[0] || '';
|
|
165
|
+
searchMode.value = searchModes[0] || '';
|
|
164
166
|
}
|
|
165
167
|
|
|
166
168
|
for (const mode of searchModes) {
|