debian-mirror-gitlab/spec/frontend/boards/components/issue_due_date_spec.js

79 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-04-08 14:13:33 +05:30
import { shallowMount } from '@vue/test-utils';
2018-12-13 13:39:08 +05:30
import dateFormat from 'dateformat';
import IssueDueDate from '~/boards/components/issue_due_date.vue';
2020-04-08 14:13:33 +05:30
const createComponent = (dueDate = new Date(), closed = false) =>
shallowMount(IssueDueDate, {
propsData: {
closed,
date: dateFormat(dueDate, 'yyyy-mm-dd', true),
},
});
2021-03-08 18:12:59 +05:30
const findTime = (wrapper) => wrapper.find('time');
2018-12-13 13:39:08 +05:30
describe('Issue Due Date component', () => {
2020-04-08 14:13:33 +05:30
let wrapper;
2018-12-13 13:39:08 +05:30
let date;
beforeEach(() => {
date = new Date();
});
afterEach(() => {
2020-04-08 14:13:33 +05:30
wrapper.destroy();
2018-12-13 13:39:08 +05:30
});
it('should render "Today" if the due date is today', () => {
2020-04-08 14:13:33 +05:30
wrapper = createComponent();
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(findTime(wrapper).text()).toBe('Today');
2018-12-13 13:39:08 +05:30
});
it('should render "Yesterday" if the due date is yesterday', () => {
date.setDate(date.getDate() - 1);
2020-04-08 14:13:33 +05:30
wrapper = createComponent(date);
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(findTime(wrapper).text()).toBe('Yesterday');
2018-12-13 13:39:08 +05:30
});
it('should render "Tomorrow" if the due date is one day from now', () => {
date.setDate(date.getDate() + 1);
2020-04-08 14:13:33 +05:30
wrapper = createComponent(date);
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(findTime(wrapper).text()).toBe('Tomorrow');
2018-12-13 13:39:08 +05:30
});
it('should render day of the week if due date is one week away', () => {
date.setDate(date.getDate() + 5);
2020-04-08 14:13:33 +05:30
wrapper = createComponent(date);
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(findTime(wrapper).text()).toBe(dateFormat(date, 'dddd'));
2018-12-13 13:39:08 +05:30
});
it('should render month and day for other dates', () => {
date.setDate(date.getDate() + 17);
2020-04-08 14:13:33 +05:30
wrapper = createComponent(date);
2018-12-23 12:14:25 +05:30
const today = new Date();
const isDueInCurrentYear = today.getFullYear() === date.getFullYear();
const format = isDueInCurrentYear ? 'mmm d' : 'mmm d, yyyy';
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
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);
2018-12-13 13:39:08 +05:30
});
2020-04-08 14:13:33 +05:30
it('should not contain the `.text-danger` css class for overdue issue that is closed', () => {
2018-12-13 13:39:08 +05:30
date.setDate(date.getDate() - 17);
2020-04-08 14:13:33 +05:30
const closed = true;
wrapper = createComponent(date, closed);
2018-12-13 13:39:08 +05:30
2020-04-08 14:13:33 +05:30
expect(findTime(wrapper).classes('text-danger')).toBe(false);
2018-12-13 13:39:08 +05:30
});
});