-
Notifications
You must be signed in to change notification settings - Fork 268
/
Copy pathDate.test.ts
60 lines (52 loc) · 1.84 KB
/
Date.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { mount } from '@vue/test-utils';
import Date from '@shell/components/formatter/Date.vue';
import dayjs from 'dayjs';
describe('component: Date formatter', () => {
it.each([
'ddd, MMM D YYYY',
'MMM YYYY'
])('should use date format pref', async(dateFormat) => {
const inputTime = dayjs().toString();
const expectedDate = dayjs(inputTime).format(dateFormat);
const wrapper = await mount(Date, {
props: { value: inputTime, showTime: false },
global: { mocks: { $store: { getters: { 'prefs/get': () => dateFormat } } } }
});
const element = wrapper.find('span');
expect(element.text()).toBe(expectedDate);
});
it.each([
'h:mm:ss a',
'hh:mm'
])('should use time format pref', async(timeFormat) => {
const inputTime = dayjs().toString();
const expectedDate = dayjs(inputTime).format(timeFormat);
const wrapper = await mount(Date, {
props: { value: inputTime, showDate: false },
global: { mocks: { $store: { getters: { 'prefs/get': () => timeFormat } } } }
});
const element = wrapper.find('span');
expect(element.text()).toBe(expectedDate);
});
it.each([
'div',
'hr'
])('use custom tag provided by tagName prop', async(tagName) => {
const wrapper = await mount(Date, {
props: { value: dayjs().toString(), tagName },
global: { mocks: { $store: { getters: { 'prefs/get': jest.fn() } } } }
});
const element = wrapper.find(tagName);
expect(element).toBeDefined();
});
it.each([
true,
false
])('should render day and time on different lines if configured', async(multiline) => {
const wrapper = await mount(Date, {
props: { value: dayjs().toString(), multiline },
global: { mocks: { $store: { getters: { 'prefs/get': jest.fn() } } } }
});
expect(wrapper.find('br').exists()).toBe(multiline);
});
});