2023-05-27 22:25:52 +05:30
|
|
|
import { GlIcon, GlTooltip } from '@gitlab/ui';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-10-24 23:57:45 +05:30
|
|
|
import { mockMilestone } from 'jest/boards/mock_data';
|
2022-01-26 12:08:38 +05:30
|
|
|
import IssueMilestone from '~/issuable/components/issue_milestone.vue';
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
describe('IssueMilestone component', () => {
|
2019-07-31 22:56:46 +05:30
|
|
|
let wrapper;
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
const findTooltip = () => wrapper.findComponent(GlTooltip);
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
const createComponent = (milestone = mockMilestone) =>
|
|
|
|
shallowMount(IssueMilestone, { propsData: { milestone } });
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = createComponent();
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('renders milestone icon', () => {
|
|
|
|
expect(wrapper.findComponent(GlIcon).props('name')).toBe('clock');
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('renders milestone title', () => {
|
|
|
|
expect(wrapper.find('.milestone-title').text()).toBe(mockMilestone.title);
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
describe('tooltip', () => {
|
|
|
|
it('renders `Milestone`', () => {
|
|
|
|
expect(findTooltip().text()).toContain('Milestone');
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('renders milestone title', () => {
|
|
|
|
expect(findTooltip().text()).toContain(mockMilestone.title);
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
describe('humanized dates', () => {
|
|
|
|
it('renders `Expired` when there is a due date in the past', () => {
|
|
|
|
wrapper = createComponent({ ...mockMilestone, due_date: '2019-12-31', start_date: '' });
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findTooltip().text()).toContain('Expired 6 months ago(December 31, 2019)');
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('renders `remaining` when there is a due date in the future', () => {
|
|
|
|
wrapper = createComponent({ ...mockMilestone, due_date: '2020-12-31', start_date: '' });
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findTooltip().text()).toContain('5 months remaining(December 31, 2020)');
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('renders `Started` when there is a start date in the past', () => {
|
|
|
|
wrapper = createComponent({ ...mockMilestone, due_date: '', start_date: '2019-12-31' });
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findTooltip().text()).toContain('Started 6 months ago(December 31, 2019)');
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('renders `Starts` when there is a start date in the future', () => {
|
|
|
|
wrapper = createComponent({ ...mockMilestone, due_date: '', start_date: '2020-12-31' });
|
2019-07-31 22:56:46 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
expect(findTooltip().text()).toContain('Starts in 5 months(December 31, 2020)');
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|