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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
import { shallowMount } from '@vue/test-utils';
import dateFormat from 'dateformat';
import IssueDueDate from '~/boards/components/issue_due_date.vue';
const createComponent = (dueDate = new Date(), closed = false) =>
shallowMount(IssueDueDate, {
propsData: {
closed,
date: dateFormat(dueDate, 'yyyy-mm-dd', true),
},
});
const findTime = wrapper => wrapper.find('time');
describe('Issue Due Date component', () => {
let wrapper;
let date;
beforeEach(() => {
date = new Date();
});
afterEach(() => {
wrapper.destroy();
});
it('should render "Today" if the due date is today', () => {
wrapper = createComponent();
expect(findTime(wrapper).text()).toBe('Today');
});
it('should render "Yesterday" if the due date is yesterday', () => {
date.setDate(date.getDate() - 1);
wrapper = createComponent(date);
expect(findTime(wrapper).text()).toBe('Yesterday');
});
it('should render "Tomorrow" if the due date is one day from now', () => {
date.setDate(date.getDate() + 1);
wrapper = createComponent(date);
expect(findTime(wrapper).text()).toBe('Tomorrow');
});
it('should render day of the week if due date is one week away', () => {
date.setDate(date.getDate() + 5);
wrapper = createComponent(date);
expect(findTime(wrapper).text()).toBe(dateFormat(date, 'dddd'));
});
it('should render month and day for other dates', () => {
date.setDate(date.getDate() + 17);
wrapper = createComponent(date);
const today = new Date();
const isDueInCurrentYear = today.getFullYear() === date.getFullYear();
const format = isDueInCurrentYear ? 'mmm d' : 'mmm d, yyyy';
expect(findTime(wrapper).text()).toBe(dateFormat(date, format));
});
it('should contain the correct `.text-danger` css class for overdue issue that is open', () => {
date.setDate(date.getDate() - 17);
wrapper = createComponent(date);
expect(findTime(wrapper).classes('text-danger')).toBe(true);
});
it('should not contain the `.text-danger` css class for overdue issue that is closed', () => {
date.setDate(date.getDate() - 17);
const closed = true;
wrapper = createComponent(date, closed);
expect(findTime(wrapper).classes('text-danger')).toBe(false);
});
});
|