@webitel/ui-sdk 0.9.64 → 0.9.65
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/ui-sdk.common.js +47 -47
- package/dist/ui-sdk.common.js.map +1 -1
- package/dist/ui-sdk.umd.js +47 -47
- package/dist/ui-sdk.umd.js.map +1 -1
- package/dist/ui-sdk.umd.min.js.map +1 -1
- package/package.json +2 -3
- package/src/modules/QueryFilters/api/__tests__/defaults.spec.js +18 -0
- package/src/modules/QueryFilters/api/defaults.js +16 -0
- package/src/modules/QueryFilters/components/__tests__/abstract-enum-filter.spec.js +0 -3
- package/src/modules/QueryFilters/components/__tests__/filter-search.spec.js +28 -23
- package/src/modules/QueryFilters/components/filter-search.vue +1 -1
- package/src/modules/QueryFilters/mixins/__tests__/apiFilterMixin.spec.js +14 -15
- package/src/modules/QueryFilters/mixins/__tests__/enumFilterMixin.spec.js +35 -50
- package/src/modules/QueryFilters/mixins/__tests__/paginationFilterMixin.spec.js +86 -0
- package/src/modules/QueryFilters/mixins/__tests__/sortFilterMixin.spec.js +11 -16
- package/src/modules/QueryFilters/mixins/__tests__/urlControllerMixin.spec.js +48 -0
- package/src/modules/QueryFilters/mixins/_urlControllerMixin/_urlControllerMixin.js +39 -0
- package/src/modules/QueryFilters/mixins/baseFilterMixin/baseFilterMixin.js +2 -8
- package/src/modules/QueryFilters/mixins/enumFilterMixin.js +9 -11
- package/src/modules/QueryFilters/mixins/paginationFilterMixin.js +76 -0
- package/src/modules/QueryFilters/store/QueryFiltersStoreModule.js +0 -6
- package/src/modules/QueryFilters/store/queryFilters.js +6 -0
- package/src/modules/QueryFilters/components/__tests__/filter-pagination.spec.js +0 -71
- package/src/modules/QueryFilters/components/filter-pagination.vue +0 -110
- package/src/modules/QueryFilters/store/QueryControllerStoreModule.js +0 -64
- package/src/modules/QueryFilters/store/__tests__/QueryControllerStoreModule.spec.js +0 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webitel/ui-sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.65",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"serve-lib": "vue-cli-service serve",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"test:unit": "vue-cli-service test:unit",
|
|
9
9
|
"lint": "vue-cli-service lint --fix",
|
|
10
10
|
"build-lib": "vue-cli-service build --target lib --name ui-sdk ./src/install.js",
|
|
11
|
-
"build-publish-lib": "npm run test:unit && npm run build-lib && npm publish --access public"
|
|
12
|
-
"build-publish-lib:testless": "npm run build-lib && npm publish --access public"
|
|
11
|
+
"build-publish-lib": "npm run test:unit && npm run build-lib && npm publish --access public"
|
|
13
12
|
},
|
|
14
13
|
"main": "./dist/@webitel/ui-sdk.common.js",
|
|
15
14
|
"files": [
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { listResponseHandler } from '../defaults';
|
|
2
|
+
|
|
3
|
+
describe('filter api Defaults', () => {
|
|
4
|
+
it('listResponseHandler returns only lookups from response', () => {
|
|
5
|
+
const response = {
|
|
6
|
+
items: [
|
|
7
|
+
{ name: 'jest1', id: 1, myField: '1' },
|
|
8
|
+
{ name: 'jest2', id: 2, obj: [] },
|
|
9
|
+
],
|
|
10
|
+
next: true,
|
|
11
|
+
};
|
|
12
|
+
const expectedResult = [
|
|
13
|
+
{ name: 'jest1', id: 1 },
|
|
14
|
+
{ name: 'jest2', id: 2 },
|
|
15
|
+
];
|
|
16
|
+
expect(listResponseHandler(response)).toEqual(expectedResult);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const PAGE = 1;
|
|
2
|
+
const SIZE = 20;
|
|
3
|
+
const FIELDS = ['id', 'name'];
|
|
4
|
+
|
|
5
|
+
export const defaultParams = {
|
|
6
|
+
page: PAGE,
|
|
7
|
+
size: SIZE,
|
|
8
|
+
fields: FIELDS,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const listResponseHandler = (response) => (
|
|
12
|
+
response.items.map((item) => ({
|
|
13
|
+
name: item.name,
|
|
14
|
+
id: item.id,
|
|
15
|
+
}))
|
|
16
|
+
);
|
|
@@ -1,44 +1,49 @@
|
|
|
1
|
-
import { shallowMount } from '@vue/test-utils';
|
|
1
|
+
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
|
2
|
+
import Vuex from 'vuex';
|
|
3
|
+
import VueRouter from 'vue-router';
|
|
2
4
|
import SearchFilter from '../filter-search.vue';
|
|
3
5
|
import BaseFilterSchema from '../../classes/BaseFilterSchema';
|
|
4
6
|
import baseFilterMixin from '../../mixins/baseFilterMixin/baseFilterMixin';
|
|
5
7
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
8
|
+
const localVue = createLocalVue();
|
|
9
|
+
localVue.use(Vuex);
|
|
10
|
+
localVue.use(VueRouter);
|
|
11
|
+
const router = new VueRouter();
|
|
10
12
|
|
|
11
13
|
describe('Search Filter', () => {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
14
|
+
const namespace = 'jest';
|
|
15
|
+
const filterQuery = 'jest';
|
|
16
|
+
const filterSchema = new BaseFilterSchema();
|
|
17
|
+
const store = new Vuex.Store({
|
|
18
|
+
modules: {
|
|
19
|
+
[namespace]: {
|
|
20
|
+
namespaced: true,
|
|
21
|
+
state: {
|
|
22
|
+
[filterQuery]: filterSchema,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
15
27
|
|
|
16
28
|
const mountOptions = {
|
|
29
|
+
localVue,
|
|
30
|
+
store,
|
|
31
|
+
router,
|
|
17
32
|
propsData: {
|
|
18
33
|
namespace,
|
|
19
34
|
filterQuery,
|
|
20
35
|
},
|
|
21
|
-
computed: {
|
|
22
|
-
filterSchema() { return filterSchema; },
|
|
23
|
-
},
|
|
24
36
|
};
|
|
25
|
-
|
|
26
|
-
jest.spyOn(baseFilterMixin.methods, 'setValue').mockImplementation(setValue);
|
|
27
|
-
jest.spyOn(baseFilterMixin.methods, 'setValueToQuery').mockImplementation(setValueToQuery);
|
|
28
|
-
jest.spyOn(baseFilterMixin.methods, 'getValueFromQuery').mockImplementation(getValueFromQuery);
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
setValue.mockClear();
|
|
32
|
-
setValueToQuery.mockClear();
|
|
33
|
-
getValueFromQuery.mockClear();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
37
|
it('renders a component', () => {
|
|
37
38
|
const wrapper = shallowMount(SearchFilter, mountOptions);
|
|
38
39
|
expect(wrapper.exists()).toBe(true);
|
|
39
40
|
});
|
|
40
41
|
it('initial restoreValue() triggers setValue() method', async () => {
|
|
42
|
+
const search = 'jest';
|
|
43
|
+
await router.replace({ query: { [filterQuery]: search } });
|
|
44
|
+
const setValueMock = jest.fn();
|
|
45
|
+
jest.spyOn(baseFilterMixin.methods, 'setValue').mockImplementationOnce(setValueMock);
|
|
41
46
|
shallowMount(SearchFilter, mountOptions);
|
|
42
|
-
expect(
|
|
47
|
+
expect(setValueMock).toHaveBeenCalledWith({ filter: filterQuery, value: search });
|
|
43
48
|
});
|
|
44
49
|
});
|
|
@@ -1,48 +1,47 @@
|
|
|
1
|
-
import { shallowMount } from '@vue/test-utils';
|
|
1
|
+
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
2
|
+
import VueRouter from 'vue-router';
|
|
2
3
|
import ApiFilterSchema from '../../classes/ApiFilterSchema';
|
|
3
4
|
import apiFilterMixin from '../apiFilterMixin';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
+
const localVue = createLocalVue();
|
|
7
|
+
localVue.use(VueRouter);
|
|
8
|
+
const router = new VueRouter();
|
|
6
9
|
const team = ['1', '2'];
|
|
7
10
|
const filterSchema = new ApiFilterSchema();
|
|
8
11
|
|
|
9
12
|
describe('API filter mixin', () => {
|
|
10
13
|
const setValue = jest.fn();
|
|
11
|
-
const setValueToQuery = jest.fn();
|
|
12
|
-
const getValueFromQuery = jest.fn(() => team);
|
|
13
|
-
|
|
14
14
|
const Component = {
|
|
15
15
|
render() {},
|
|
16
16
|
mixins: [apiFilterMixin],
|
|
17
17
|
data: () => ({
|
|
18
|
-
filterQuery,
|
|
18
|
+
filterQuery: 'team',
|
|
19
19
|
}),
|
|
20
20
|
computed: {
|
|
21
21
|
filterSchema() { return filterSchema; },
|
|
22
22
|
},
|
|
23
|
-
methods: {
|
|
24
|
-
setValue,
|
|
25
|
-
setValueToQuery,
|
|
26
|
-
getValueFromQuery,
|
|
27
|
-
},
|
|
23
|
+
methods: { setValue },
|
|
28
24
|
};
|
|
29
25
|
|
|
30
26
|
beforeEach(() => {
|
|
31
27
|
setValue.mockClear();
|
|
32
|
-
|
|
33
|
-
getValueFromQuery.mockClear();
|
|
28
|
+
if (Object.keys(router.currentRoute.query).length) router.replace({ query: null });
|
|
34
29
|
});
|
|
35
30
|
|
|
36
31
|
it('Correctly sets value from $route query', async () => {
|
|
32
|
+
await router.replace({ query: { team } });
|
|
37
33
|
const wrapper = shallowMount(Component, {
|
|
34
|
+
localVue,
|
|
35
|
+
router,
|
|
38
36
|
});
|
|
39
37
|
expect(setValue).toHaveBeenCalledWith({ filter: 'team', value: [{ id: team[0] }, { id: team[1] }] });
|
|
40
38
|
});
|
|
41
39
|
|
|
42
40
|
it('Sets empty array value if $route query is empty', async () => {
|
|
43
|
-
getValueFromQuery.mockImplementationOnce(() => []);
|
|
44
41
|
const wrapper = shallowMount(Component, {
|
|
45
|
-
|
|
42
|
+
localVue,
|
|
43
|
+
router,
|
|
44
|
+
data: () => ({ filterQuery: 'queue' }),
|
|
46
45
|
});
|
|
47
46
|
expect(setValue).not.toHaveBeenCalled();
|
|
48
47
|
});
|
|
@@ -1,84 +1,69 @@
|
|
|
1
|
-
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import
|
|
1
|
+
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
2
|
+
import VueRouter from 'vue-router';
|
|
3
3
|
import enumFilterMixin from '../enumFilterMixin';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const options = [
|
|
7
|
-
{
|
|
5
|
+
const options = [{
|
|
8
6
|
name: 'Inbound',
|
|
9
7
|
value: 'inbound',
|
|
10
|
-
},
|
|
8
|
+
},
|
|
9
|
+
{
|
|
11
10
|
name: 'Outbound',
|
|
12
11
|
value: 'outbound',
|
|
13
|
-
}
|
|
14
|
-
];
|
|
12
|
+
}];
|
|
15
13
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
options,
|
|
20
|
-
storedProp: 'value',
|
|
21
|
-
});
|
|
14
|
+
const localVue = createLocalVue();
|
|
15
|
+
localVue.use(VueRouter);
|
|
16
|
+
const router = new VueRouter();
|
|
22
17
|
|
|
23
18
|
describe('Enum filter mixin', () => {
|
|
24
19
|
const setValue = jest.fn();
|
|
25
|
-
const setValueToQuery = jest.fn();
|
|
26
|
-
const getValueFromQuery = jest.fn(() => queryValue);
|
|
27
|
-
|
|
28
20
|
const Component = {
|
|
29
21
|
render() {
|
|
30
22
|
},
|
|
31
23
|
mixins: [enumFilterMixin],
|
|
32
24
|
data: () => ({
|
|
33
|
-
filterQuery,
|
|
25
|
+
filterQuery: 'direction',
|
|
26
|
+
storedProp: 'value',
|
|
27
|
+
options,
|
|
34
28
|
}),
|
|
35
|
-
|
|
36
|
-
filterSchema() { return filterSchema; },
|
|
37
|
-
},
|
|
38
|
-
methods: {
|
|
39
|
-
setValue,
|
|
40
|
-
setValueToQuery,
|
|
41
|
-
getValueFromQuery,
|
|
42
|
-
},
|
|
29
|
+
methods: { setValue },
|
|
43
30
|
};
|
|
44
31
|
|
|
45
32
|
beforeEach(() => {
|
|
46
33
|
setValue.mockClear();
|
|
47
|
-
|
|
48
|
-
getValueFromQuery.mockClear();
|
|
34
|
+
if (Object.keys(router.currentRoute.query).length) router.replace({ query: null });
|
|
49
35
|
});
|
|
50
36
|
|
|
51
37
|
it('Correctly sets value from $route query', async () => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
await router.replace({ query: { direction: options[0].value } });
|
|
39
|
+
const wrapper = shallowMount(Component, {
|
|
40
|
+
localVue,
|
|
41
|
+
router,
|
|
42
|
+
});
|
|
43
|
+
await wrapper.vm.$nextTick();
|
|
44
|
+
expect(setValue).toHaveBeenCalledWith({ filter: 'direction', value: options[0] });
|
|
55
45
|
});
|
|
56
46
|
|
|
57
47
|
it('Sets empty array value if $route query is empty', async () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
shallowMount(Component, {
|
|
49
|
+
localVue,
|
|
50
|
+
router,
|
|
51
|
+
});
|
|
61
52
|
expect(setValue).not.toHaveBeenCalled();
|
|
62
53
|
});
|
|
63
54
|
|
|
64
55
|
it('Attaches locales to options, if they have "locale" key', async () => {
|
|
65
|
-
const options = [
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
locale: options[0].locale,
|
|
73
|
-
name: options[0].locale,
|
|
74
|
-
},
|
|
75
|
-
];
|
|
56
|
+
const options = [{
|
|
57
|
+
locale: 'jest.locale',
|
|
58
|
+
}];
|
|
59
|
+
const expectedOptions = [{
|
|
60
|
+
locale: options[0].locale,
|
|
61
|
+
name: options[0].locale,
|
|
62
|
+
}];
|
|
76
63
|
const wrapper = shallowMount(Component, {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
},
|
|
81
|
-
},
|
|
64
|
+
localVue,
|
|
65
|
+
router,
|
|
66
|
+
data: () => ({ options }),
|
|
82
67
|
});
|
|
83
68
|
expect(wrapper.vm.localizedOptions).toEqual(expectedOptions);
|
|
84
69
|
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
2
|
+
import VueRouter from 'vue-router';
|
|
3
|
+
import paginationFilterMixin from '../paginationFilterMixin';
|
|
4
|
+
|
|
5
|
+
const localVue = createLocalVue();
|
|
6
|
+
localVue.use(VueRouter);
|
|
7
|
+
const router = new VueRouter();
|
|
8
|
+
const page = 2;
|
|
9
|
+
const size = 20;
|
|
10
|
+
|
|
11
|
+
describe('Pagination filter mixin', () => {
|
|
12
|
+
const setPage = jest.fn();
|
|
13
|
+
const setSize = jest.fn();
|
|
14
|
+
let wrapper;
|
|
15
|
+
const Component = {
|
|
16
|
+
render() {},
|
|
17
|
+
mixins: [paginationFilterMixin],
|
|
18
|
+
data: () => ({ page, size }),
|
|
19
|
+
methods: { setPage, setSize },
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
setPage.mockClear();
|
|
24
|
+
setSize.mockClear();
|
|
25
|
+
if (Object.keys(router.currentRoute.query).length) router.replace({ query: null });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('Correctly sets value from $route query', async () => {
|
|
29
|
+
await router.replace({ query: { page, size } });
|
|
30
|
+
wrapper = shallowMount(Component, {
|
|
31
|
+
localVue,
|
|
32
|
+
router,
|
|
33
|
+
});
|
|
34
|
+
expect(setPage).toHaveBeenCalledWith(page);
|
|
35
|
+
expect(setSize).toHaveBeenCalledWith(size);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('At "prev" page, changes query and emits event', async () => {
|
|
39
|
+
await router.replace({ query: { page, size } });
|
|
40
|
+
wrapper = shallowMount(Component, {
|
|
41
|
+
localVue,
|
|
42
|
+
router,
|
|
43
|
+
});
|
|
44
|
+
wrapper._emitted.input = []; // reset emitted events
|
|
45
|
+
wrapper.vm.prev();
|
|
46
|
+
expect(wrapper.emitted().input).toBeTruthy();
|
|
47
|
+
expect(wrapper.vm.$route.query.page).toBe(`${page - 1}`);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('At "next" page, changes query and emits event', async () => {
|
|
51
|
+
await router.replace({ query: { page, size } });
|
|
52
|
+
wrapper = shallowMount(Component, {
|
|
53
|
+
localVue,
|
|
54
|
+
router,
|
|
55
|
+
});
|
|
56
|
+
wrapper._emitted.input = []; // reset emitted events
|
|
57
|
+
wrapper.vm.next();
|
|
58
|
+
expect(wrapper.emitted().input).toBeTruthy();
|
|
59
|
+
expect(wrapper.vm.$route.query.page).toBe(`${page + 1}`);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('At "restPage" method, changes query and emits event', async () => {
|
|
63
|
+
await router.replace({ query: { page: 100, size } });
|
|
64
|
+
wrapper = shallowMount(Component, {
|
|
65
|
+
localVue,
|
|
66
|
+
router,
|
|
67
|
+
});
|
|
68
|
+
wrapper._emitted.input = []; // reset emitted events
|
|
69
|
+
wrapper.vm.resetPage();
|
|
70
|
+
expect(wrapper.emitted().input).toBeTruthy();
|
|
71
|
+
expect(wrapper.vm.$route.query.page).toBe('1');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('At "sizeChange", changes query and emits event', async () => {
|
|
75
|
+
const newSize = 40;
|
|
76
|
+
await router.replace({ query: { page, size } });
|
|
77
|
+
wrapper = shallowMount(Component, {
|
|
78
|
+
localVue,
|
|
79
|
+
router,
|
|
80
|
+
});
|
|
81
|
+
wrapper._emitted.input = []; // reset emitted events
|
|
82
|
+
wrapper.vm.sizeChange(newSize);
|
|
83
|
+
expect(wrapper.emitted().input).toBeTruthy();
|
|
84
|
+
expect(wrapper.vm.$route.query.size).toBe(`${newSize}`);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { shallowMount } from '@vue/test-utils';
|
|
1
|
+
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
|
2
|
+
import VueRouter from 'vue-router';
|
|
2
3
|
import sortFilterMixin from '../sortFilterMixin';
|
|
3
4
|
|
|
5
|
+
const localVue = createLocalVue();
|
|
6
|
+
localVue.use(VueRouter);
|
|
7
|
+
const router = new VueRouter();
|
|
8
|
+
|
|
4
9
|
const headers = [{
|
|
5
10
|
value: 'queue',
|
|
6
11
|
show: true,
|
|
@@ -25,37 +30,27 @@ const sortedHeaders = [{
|
|
|
25
30
|
field: 'online',
|
|
26
31
|
}];
|
|
27
32
|
|
|
28
|
-
const queryValue = '+queue';
|
|
29
|
-
|
|
30
33
|
describe('Sort filter mixin', () => {
|
|
31
34
|
const setHeaders = jest.fn();
|
|
32
|
-
const setValueToQuery = jest.fn();
|
|
33
|
-
const getValueFromQuery = jest.fn(() => queryValue);
|
|
34
|
-
|
|
35
35
|
const Component = {
|
|
36
36
|
render() {},
|
|
37
37
|
mixins: [sortFilterMixin],
|
|
38
38
|
data: () => ({ headers }),
|
|
39
|
-
methods: {
|
|
40
|
-
setHeaders,
|
|
41
|
-
setValueToQuery,
|
|
42
|
-
getValueFromQuery,
|
|
43
|
-
},
|
|
39
|
+
methods: { setHeaders },
|
|
44
40
|
};
|
|
45
41
|
|
|
46
42
|
beforeEach(() => {
|
|
47
|
-
|
|
48
|
-
setValueToQuery.mockClear();
|
|
49
|
-
getValueFromQuery.mockClear();
|
|
43
|
+
router.replace('/');
|
|
50
44
|
});
|
|
51
45
|
|
|
52
46
|
it('Correctly sets value from $route query', async () => {
|
|
53
|
-
|
|
47
|
+
await router.replace({ path: '/', query: { sort: '+queue' } });
|
|
48
|
+
const wrapper = shallowMount(Component, { localVue, router });
|
|
54
49
|
expect(setHeaders).toHaveBeenCalledWith(sortedHeaders);
|
|
55
50
|
});
|
|
56
51
|
|
|
57
52
|
it('After "sort" trigger, header column sort value changes properly', () => {
|
|
58
|
-
const wrapper = shallowMount(Component);
|
|
53
|
+
const wrapper = shallowMount(Component, { localVue, router });
|
|
59
54
|
const queue = wrapper.vm.headers.find((header) => header.value === 'queue');
|
|
60
55
|
wrapper.vm.sort(queue);
|
|
61
56
|
expect(setHeaders).toHaveBeenCalledWith(sortedHeaders);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
|
2
|
+
import VueRouter from 'vue-router';
|
|
3
|
+
import _urlControllerMixin from '../_urlControllerMixin/_urlControllerMixin';
|
|
4
|
+
|
|
5
|
+
const localVue = createLocalVue();
|
|
6
|
+
localVue.use(VueRouter);
|
|
7
|
+
const router = new VueRouter();
|
|
8
|
+
|
|
9
|
+
const $t = () => {};
|
|
10
|
+
const filterQuery = 'team';
|
|
11
|
+
|
|
12
|
+
describe('URL Controller mixin Set and Get operations', () => {
|
|
13
|
+
let wrapper;
|
|
14
|
+
const Component = {
|
|
15
|
+
render() {},
|
|
16
|
+
mixins: [_urlControllerMixin],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
router.replace('/');
|
|
21
|
+
wrapper = shallowMount(Component, {
|
|
22
|
+
localVue,
|
|
23
|
+
router,
|
|
24
|
+
mocks: { $t },
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('Array of objects', async () => {
|
|
29
|
+
const value = [{ name: 'team 1', id: '1' }, { name: 'team 2', id: '2' }];
|
|
30
|
+
wrapper.vm.setValueToQuery({ filterQuery, value });
|
|
31
|
+
const queryValue = wrapper.vm.getValueFromQuery({ filterQuery });
|
|
32
|
+
expect(queryValue).toEqual(['1', '2']);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('Array of values', async () => {
|
|
36
|
+
const value = ['hello', '1'];
|
|
37
|
+
wrapper.vm.setValueToQuery({ filterQuery, value });
|
|
38
|
+
const queryValue = wrapper.vm.getValueFromQuery({ filterQuery });
|
|
39
|
+
expect(queryValue).toEqual(value);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('String value', async () => {
|
|
43
|
+
const value = 'hello there';
|
|
44
|
+
wrapper.vm.setValueToQuery({ filterQuery, value });
|
|
45
|
+
const queryValue = wrapper.vm.getValueFromQuery({ filterQuery });
|
|
46
|
+
expect(queryValue).toEqual(value);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import deepEqual from 'deep-equal';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
methods: {
|
|
5
|
+
changeRouteQuery({ filterQuery, value }) {
|
|
6
|
+
const query = { ...this.$route.query };
|
|
7
|
+
query[filterQuery] = value;
|
|
8
|
+
return this.$router.replace({
|
|
9
|
+
name: this.$router.currentRoute.name,
|
|
10
|
+
query,
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
setValueToQuery({ filterQuery, value, storedProp = 'id' }) {
|
|
15
|
+
let newValue = '';
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
if (value.length && typeof value[0] !== 'object') {
|
|
18
|
+
newValue = value;
|
|
19
|
+
} else {
|
|
20
|
+
newValue = value.map((item) => item[storedProp]);
|
|
21
|
+
}
|
|
22
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
23
|
+
newValue = value[storedProp];
|
|
24
|
+
} else {
|
|
25
|
+
newValue = value;
|
|
26
|
+
}
|
|
27
|
+
if (!deepEqual(this.$route.query[filterQuery], newValue)) {
|
|
28
|
+
this.changeRouteQuery({
|
|
29
|
+
value: newValue,
|
|
30
|
+
filterQuery,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
getValueFromQuery({ filterQuery }) {
|
|
36
|
+
return this.$route.query[filterQuery];
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import _urlControllerMixin from '../_urlControllerMixin/_urlControllerMixin';
|
|
1
2
|
import getNamespacedState from '../../../../store/helpers/getNamespacedState';
|
|
2
3
|
|
|
3
4
|
export default {
|
|
5
|
+
mixins: [_urlControllerMixin],
|
|
4
6
|
props: {
|
|
5
7
|
namespace: {
|
|
6
8
|
type: String,
|
|
@@ -28,13 +30,5 @@ export default {
|
|
|
28
30
|
if (!this.$store) throw new Error('Vuex is required for default setValue() baseFilterMixin method');
|
|
29
31
|
return this.$store.dispatch(`${this.namespace}/SET_FILTER`, payload);
|
|
30
32
|
},
|
|
31
|
-
setValueToQuery(payload) {
|
|
32
|
-
if (!this.$store) throw new Error('Vuex is required for default setValueToQuery() baseFilterMixin method');
|
|
33
|
-
return this.$store.dispatch(`${this.namespace}/SET_VALUE_TO_QUERY`, payload);
|
|
34
|
-
},
|
|
35
|
-
getValueFromQuery({ filterQuery }) {
|
|
36
|
-
if (!this.$store) throw new Error('Vuex is required for default getValueFromQuery() baseFilterMixin method');
|
|
37
|
-
return this.$route.query[filterQuery];
|
|
38
|
-
},
|
|
39
33
|
},
|
|
40
34
|
};
|
|
@@ -31,18 +31,16 @@ export default {
|
|
|
31
31
|
},
|
|
32
32
|
methods: {
|
|
33
33
|
restoreValue(value) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
.find((option) => value === option[this.storedProp]);
|
|
43
|
-
}
|
|
44
|
-
this.setValue({ filter: this.filterQuery, value: newValue });
|
|
34
|
+
let newValue;
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
newValue = this.localizedOptions
|
|
37
|
+
.filter((option) => value
|
|
38
|
+
.some((value) => value === option[this.storedProp]));
|
|
39
|
+
} else {
|
|
40
|
+
newValue = this.localizedOptions
|
|
41
|
+
.find((option) => value === option[this.storedProp]);
|
|
45
42
|
}
|
|
43
|
+
this.setValue({ filter: this.filterQuery, value: newValue });
|
|
46
44
|
},
|
|
47
45
|
},
|
|
48
46
|
};
|