@weni/unnnic-system 3.11.1-alpha.2 → 3.11.1-alpha.4
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/CHANGELOG.md +32 -0
- package/dist/components/DatePicker/DatePicker.vue.d.ts +69 -249
- package/dist/components/DatePicker/DatePicker.vue.d.ts.map +1 -1
- package/dist/components/InputDatePicker/InputDatePicker.vue.d.ts +47 -911
- package/dist/components/InputDatePicker/InputDatePicker.vue.d.ts.map +1 -1
- package/dist/components/Select/SelectItem.vue.d.ts +1 -1
- package/dist/components/SelectSmart/SelectSmart.vue.d.ts +1 -1
- package/dist/components/SelectSmart/SelectSmartOption.vue.d.ts +1 -1
- package/dist/components/Sidebar/SidebarItem.vue.d.ts +2 -2
- package/dist/{es-2f0d1dd1.mjs → es-fc643bdb.mjs} +1 -1
- package/dist/{index-7d496127.mjs → index-4601aaf4.mjs} +9037 -9104
- package/dist/{pt-br-ec24bd23.mjs → pt-br-0b82e6d2.mjs} +1 -1
- package/dist/style.css +1 -1
- package/dist/unnnic.mjs +1 -1
- package/dist/unnnic.umd.js +42 -42
- package/package.json +1 -1
- package/src/components/DatePicker/DatePicker.vue +628 -516
- package/src/components/DatePicker/__tests__/DatePicker.spec.js +227 -0
- package/src/components/Drawer/__tests__/Drawer.spec.js +11 -15
- package/src/components/Drawer/__tests__/__snapshots__/Drawer.spec.js.snap +9 -9
- package/src/components/InputDatePicker/InputDatePicker.vue +149 -183
- package/src/components/InputDatePicker/__test__/InputDatePicker.spec.js +159 -0
- package/src/components/Tab/__test__/__snapshots__/Tab.spec.js.snap +1 -1
- package/src/stories/DatePicker.stories.js +71 -0
- package/src/stories/InputDatePicker.stories.js +22 -0
- package/dist/components/index.d.ts +0 -25946
- package/dist/components/index.d.ts.map +0 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils';
|
|
2
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
3
|
+
import InputDatePicker from '../InputDatePicker.vue';
|
|
4
|
+
|
|
5
|
+
const factory = (props = {}) =>
|
|
6
|
+
mount(InputDatePicker, {
|
|
7
|
+
props: {
|
|
8
|
+
modelValue: {
|
|
9
|
+
start: null,
|
|
10
|
+
end: null,
|
|
11
|
+
},
|
|
12
|
+
...props,
|
|
13
|
+
},
|
|
14
|
+
global: {
|
|
15
|
+
stubs: {
|
|
16
|
+
UnnnicInput: {
|
|
17
|
+
name: 'UnnnicInput',
|
|
18
|
+
template:
|
|
19
|
+
'<input data-testid="input" v-bind="$attrs" @focus="$emit(\'focus\', $event)" />',
|
|
20
|
+
},
|
|
21
|
+
UnnnicDatePicker: {
|
|
22
|
+
name: 'UnnnicDatePicker',
|
|
23
|
+
props: ['minDate', 'maxDate', 'periodBaseDate', 'options'],
|
|
24
|
+
template: '<div data-testid="datepicker"></div>',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('InputDatePicker.vue', () => {
|
|
31
|
+
let wrapper;
|
|
32
|
+
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
wrapper = factory();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('renders input and does not show datepicker by default', () => {
|
|
38
|
+
expect(wrapper.find('[data-testid="input"]').exists()).toBe(true);
|
|
39
|
+
expect(wrapper.find('[data-testid="datepicker"]').exists()).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('opens datepicker when input receives focus', async () => {
|
|
43
|
+
const input = wrapper.find('[data-testid="input"]');
|
|
44
|
+
await input.trigger('focus');
|
|
45
|
+
|
|
46
|
+
wrapper.vm.showCalendarFilter = true;
|
|
47
|
+
await wrapper.vm.$nextTick();
|
|
48
|
+
|
|
49
|
+
expect(wrapper.findComponent({ name: 'UnnnicDatePicker' }).exists()).toBe(
|
|
50
|
+
true,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('computes filterText placeholder when there is no date selected', () => {
|
|
55
|
+
expect(wrapper.vm.filterText).toBe('mm/dd/yyyy');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('computes filterText from start and end dates', async () => {
|
|
59
|
+
const withDates = factory({
|
|
60
|
+
modelValue: {
|
|
61
|
+
start: '2025-01-10',
|
|
62
|
+
end: '2025-01-20',
|
|
63
|
+
},
|
|
64
|
+
format: 'YYYY-MM-DD',
|
|
65
|
+
inputFormat: 'MM-DD-YYYY',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(withDates.vm.filterText).toBe('01-10-2025 ~ 01-20-2025');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('computes initialStartDate and initialEndDate for DatePicker', () => {
|
|
72
|
+
const withDates = factory({
|
|
73
|
+
modelValue: {
|
|
74
|
+
start: '2025-01-10',
|
|
75
|
+
end: '2025-01-20',
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(withDates.vm.initialStartDate).toBe('01 10 2025');
|
|
80
|
+
expect(withDates.vm.initialEndDate).toBe('01 20 2025');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('emits selectDate with formatted dates when DatePicker emits change', async () => {
|
|
84
|
+
wrapper.vm.showCalendarFilter = true;
|
|
85
|
+
await wrapper.vm.$nextTick();
|
|
86
|
+
|
|
87
|
+
const datePicker = wrapper.findComponent({ name: 'UnnnicDatePicker' });
|
|
88
|
+
|
|
89
|
+
const payload = {
|
|
90
|
+
startDate: '01-10-2025',
|
|
91
|
+
endDate: '01-20-2025',
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
await datePicker.vm.$emit('change', payload);
|
|
95
|
+
|
|
96
|
+
const emitted = wrapper.emitted('selectDate');
|
|
97
|
+
expect(emitted).toBeTruthy();
|
|
98
|
+
|
|
99
|
+
const [formatted] = emitted[0];
|
|
100
|
+
expect(formatted).toEqual({
|
|
101
|
+
start: '2025-01-10',
|
|
102
|
+
end: '2025-01-20',
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('emits update:model-value and closes dropdown when DatePicker emits submit', async () => {
|
|
107
|
+
wrapper.vm.showCalendarFilter = true;
|
|
108
|
+
await wrapper.vm.$nextTick();
|
|
109
|
+
|
|
110
|
+
const datePicker = wrapper.findComponent({ name: 'UnnnicDatePicker' });
|
|
111
|
+
|
|
112
|
+
const payload = {
|
|
113
|
+
startDate: '01-10-2025',
|
|
114
|
+
endDate: '01-20-2025',
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
await datePicker.vm.$emit('submit', payload);
|
|
118
|
+
|
|
119
|
+
const emitted = wrapper.emitted('update:model-value');
|
|
120
|
+
expect(emitted).toBeTruthy();
|
|
121
|
+
|
|
122
|
+
const [newValue] = emitted[0];
|
|
123
|
+
expect(newValue).toEqual({
|
|
124
|
+
start: '2025-01-10',
|
|
125
|
+
end: '2025-01-20',
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
expect(wrapper.vm.showCalendarFilter).toBe(false);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('passes minDate, maxDate, options and periodBaseDate down to DatePicker', async () => {
|
|
132
|
+
const props = {
|
|
133
|
+
minDate: '2025-01-01',
|
|
134
|
+
maxDate: '2025-01-31',
|
|
135
|
+
periodBaseDate: '2025-01-15',
|
|
136
|
+
options: [{ name: 'Last 7 days', id: 'last-7-days' }],
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
wrapper = factory(props);
|
|
140
|
+
wrapper.vm.showCalendarFilter = true;
|
|
141
|
+
await wrapper.vm.$nextTick();
|
|
142
|
+
|
|
143
|
+
const datePicker = wrapper.findComponent({ name: 'UnnnicDatePicker' });
|
|
144
|
+
const dpProps = datePicker.props();
|
|
145
|
+
|
|
146
|
+
expect(dpProps.minDate).toBe(props.minDate);
|
|
147
|
+
expect(dpProps.maxDate).toBe(props.maxDate);
|
|
148
|
+
expect(dpProps.periodBaseDate).toBe(props.periodBaseDate);
|
|
149
|
+
expect(dpProps.options).toEqual(props.options);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('closes dropdown on mouseout when clicking outside', () => {
|
|
153
|
+
wrapper.vm.showCalendarFilter = true;
|
|
154
|
+
|
|
155
|
+
wrapper.vm.mouseout({ target: document.createElement('div') });
|
|
156
|
+
|
|
157
|
+
expect(wrapper.vm.showCalendarFilter).toBe(false);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -4,7 +4,7 @@ exports[`Tab.vue > matches the snapshot 1`] = `
|
|
|
4
4
|
"<div data-v-b4e39fac="" class="tab size-md">
|
|
5
5
|
<header data-v-b4e39fac="" class="tab-header">
|
|
6
6
|
<ul data-v-b4e39fac="" class="tab-content">
|
|
7
|
-
<li data-v-b4e39fac="" class="tab-head">tab1<div data-v-b3d24f2b="" class="unnnic-tooltip-trigger" data-testid="tooltip-trigger" data-state="closed" data-grace-area-trigger=""><span data-v-26446d8e="" data-v-b4e39fac="" class="material-symbols-rounded unnnic-icon-scheme--
|
|
7
|
+
<li data-v-b4e39fac="" class="tab-head">tab1<div data-v-b3d24f2b="" class="unnnic-tooltip-trigger" data-testid="tooltip-trigger" data-state="closed" data-grace-area-trigger=""><span data-v-26446d8e="" data-v-b4e39fac="" class="unnnic-icon material-symbols-rounded unnnic-icon-scheme--fg-base unnnic-icon-size--sm unnnic-icon__size--sm" data-testid="material-icon" translate="no">help</span></div>
|
|
8
8
|
<!--teleport start-->
|
|
9
9
|
<!--teleport end-->
|
|
10
10
|
</li>
|
|
@@ -20,6 +20,7 @@ export default {
|
|
|
20
20
|
months: { control: { type: 'array' } },
|
|
21
21
|
days: { control: { type: 'array' } },
|
|
22
22
|
options: { control: { type: 'array' } },
|
|
23
|
+
periodBaseDate: { control: { type: 'text' } },
|
|
23
24
|
clearLabel: { control: { type: 'text' } },
|
|
24
25
|
actionLabel: { control: { type: 'text' } },
|
|
25
26
|
},
|
|
@@ -33,3 +34,73 @@ export const Default = {
|
|
|
33
34
|
initialEndDate: '12-01-2021',
|
|
34
35
|
},
|
|
35
36
|
};
|
|
37
|
+
|
|
38
|
+
export const SmallDayPicker = {
|
|
39
|
+
args: {
|
|
40
|
+
size: 'small',
|
|
41
|
+
type: 'day',
|
|
42
|
+
maxDate: moment().format('YYYY-MM-DD'),
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const MonthView = {
|
|
47
|
+
args: {
|
|
48
|
+
size: 'large',
|
|
49
|
+
type: 'month',
|
|
50
|
+
maxDate: moment().format('YYYY-MM-DD'),
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export const YearView = {
|
|
55
|
+
args: {
|
|
56
|
+
size: 'large',
|
|
57
|
+
type: 'year',
|
|
58
|
+
maxDate: moment().format('YYYY-MM-DD'),
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const WithMinAndMaxDateRange = {
|
|
63
|
+
args: {
|
|
64
|
+
size: 'large',
|
|
65
|
+
type: 'day',
|
|
66
|
+
minDate: moment().subtract(30, 'days').format('YYYY-MM-DD'),
|
|
67
|
+
maxDate: moment().format('YYYY-MM-DD'),
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const WithCustomLabelsAndDisableClear = {
|
|
72
|
+
args: {
|
|
73
|
+
size: 'large',
|
|
74
|
+
type: 'day',
|
|
75
|
+
clearLabel: 'Reset',
|
|
76
|
+
actionLabel: 'Apply',
|
|
77
|
+
disableClear: true,
|
|
78
|
+
options: [
|
|
79
|
+
{ name: 'Last 7 days', id: 'last-7-days' },
|
|
80
|
+
{ name: 'Last 30 days', id: 'last-30-days' },
|
|
81
|
+
{ name: 'Current month', id: 'current-month' },
|
|
82
|
+
{ name: 'Previous month', id: 'previous-month' },
|
|
83
|
+
{ name: 'Custom', id: 'custom' },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const CustomRelativePeriodsWithBaseDate = {
|
|
89
|
+
args: {
|
|
90
|
+
size: 'large',
|
|
91
|
+
|
|
92
|
+
periodBaseDate: moment().subtract(1, 'day').format('YYYY-MM-DD'),
|
|
93
|
+
|
|
94
|
+
maxDate: moment().subtract(1, 'day').format('YYYY-MM-DD'),
|
|
95
|
+
|
|
96
|
+
options: [
|
|
97
|
+
{ name: 'Last 7 days (up to 24h ago)', id: 'last-7-days' },
|
|
98
|
+
{ name: 'Last 14 days (up to 24h ago)', id: 'last-14-days' },
|
|
99
|
+
{ name: 'Last 30 days (up to 24h ago)', id: 'last-30-days' },
|
|
100
|
+
{ name: 'Last 12 months (up to 24h ago)', id: 'last-12-months' },
|
|
101
|
+
{ name: 'Current month (up to 24h ago)', id: 'current-month' },
|
|
102
|
+
{ name: 'Previous month (up to 24h ago)', id: 'previous-month' },
|
|
103
|
+
{ name: 'Custom', id: 'custom' },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
};
|
|
@@ -67,3 +67,25 @@ export const WithMinMaxDates = {
|
|
|
67
67
|
],
|
|
68
68
|
},
|
|
69
69
|
};
|
|
70
|
+
|
|
71
|
+
export const WithCustomRelativePeriodsAndBaseDate = {
|
|
72
|
+
args: {
|
|
73
|
+
size: 'sm',
|
|
74
|
+
next: true,
|
|
75
|
+
iconPosition: 'right',
|
|
76
|
+
fillW: true,
|
|
77
|
+
|
|
78
|
+
periodBaseDate: moment().subtract(1, 'day').format('YYYY-MM-DD'),
|
|
79
|
+
maxDate: moment().subtract(1, 'day').format('YYYY-MM-DD'),
|
|
80
|
+
|
|
81
|
+
options: [
|
|
82
|
+
{ name: 'Last 7 days (up to 24h ago)', id: 'last-7-days' },
|
|
83
|
+
{ name: 'Last 14 days (up to 24h ago)', id: 'last-14-days' },
|
|
84
|
+
{ name: 'Last 30 days (up to 24h ago)', id: 'last-30-days' },
|
|
85
|
+
{ name: 'Last 12 months (up to 24h ago)', id: 'last-12-months' },
|
|
86
|
+
{ name: 'Current month (up to 24h ago)', id: 'current-month' },
|
|
87
|
+
{ name: 'Previous month (up to 24h ago)', id: 'previous-month' },
|
|
88
|
+
{ name: 'Custom', id: 'custom' },
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
};
|