@webitel/ui-sdk 2.0.2 → 2.0.3-1
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/locale/en/en.js +2 -0
- package/src/locale/ru/ru.js +2 -0
- package/src/locale/ua/ua.js +2 -0
- package/src/modules/QueryFilters/components/__tests__/filter-datetime.spec.js +49 -0
- package/src/modules/QueryFilters/components/__tests__/filter-from-to.spec.js +65 -0
- package/src/modules/QueryFilters/components/filter-datetime.vue +39 -0
- package/src/modules/QueryFilters/components/filter-from-to.vue +142 -0
package/package.json
CHANGED
package/src/locale/en/en.js
CHANGED
package/src/locale/ru/ru.js
CHANGED
package/src/locale/ua/ua.js
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
|
2
|
+
import Vuex from 'vuex';
|
|
3
|
+
import VueRouter from 'vue-router';
|
|
4
|
+
import DatetimeFilter from '../filter-datetime.vue';
|
|
5
|
+
import BaseFilterSchema from '../../classes/BaseFilterSchema';
|
|
6
|
+
import baseFilterMixin from '../../mixins/baseFilterMixin/baseFilterMixin';
|
|
7
|
+
|
|
8
|
+
const localVue = createLocalVue();
|
|
9
|
+
localVue.use(Vuex);
|
|
10
|
+
localVue.use(VueRouter);
|
|
11
|
+
const router = new VueRouter();
|
|
12
|
+
|
|
13
|
+
describe('DatetimeFilter Filter', () => {
|
|
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
|
+
});
|
|
27
|
+
|
|
28
|
+
const mountOptions = {
|
|
29
|
+
localVue,
|
|
30
|
+
store,
|
|
31
|
+
router,
|
|
32
|
+
propsData: {
|
|
33
|
+
namespace,
|
|
34
|
+
filterQuery,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
it('renders a component', () => {
|
|
38
|
+
const wrapper = shallowMount(DatetimeFilter, mountOptions);
|
|
39
|
+
expect(wrapper.exists()).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('initial restoreValue() triggers setValue() method', async () => {
|
|
42
|
+
const value = Date.now();
|
|
43
|
+
await router.replace({ query: { [filterQuery]: value } });
|
|
44
|
+
const setValueMock = jest.fn();
|
|
45
|
+
jest.spyOn(baseFilterMixin.methods, 'setValue').mockImplementationOnce(setValueMock);
|
|
46
|
+
shallowMount(DatetimeFilter, mountOptions);
|
|
47
|
+
expect(setValueMock).toHaveBeenCalledWith({ filter: filterQuery, value });
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
2
|
+
import VueRouter from 'vue-router';
|
|
3
|
+
import Vuex from 'vuex';
|
|
4
|
+
import BaseFilterSchema from '../../classes/BaseFilterSchema';
|
|
5
|
+
import baseFilterMixin from '../../mixins/baseFilterMixin/baseFilterMixin';
|
|
6
|
+
import FilterFromTo from '../filter-from-to.vue';
|
|
7
|
+
|
|
8
|
+
const localVue = createLocalVue();
|
|
9
|
+
localVue.use(Vuex);
|
|
10
|
+
localVue.use(VueRouter);
|
|
11
|
+
const router = new VueRouter();
|
|
12
|
+
|
|
13
|
+
describe('FilterFromTo Filter', () => {
|
|
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
|
+
});
|
|
27
|
+
|
|
28
|
+
const mountOptions = {
|
|
29
|
+
localVue,
|
|
30
|
+
store,
|
|
31
|
+
router,
|
|
32
|
+
propsData: {
|
|
33
|
+
namespace,
|
|
34
|
+
filterQuery,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
it('renders a component', () => {
|
|
38
|
+
const wrapper = shallowMount(FilterFromTo, mountOptions);
|
|
39
|
+
expect(wrapper.exists()).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('initial restoreValue() triggers setValue() method: From case', async () => {
|
|
42
|
+
const value = 10;
|
|
43
|
+
await router.replace({ query: { [`${filterQuery}From`]: value } });
|
|
44
|
+
const setValueMock = jest.fn();
|
|
45
|
+
jest.spyOn(baseFilterMixin.methods, 'setValue')
|
|
46
|
+
.mockImplementationOnce(setValueMock);
|
|
47
|
+
shallowMount(FilterFromTo, mountOptions);
|
|
48
|
+
expect(setValueMock).toHaveBeenCalledWith({
|
|
49
|
+
filter: filterQuery,
|
|
50
|
+
value: { to: undefined, from: value },
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
// it('initial restoreValue() triggers setValue() method: To case', async () => {
|
|
54
|
+
// const value = 10;
|
|
55
|
+
// await router.replace({ query: { [`${filterQuery}To`]: value } });
|
|
56
|
+
// const setValueMock = jest.fn();
|
|
57
|
+
// jest.spyOn(baseFilterMixin.methods, 'setValue')
|
|
58
|
+
// .mockImplementationOnce(setValueMock);
|
|
59
|
+
// shallowMount(FilterFromTo, mountOptions);
|
|
60
|
+
// expect(setValueMock).toHaveBeenCalledWith({
|
|
61
|
+
// filter: filterQuery,
|
|
62
|
+
// value: { to: value, from: 0 },
|
|
63
|
+
// });
|
|
64
|
+
// });
|
|
65
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<wt-datetimepicker
|
|
3
|
+
:value="filterSchema.value"
|
|
4
|
+
:label="label"
|
|
5
|
+
@change="handleChange"
|
|
6
|
+
></wt-datetimepicker>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
import baseFilterMixin from '../mixins/baseFilterMixin/baseFilterMixin';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
name: 'filter-from',
|
|
14
|
+
mixins: [baseFilterMixin],
|
|
15
|
+
props: {
|
|
16
|
+
filterQuery: {
|
|
17
|
+
type: String,
|
|
18
|
+
required: true,
|
|
19
|
+
},
|
|
20
|
+
label: {
|
|
21
|
+
type: String,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
methods: {
|
|
26
|
+
handleChange(value) {
|
|
27
|
+
this.setValue({ filter: this.filterQuery, value });
|
|
28
|
+
this.setValueToQuery({ filterQuery: this.filterQuery, value });
|
|
29
|
+
},
|
|
30
|
+
restoreValue(value) {
|
|
31
|
+
this.setValue({ filter: this.filterQuery, value: +value });
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<style scoped>
|
|
38
|
+
|
|
39
|
+
</style>
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="filter-from-to">
|
|
3
|
+
<wt-label>{{ label }}</wt-label>
|
|
4
|
+
<div class="filter-from-to__inputs-wrapper">
|
|
5
|
+
<div class="filter-from-to__input-wrapper">
|
|
6
|
+
<wt-label
|
|
7
|
+
class="filter-from-to__input-label"
|
|
8
|
+
for="filter-from-to-from"
|
|
9
|
+
>{{ $t('reusable.from') }}
|
|
10
|
+
</wt-label>
|
|
11
|
+
<wt-input
|
|
12
|
+
class="filter-from-to-input"
|
|
13
|
+
name="filter-from-to-from"
|
|
14
|
+
:value="filterSchema.value.from"
|
|
15
|
+
type="number"
|
|
16
|
+
:number-min="0"
|
|
17
|
+
@input="setFrom"
|
|
18
|
+
></wt-input>
|
|
19
|
+
</div>
|
|
20
|
+
<div class="filter-from-to__input-wrapper">
|
|
21
|
+
<wt-label
|
|
22
|
+
class="filter-from-to__input-label"
|
|
23
|
+
for="filter-from-to-to"
|
|
24
|
+
>{{ $t('reusable.to') }}
|
|
25
|
+
</wt-label>
|
|
26
|
+
<wt-input
|
|
27
|
+
class="filter-from-to-input"
|
|
28
|
+
name="filter-from-to-to"
|
|
29
|
+
:value="filterSchema.value.to"
|
|
30
|
+
type="number"
|
|
31
|
+
:number-min="0"
|
|
32
|
+
@input="setTo"
|
|
33
|
+
></wt-input>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
38
|
+
|
|
39
|
+
<script>
|
|
40
|
+
import debounce from '../../../scripts/debounce';
|
|
41
|
+
import baseFilterMixin from '../mixins/baseFilterMixin/baseFilterMixin';
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
name: 'filter-from-to',
|
|
45
|
+
mixins: [baseFilterMixin],
|
|
46
|
+
props: {
|
|
47
|
+
filterQuery: {
|
|
48
|
+
type: String,
|
|
49
|
+
required: true,
|
|
50
|
+
},
|
|
51
|
+
label: {
|
|
52
|
+
type: String,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
methods: {
|
|
56
|
+
restore() {
|
|
57
|
+
this.restoreFrom();
|
|
58
|
+
this.restoreTo();
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
restoreFrom() {
|
|
62
|
+
const from = 0;
|
|
63
|
+
const queryValue = this.$route.query[`${this.filterQuery}From`];
|
|
64
|
+
// this.value.from = +queryValue || from;
|
|
65
|
+
const value = { from: +queryValue || from, to: this.value.to };
|
|
66
|
+
this.setValue({ filter: this.filterQuery, value });
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
restoreTo() {
|
|
70
|
+
const to = null;
|
|
71
|
+
const queryValue = this.$route.query[`${this.filterQuery}To`];
|
|
72
|
+
// this.value.to = +queryValue || to;
|
|
73
|
+
const value = { from: this.value.from, to: +queryValue || to };
|
|
74
|
+
console.info(value);
|
|
75
|
+
this.setValue({ filter: this.filterQuery, value });
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
setFrom(value) {
|
|
79
|
+
this.setValueToQuery({
|
|
80
|
+
filterQuery: `${this.filterQuery}From`,
|
|
81
|
+
value,
|
|
82
|
+
});
|
|
83
|
+
this.restoreFrom();
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
setTo(value) {
|
|
87
|
+
this.setValueToQuery({
|
|
88
|
+
filterQuery: `${this.filterQuery}To`,
|
|
89
|
+
value,
|
|
90
|
+
});
|
|
91
|
+
this.restoreTo();
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
created() {
|
|
96
|
+
this.setFrom = debounce(this.setFrom);
|
|
97
|
+
this.setTo = debounce(this.setTo);
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
</script>
|
|
101
|
+
|
|
102
|
+
<style lang="scss" scoped>
|
|
103
|
+
.filter-from-to {
|
|
104
|
+
|
|
105
|
+
& > .wt-label {
|
|
106
|
+
margin-bottom: 10px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
&:hover > .wt-label {
|
|
110
|
+
color: var(--form-label--hover-color);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
&:focus-within > .wt-label {
|
|
114
|
+
color: var(--form-label--active-color);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.filter-from-to__inputs-wrapper,
|
|
119
|
+
.filter-from-to__input-wrapper {
|
|
120
|
+
display: flex;
|
|
121
|
+
align-items: center;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.filter-from-to__input-label {
|
|
125
|
+
@extend %typo-subtitle-1;
|
|
126
|
+
margin-right: 5px;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.filter-from-to__input-wrapper {
|
|
130
|
+
&:focus-within .wt-label {
|
|
131
|
+
color: var(--form-label--active-color)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.filter-from-to-input {
|
|
135
|
+
width: 70px;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
&:first-child {
|
|
139
|
+
margin-right: 10px;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
</style>
|