@webitel/ui-sdk 0.9.57 → 0.9.61
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/QueryFilters/components/__tests__/filter-pagination.spec.js +71 -0
- package/src/modules/QueryFilters/components/__tests__/filter-search.spec.js +23 -28
- package/src/modules/QueryFilters/components/filter-pagination.vue +110 -0
- package/src/modules/QueryFilters/components/filter-search.vue +1 -1
- package/src/modules/QueryFilters/mixins/__tests__/apiFilterMixin.spec.js +15 -14
- package/src/modules/QueryFilters/mixins/__tests__/enumFilterMixin.spec.js +50 -35
- package/src/modules/QueryFilters/mixins/__tests__/sortFilterMixin.spec.js +16 -11
- package/src/modules/QueryFilters/mixins/baseFilterMixin/baseFilterMixin.js +8 -2
- package/src/modules/QueryFilters/mixins/enumFilterMixin.js +11 -9
- package/src/modules/QueryFilters/store/QueryControllerStoreModule.js +61 -0
- package/src/modules/QueryFilters/store/QueryFiltersStoreModule.js +6 -0
- package/src/modules/QueryFilters/store/__tests__/QueryControllerStoreModule.spec.js +42 -0
- package/src/modules/QueryFilters/api/__tests__/defaults.spec.js +0 -18
- package/src/modules/QueryFilters/api/defaults.js +0 -16
- package/src/modules/QueryFilters/mixins/__tests__/paginationFilterMixin.spec.js +0 -74
- package/src/modules/QueryFilters/mixins/__tests__/urlControllerMixin.spec.js +0 -48
- package/src/modules/QueryFilters/mixins/_urlControllerMixin/_urlControllerMixin.js +0 -39
- package/src/modules/QueryFilters/mixins/paginationFilterMixin.js +0 -76
- package/src/modules/QueryFilters/store/queryFilters.js +0 -6
package/package.json
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import BaseFilterSchema from '../../classes/BaseFilterSchema';
|
|
3
|
+
import baseFilterMixin from '../../mixins/baseFilterMixin/baseFilterMixin';
|
|
4
|
+
import FilterPagination from '../filter-pagination.vue';
|
|
5
|
+
|
|
6
|
+
const pageDefaultValue = 1;
|
|
7
|
+
const page = 2;
|
|
8
|
+
const size = 20;
|
|
9
|
+
|
|
10
|
+
const pageFilterSchema = new BaseFilterSchema({ value: page, defaultValue: pageDefaultValue });
|
|
11
|
+
const sizeFilterSchema = new BaseFilterSchema({ value: size });
|
|
12
|
+
|
|
13
|
+
describe('Pagination filter mixin', () => {
|
|
14
|
+
const setValue = jest.fn();
|
|
15
|
+
const setValueToQuery = jest.fn();
|
|
16
|
+
const getValueFromQuery = jest.fn(({ filterQuery }) => (filterQuery === 'page' ? page : size));
|
|
17
|
+
|
|
18
|
+
let wrapper;
|
|
19
|
+
|
|
20
|
+
jest.spyOn(baseFilterMixin.methods, 'setValue').mockImplementation(setValue);
|
|
21
|
+
jest.spyOn(baseFilterMixin.methods, 'setValueToQuery').mockImplementation(setValueToQuery);
|
|
22
|
+
jest.spyOn(baseFilterMixin.methods, 'getValueFromQuery').mockImplementation(getValueFromQuery);
|
|
23
|
+
|
|
24
|
+
const computed = {
|
|
25
|
+
pageFilterSchema() { return pageFilterSchema; },
|
|
26
|
+
sizeFilterSchema() { return sizeFilterSchema; },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
setValue.mockClear();
|
|
31
|
+
setValueToQuery.mockClear();
|
|
32
|
+
getValueFromQuery.mockClear();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('Correctly sets value from $route query', async () => {
|
|
36
|
+
wrapper = shallowMount(FilterPagination, {
|
|
37
|
+
computed,
|
|
38
|
+
});
|
|
39
|
+
expect(setValue).toHaveBeenNthCalledWith(1, { filter: 'page', value: page });
|
|
40
|
+
expect(setValue).toHaveBeenNthCalledWith(2, { filter: 'size', value: size });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('At "prev" page, changes query and emits event', async () => {
|
|
44
|
+
wrapper = shallowMount(FilterPagination, { computed });
|
|
45
|
+
wrapper.vm.prev();
|
|
46
|
+
expect(wrapper.emitted().input).toBeTruthy();
|
|
47
|
+
expect(setValue).toHaveBeenLastCalledWith({ filter: 'page', value: page - 1 });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('At "next" page, changes query and emits event', async () => {
|
|
51
|
+
wrapper = shallowMount(FilterPagination, { computed });
|
|
52
|
+
wrapper.vm.next();
|
|
53
|
+
expect(wrapper.emitted().input).toBeTruthy();
|
|
54
|
+
expect(setValue).toHaveBeenLastCalledWith({ filter: 'page', value: page + 1 });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('At "resetPage" method, changes query and emits event', async () => {
|
|
58
|
+
wrapper = shallowMount(FilterPagination, { computed });
|
|
59
|
+
wrapper.vm.resetPage();
|
|
60
|
+
expect(wrapper.emitted().input).toBeTruthy();
|
|
61
|
+
expect(setValue).toHaveBeenLastCalledWith({ filter: 'page', value: pageDefaultValue });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('At "sizeChange", changes query and emits event', async () => {
|
|
65
|
+
const newSize = 40;
|
|
66
|
+
wrapper = shallowMount(FilterPagination, { computed });
|
|
67
|
+
wrapper.vm.sizeChange(newSize);
|
|
68
|
+
expect(wrapper.emitted().input).toBeTruthy();
|
|
69
|
+
expect(setValue).toHaveBeenLastCalledWith({ filter: 'size', value: newSize });
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -1,49 +1,44 @@
|
|
|
1
|
-
import { shallowMount
|
|
2
|
-
import Vuex from 'vuex';
|
|
3
|
-
import VueRouter from 'vue-router';
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
4
2
|
import SearchFilter from '../filter-search.vue';
|
|
5
3
|
import BaseFilterSchema from '../../classes/BaseFilterSchema';
|
|
6
4
|
import baseFilterMixin from '../../mixins/baseFilterMixin/baseFilterMixin';
|
|
7
5
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
6
|
+
const namespace = 'jest';
|
|
7
|
+
const filterQuery = 'jest';
|
|
8
|
+
const filterSchema = new BaseFilterSchema();
|
|
9
|
+
const searchValue = 'jest-search';
|
|
12
10
|
|
|
13
11
|
describe('Search Filter', () => {
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const store = new Vuex.Store({
|
|
18
|
-
modules: {
|
|
19
|
-
[namespace]: {
|
|
20
|
-
namespaced: true,
|
|
21
|
-
state: {
|
|
22
|
-
[filterQuery]: filterSchema,
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
});
|
|
12
|
+
const setValue = jest.fn();
|
|
13
|
+
const setValueToQuery = jest.fn();
|
|
14
|
+
const getValueFromQuery = jest.fn(() => searchValue);
|
|
27
15
|
|
|
28
16
|
const mountOptions = {
|
|
29
|
-
localVue,
|
|
30
|
-
store,
|
|
31
|
-
router,
|
|
32
17
|
propsData: {
|
|
33
18
|
namespace,
|
|
34
19
|
filterQuery,
|
|
35
20
|
},
|
|
21
|
+
computed: {
|
|
22
|
+
filterSchema() { return filterSchema; },
|
|
23
|
+
},
|
|
36
24
|
};
|
|
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
|
+
|
|
37
36
|
it('renders a component', () => {
|
|
38
37
|
const wrapper = shallowMount(SearchFilter, mountOptions);
|
|
39
38
|
expect(wrapper.exists()).toBe(true);
|
|
40
39
|
});
|
|
41
40
|
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);
|
|
46
41
|
shallowMount(SearchFilter, mountOptions);
|
|
47
|
-
expect(
|
|
42
|
+
expect(setValue).toHaveBeenCalledWith({ filter: filterQuery, value: searchValue });
|
|
48
43
|
});
|
|
49
44
|
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<wt-pagination
|
|
3
|
+
:next="isNext"
|
|
4
|
+
:prev="isPrev"
|
|
5
|
+
:value="sizeFilterSchema.value"
|
|
6
|
+
debounce
|
|
7
|
+
@change="sizeChange"
|
|
8
|
+
@next="next"
|
|
9
|
+
@prev="prev"
|
|
10
|
+
></wt-pagination>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
import getNamespacedState from '../../../store/helpers/getNamespacedState';
|
|
15
|
+
import baseFilterMixin from '../mixins/baseFilterMixin/baseFilterMixin';
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
name: 'filter-pagination',
|
|
19
|
+
mixins: [baseFilterMixin],
|
|
20
|
+
props: {
|
|
21
|
+
isNext: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
default: true,
|
|
24
|
+
},
|
|
25
|
+
pageFilterQuery: {
|
|
26
|
+
type: String,
|
|
27
|
+
default: 'page',
|
|
28
|
+
},
|
|
29
|
+
sizeFilterQuery: {
|
|
30
|
+
type: String,
|
|
31
|
+
default: 'size',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
computed: {
|
|
36
|
+
pageFilterSchema() {
|
|
37
|
+
if (!this.$store) throw new Error('Vuex is required for page filter binding');
|
|
38
|
+
return getNamespacedState(this.$store.state, this.namespace)[this.pageFilterQuery];
|
|
39
|
+
},
|
|
40
|
+
sizeFilterSchema() {
|
|
41
|
+
if (!this.$store) throw new Error('Vuex is required for size filter binding');
|
|
42
|
+
return getNamespacedState(this.$store.state, this.namespace)[this.sizeFilterQuery];
|
|
43
|
+
},
|
|
44
|
+
isPrev() {
|
|
45
|
+
return this.page > 1;
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
methods: {
|
|
50
|
+
restore() {
|
|
51
|
+
this.restorePage();
|
|
52
|
+
this.restoreSize();
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
restorePage() {
|
|
56
|
+
const value = +this.getValueFromQuery({ filterQuery: this.pageFilterQuery });
|
|
57
|
+
if (value) this.setValue({ filter: this.pageFilterQuery, value });
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
restoreSize() {
|
|
61
|
+
const value = +this.getValueFromQuery({ filterQuery: this.sizeFilterQuery });
|
|
62
|
+
if (value) this.setValue({ filter: this.sizeFilterQuery, value });
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
next() {
|
|
66
|
+
this.$emit('input');
|
|
67
|
+
const value = this.pageFilterSchema.value + 1;
|
|
68
|
+
this.setValue({ filter: this.pageFilterQuery, value });
|
|
69
|
+
this.setValueToQuery({
|
|
70
|
+
filterQuery: this.pageFilterQuery,
|
|
71
|
+
value,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
prev() {
|
|
76
|
+
this.$emit('input');
|
|
77
|
+
const value = this.pageFilterSchema.value - 1;
|
|
78
|
+
this.setValue({ filter: this.pageFilterQuery, value });
|
|
79
|
+
this.setValueToQuery({
|
|
80
|
+
filterQuery: this.pageFilterQuery,
|
|
81
|
+
value,
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
resetPage() {
|
|
86
|
+
this.$emit('input');
|
|
87
|
+
const value = this.pageFilterSchema.defaultValue;
|
|
88
|
+
this.setValue({ filter: this.pageFilterQuery, value });
|
|
89
|
+
this.setValueToQuery({
|
|
90
|
+
filterQuery: this.pageFilterQuery,
|
|
91
|
+
value,
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
sizeChange(value) {
|
|
96
|
+
this.$emit('input');
|
|
97
|
+
this.setValue({ filter: this.sizeFilterQuery, value });
|
|
98
|
+
this.setValueToQuery({
|
|
99
|
+
filterQuery: this.sizeFilterQuery,
|
|
100
|
+
value,
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
</script>
|
|
107
|
+
|
|
108
|
+
<style scoped>
|
|
109
|
+
|
|
110
|
+
</style>
|
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import VueRouter from 'vue-router';
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
3
2
|
import ApiFilterSchema from '../../classes/ApiFilterSchema';
|
|
4
3
|
import apiFilterMixin from '../apiFilterMixin';
|
|
5
4
|
|
|
6
|
-
const
|
|
7
|
-
localVue.use(VueRouter);
|
|
8
|
-
const router = new VueRouter();
|
|
5
|
+
const filterQuery = 'team';
|
|
9
6
|
const team = ['1', '2'];
|
|
10
7
|
const filterSchema = new ApiFilterSchema();
|
|
11
8
|
|
|
12
9
|
describe('API filter mixin', () => {
|
|
13
10
|
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,
|
|
19
19
|
}),
|
|
20
20
|
computed: {
|
|
21
21
|
filterSchema() { return filterSchema; },
|
|
22
22
|
},
|
|
23
|
-
methods: {
|
|
23
|
+
methods: {
|
|
24
|
+
setValue,
|
|
25
|
+
setValueToQuery,
|
|
26
|
+
getValueFromQuery,
|
|
27
|
+
},
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
beforeEach(() => {
|
|
27
31
|
setValue.mockClear();
|
|
28
|
-
|
|
32
|
+
setValueToQuery.mockClear();
|
|
33
|
+
getValueFromQuery.mockClear();
|
|
29
34
|
});
|
|
30
35
|
|
|
31
36
|
it('Correctly sets value from $route query', async () => {
|
|
32
|
-
await router.replace({ query: { team } });
|
|
33
37
|
const wrapper = shallowMount(Component, {
|
|
34
|
-
localVue,
|
|
35
|
-
router,
|
|
36
38
|
});
|
|
37
39
|
expect(setValue).toHaveBeenCalledWith({ filter: 'team', value: [{ id: team[0] }, { id: team[1] }] });
|
|
38
40
|
});
|
|
39
41
|
|
|
40
42
|
it('Sets empty array value if $route query is empty', async () => {
|
|
43
|
+
getValueFromQuery.mockImplementationOnce(() => []);
|
|
41
44
|
const wrapper = shallowMount(Component, {
|
|
42
|
-
|
|
43
|
-
router,
|
|
44
|
-
data: () => ({ filterQuery: 'queue' }),
|
|
45
|
+
data: () => ({ filterQuery }),
|
|
45
46
|
});
|
|
46
47
|
expect(setValue).not.toHaveBeenCalled();
|
|
47
48
|
});
|
|
@@ -1,69 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import EnumFilterSchema from '../../classes/EnumFilterSchema';
|
|
3
3
|
import enumFilterMixin from '../enumFilterMixin';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const filterQuery = 'direction';
|
|
6
|
+
const options = [
|
|
7
|
+
{
|
|
6
8
|
name: 'Inbound',
|
|
7
9
|
value: 'inbound',
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
+
}, {
|
|
10
11
|
name: 'Outbound',
|
|
11
12
|
value: 'outbound',
|
|
12
|
-
}
|
|
13
|
+
},
|
|
14
|
+
];
|
|
13
15
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
const
|
|
16
|
+
const queryValue = options[0].value;
|
|
17
|
+
|
|
18
|
+
const filterSchema = new EnumFilterSchema({
|
|
19
|
+
options,
|
|
20
|
+
storedProp: 'value',
|
|
21
|
+
});
|
|
17
22
|
|
|
18
23
|
describe('Enum filter mixin', () => {
|
|
19
24
|
const setValue = jest.fn();
|
|
25
|
+
const setValueToQuery = jest.fn();
|
|
26
|
+
const getValueFromQuery = jest.fn(() => queryValue);
|
|
27
|
+
|
|
20
28
|
const Component = {
|
|
21
29
|
render() {
|
|
22
30
|
},
|
|
23
31
|
mixins: [enumFilterMixin],
|
|
24
32
|
data: () => ({
|
|
25
|
-
filterQuery
|
|
26
|
-
storedProp: 'value',
|
|
27
|
-
options,
|
|
33
|
+
filterQuery,
|
|
28
34
|
}),
|
|
29
|
-
|
|
35
|
+
computed: {
|
|
36
|
+
filterSchema() { return filterSchema; },
|
|
37
|
+
},
|
|
38
|
+
methods: {
|
|
39
|
+
setValue,
|
|
40
|
+
setValueToQuery,
|
|
41
|
+
getValueFromQuery,
|
|
42
|
+
},
|
|
30
43
|
};
|
|
31
44
|
|
|
32
45
|
beforeEach(() => {
|
|
33
46
|
setValue.mockClear();
|
|
34
|
-
|
|
47
|
+
setValueToQuery.mockClear();
|
|
48
|
+
getValueFromQuery.mockClear();
|
|
35
49
|
});
|
|
36
50
|
|
|
37
51
|
it('Correctly sets value from $route query', async () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
router,
|
|
42
|
-
});
|
|
43
|
-
await wrapper.vm.$nextTick();
|
|
44
|
-
expect(setValue).toHaveBeenCalledWith({ filter: 'direction', value: options[0] });
|
|
52
|
+
const wrapper = shallowMount(Component, {});
|
|
53
|
+
expect(setValue)
|
|
54
|
+
.toHaveBeenCalledWith({ filter: filterQuery, value: options[0] });
|
|
45
55
|
});
|
|
46
56
|
|
|
47
57
|
it('Sets empty array value if $route query is empty', async () => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
58
|
+
getValueFromQuery.mockImplementationOnce(() => []);
|
|
59
|
+
|
|
60
|
+
shallowMount(Component, {});
|
|
52
61
|
expect(setValue).not.toHaveBeenCalled();
|
|
53
62
|
});
|
|
54
63
|
|
|
55
64
|
it('Attaches locales to options, if they have "locale" key', async () => {
|
|
56
|
-
const options = [
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
const options = [
|
|
66
|
+
{
|
|
67
|
+
locale: 'jest.locale',
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
const expectedOptions = [
|
|
71
|
+
{
|
|
72
|
+
locale: options[0].locale,
|
|
73
|
+
name: options[0].locale,
|
|
74
|
+
},
|
|
75
|
+
];
|
|
63
76
|
const wrapper = shallowMount(Component, {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
computed: {
|
|
78
|
+
options() {
|
|
79
|
+
return options;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
67
82
|
});
|
|
68
83
|
expect(wrapper.vm.localizedOptions).toEqual(expectedOptions);
|
|
69
84
|
});
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { shallowMount
|
|
2
|
-
import VueRouter from 'vue-router';
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
3
2
|
import sortFilterMixin from '../sortFilterMixin';
|
|
4
3
|
|
|
5
|
-
const localVue = createLocalVue();
|
|
6
|
-
localVue.use(VueRouter);
|
|
7
|
-
const router = new VueRouter();
|
|
8
|
-
|
|
9
4
|
const headers = [{
|
|
10
5
|
value: 'queue',
|
|
11
6
|
show: true,
|
|
@@ -30,27 +25,37 @@ const sortedHeaders = [{
|
|
|
30
25
|
field: 'online',
|
|
31
26
|
}];
|
|
32
27
|
|
|
28
|
+
const queryValue = '+queue';
|
|
29
|
+
|
|
33
30
|
describe('Sort filter mixin', () => {
|
|
34
31
|
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: {
|
|
39
|
+
methods: {
|
|
40
|
+
setHeaders,
|
|
41
|
+
setValueToQuery,
|
|
42
|
+
getValueFromQuery,
|
|
43
|
+
},
|
|
40
44
|
};
|
|
41
45
|
|
|
42
46
|
beforeEach(() => {
|
|
43
|
-
|
|
47
|
+
setHeaders.mockClear();
|
|
48
|
+
setValueToQuery.mockClear();
|
|
49
|
+
getValueFromQuery.mockClear();
|
|
44
50
|
});
|
|
45
51
|
|
|
46
52
|
it('Correctly sets value from $route query', async () => {
|
|
47
|
-
|
|
48
|
-
const wrapper = shallowMount(Component, { localVue, router });
|
|
53
|
+
const wrapper = shallowMount(Component);
|
|
49
54
|
expect(setHeaders).toHaveBeenCalledWith(sortedHeaders);
|
|
50
55
|
});
|
|
51
56
|
|
|
52
57
|
it('After "sort" trigger, header column sort value changes properly', () => {
|
|
53
|
-
const wrapper = shallowMount(Component
|
|
58
|
+
const wrapper = shallowMount(Component);
|
|
54
59
|
const queue = wrapper.vm.headers.find((header) => header.value === 'queue');
|
|
55
60
|
wrapper.vm.sort(queue);
|
|
56
61
|
expect(setHeaders).toHaveBeenCalledWith(sortedHeaders);
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import _urlControllerMixin from '../_urlControllerMixin/_urlControllerMixin';
|
|
2
1
|
import getNamespacedState from '../../../../store/helpers/getNamespacedState';
|
|
3
2
|
|
|
4
3
|
export default {
|
|
5
|
-
mixins: [_urlControllerMixin],
|
|
6
4
|
props: {
|
|
7
5
|
namespace: {
|
|
8
6
|
type: String,
|
|
@@ -30,5 +28,13 @@ export default {
|
|
|
30
28
|
if (!this.$store) throw new Error('Vuex is required for default setValue() baseFilterMixin method');
|
|
31
29
|
return this.$store.dispatch(`${this.namespace}/SET_FILTER`, payload);
|
|
32
30
|
},
|
|
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(payload) {
|
|
36
|
+
if (!this.$store) throw new Error('Vuex is required for default getValueFromQuery() baseFilterMixin method');
|
|
37
|
+
return this.$store.dispatch(`${this.namespace}/GET_VALUE_FROM_QUERY`, payload);
|
|
38
|
+
},
|
|
33
39
|
},
|
|
34
40
|
};
|
|
@@ -31,16 +31,18 @@ export default {
|
|
|
31
31
|
},
|
|
32
32
|
methods: {
|
|
33
33
|
restoreValue(value) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
if (value && value.length) {
|
|
35
|
+
let newValue;
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
newValue = this.localizedOptions
|
|
38
|
+
.filter((option) => value
|
|
39
|
+
.some((value) => value === option[this.storedProp]));
|
|
40
|
+
} else {
|
|
41
|
+
newValue = this.localizedOptions
|
|
42
|
+
.find((option) => value === option[this.storedProp]);
|
|
43
|
+
}
|
|
44
|
+
this.setValue({ filter: this.filterQuery, value: newValue });
|
|
42
45
|
}
|
|
43
|
-
this.setValue({ filter: this.filterQuery, value: newValue });
|
|
44
46
|
},
|
|
45
47
|
},
|
|
46
48
|
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import deepEqual from 'deep-equal';
|
|
2
|
+
import BaseStoreModule from '../../../store/BaseStoreModules/BaseStoreModule';
|
|
3
|
+
|
|
4
|
+
export default class QueryControllerStoreModule extends BaseStoreModule {
|
|
5
|
+
actions = {
|
|
6
|
+
// OVERRIDE ME
|
|
7
|
+
// eslint-disable-next-line no-unused-vars
|
|
8
|
+
BEFORE_CHANGE_ROUTE_QUERY_HOOK: (context, { query, filterQuery, value }) => query,
|
|
9
|
+
// OVERRIDE ME
|
|
10
|
+
AFTER_CHANGE_ROUTE_QUERY_HOOK: (context, { query }) => query,
|
|
11
|
+
_CHANGE_ROUTE_QUERY: async (context, { filterQuery, value }) => {
|
|
12
|
+
try {
|
|
13
|
+
const { router } = context.state;
|
|
14
|
+
let query = { ...router.currentRoute.query };
|
|
15
|
+
query[filterQuery] = value;
|
|
16
|
+
query = await context.dispatch('BEFORE_CHANGE_ROUTE_QUERY_HOOK', { query, filterQuery, value });
|
|
17
|
+
await router.replace({
|
|
18
|
+
name: router.currentRoute.name,
|
|
19
|
+
query,
|
|
20
|
+
});
|
|
21
|
+
await context.dispatch('AFTER_CHANGE_ROUTE_QUERY_HOOK', { query });
|
|
22
|
+
} catch (err) {
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
SET_VALUE_TO_QUERY: async (
|
|
27
|
+
context,
|
|
28
|
+
{ filterQuery, value, storedProp = 'id' },
|
|
29
|
+
) => {
|
|
30
|
+
try {
|
|
31
|
+
let newValue = '';
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
if (value.length && typeof value[0] !== 'object') {
|
|
34
|
+
newValue = value;
|
|
35
|
+
} else {
|
|
36
|
+
newValue = value.map((item) => item[storedProp]);
|
|
37
|
+
}
|
|
38
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
39
|
+
newValue = value[storedProp];
|
|
40
|
+
} else {
|
|
41
|
+
newValue = value;
|
|
42
|
+
}
|
|
43
|
+
if (!deepEqual(context.state.router.currentRoute.query[filterQuery], newValue)) {
|
|
44
|
+
await context.dispatch('_CHANGE_ROUTE_QUERY', {
|
|
45
|
+
value: newValue,
|
|
46
|
+
filterQuery,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
} catch (err) {
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
GET_VALUE_FROM_QUERY: (context, { filterQuery }) => context.state.router.currentRoute.query[filterQuery],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
constructor({ router } = {}) {
|
|
57
|
+
super();
|
|
58
|
+
if (!router) throw new Error('Pass router object to QueryController Store Module');
|
|
59
|
+
this.state.router = router;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -43,6 +43,12 @@ export default class QueryFiltersStoreModule extends BaseStoreModule {
|
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
generateQueryControllerActions(controllerNamespace) {
|
|
47
|
+
this.actions.SET_VALUE_TO_QUERY = (context, payload) => context.dispatch(`${controllerNamespace}/SET_VALUE_TO_QUERY`, payload, { root: true });
|
|
48
|
+
this.actions.GET_VALUE_FROM_QUERY = (context, payload) => context.dispatch(`${controllerNamespace}/GET_VALUE_FROM_QUERY`, payload, { root: true });
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
46
52
|
constructor({ state = {} } = {}) {
|
|
47
53
|
super();
|
|
48
54
|
this.state = state;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createLocalVue } from '@vue/test-utils';
|
|
2
|
+
import VueRouter from 'vue-router';
|
|
3
|
+
import Vuex from 'vuex';
|
|
4
|
+
import QueryContrllerStoreModule from '../QueryControllerStoreModule';
|
|
5
|
+
|
|
6
|
+
const localVue = createLocalVue();
|
|
7
|
+
localVue.use(Vuex);
|
|
8
|
+
localVue.use(VueRouter);
|
|
9
|
+
const router = new VueRouter();
|
|
10
|
+
|
|
11
|
+
const filterQuery = 'team';
|
|
12
|
+
|
|
13
|
+
describe('Query Controller Store Module Actions', () => {
|
|
14
|
+
const store = new Vuex.Store({
|
|
15
|
+
...new QueryContrllerStoreModule({ router }).getModule(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
router.replace('/');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Array of objects', async () => {
|
|
23
|
+
const value = [{ name: 'team 1', id: '1' }, { name: 'team 2', id: '2' }];
|
|
24
|
+
await store.dispatch('SET_VALUE_TO_QUERY', { filterQuery, value });
|
|
25
|
+
const queryValue = await store.dispatch('GET_VALUE_FROM_QUERY', { filterQuery });
|
|
26
|
+
expect(queryValue).toEqual(['1', '2']);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('Array of values', async () => {
|
|
30
|
+
const value = ['hello', '1'];
|
|
31
|
+
await store.dispatch('SET_VALUE_TO_QUERY', { filterQuery, value });
|
|
32
|
+
const queryValue = await store.dispatch('GET_VALUE_FROM_QUERY', { filterQuery });
|
|
33
|
+
expect(queryValue).toEqual(value);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('String value', async () => {
|
|
37
|
+
const value = 'hello there';
|
|
38
|
+
await store.dispatch('SET_VALUE_TO_QUERY', { filterQuery, value });
|
|
39
|
+
const queryValue = await store.dispatch('GET_VALUE_FROM_QUERY', { filterQuery });
|
|
40
|
+
expect(queryValue).toEqual(value);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
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,74 +0,0 @@
|
|
|
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 "sizeChange", changes query and emits event', async () => {
|
|
63
|
-
const newSize = 40;
|
|
64
|
-
await router.replace({ query: { page, size } });
|
|
65
|
-
wrapper = shallowMount(Component, {
|
|
66
|
-
localVue,
|
|
67
|
-
router,
|
|
68
|
-
});
|
|
69
|
-
wrapper._emitted.input = []; // reset emitted events
|
|
70
|
-
wrapper.vm.sizeChange(newSize);
|
|
71
|
-
expect(wrapper.emitted().input).toBeTruthy();
|
|
72
|
-
expect(wrapper.vm.$route.query.size).toBe(`${newSize}`);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
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,76 +0,0 @@
|
|
|
1
|
-
import baseFilterMixin from './baseFilterMixin/baseFilterMixin';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
mixins: [baseFilterMixin],
|
|
5
|
-
|
|
6
|
-
props: {
|
|
7
|
-
isNext: {
|
|
8
|
-
type: Boolean,
|
|
9
|
-
default: true,
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
computed: {
|
|
14
|
-
isPrev() {
|
|
15
|
-
return this.page > 1;
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
methods: {
|
|
20
|
-
restore() {
|
|
21
|
-
this.restorePage();
|
|
22
|
-
this.restoreSize();
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
restorePage() {
|
|
26
|
-
const defaultPage = 1;
|
|
27
|
-
const value = +this.getValueFromQuery({ filterQuery: 'page' }) || defaultPage;
|
|
28
|
-
this.setPage(value);
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
restoreSize() {
|
|
32
|
-
const defaultSize = 10;
|
|
33
|
-
const value = +this.getValueFromQuery({ filterQuery: 'size' }) || defaultSize;
|
|
34
|
-
this.setSize(value);
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
next() {
|
|
38
|
-
this.$emit('input');
|
|
39
|
-
const value = this.page + 1;
|
|
40
|
-
this.setPage(value);
|
|
41
|
-
this.setValueToQuery({
|
|
42
|
-
filterQuery: 'page',
|
|
43
|
-
value,
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
prev() {
|
|
48
|
-
this.$emit('input');
|
|
49
|
-
const value = this.page - 1;
|
|
50
|
-
this.setPage(value);
|
|
51
|
-
this.setValueToQuery({
|
|
52
|
-
filterQuery: 'page',
|
|
53
|
-
value,
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
resetPage() {
|
|
58
|
-
this.$emit('input');
|
|
59
|
-
const value = 1;
|
|
60
|
-
this.setPage(value);
|
|
61
|
-
this.setValueToQuery({
|
|
62
|
-
filterQuery: 'page',
|
|
63
|
-
value,
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
sizeChange(value) {
|
|
68
|
-
this.$emit('input');
|
|
69
|
-
this.setSize(value);
|
|
70
|
-
this.setValueToQuery({
|
|
71
|
-
filterQuery: 'size',
|
|
72
|
-
value,
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
};
|