Commit fb8b7c25 authored by Justin Ho's avatar Justin Ho

Add specs around due date

- Add specs for sidebar and due date components
- Update mock data to match current schema
parent 2cbc9d23
...@@ -63,7 +63,7 @@ export default { ...@@ -63,7 +63,7 @@ export default {
<div class="hide-collapsed"> <div class="hide-collapsed">
<div class="title">{{ $options.i18n.dueDateTitle }}</div> <div class="title">{{ $options.i18n.dueDateTitle }}</div>
<div class="value"> <div class="value" data-testid="due-date-value">
<strong v-if="dueDate">{{ formattedDueDate }}</strong> <strong v-if="dueDate">{{ formattedDueDate }}</strong>
<span v-else class="no-value">{{ $options.i18n.none }}</span> <span v-else class="no-value">{{ $options.i18n.none }}</span>
</div> </div>
......
import { shallowMount } from '@vue/test-utils';
import IssueDueDate from 'ee/integrations/jira/issues_show/components/sidebar/issue_due_date.vue';
import { useFakeDate } from 'helpers/fake_date';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
describe('IssueDueDate', () => {
let wrapper;
const createComponent = ({ props = {} } = {}) => {
wrapper = extendedWrapper(
shallowMount(IssueDueDate, {
propsData: props,
}),
);
};
afterEach(() => {
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
});
const findDueDateValue = () => wrapper.findByTestId('due-date-value');
describe('when dueDate is null', () => {
it('renders "None" as value', () => {
createComponent();
expect(findDueDateValue().text()).toBe('None');
});
});
describe('when dueDate is in the past', () => {
const dueDate = '2021-02-14T00:00:00.000Z';
useFakeDate(2021, 2, 18);
it('renders formatted dueDate', () => {
createComponent({
props: {
dueDate,
},
});
expect(findDueDateValue().text()).toBe('Feb 14, 2021 (Past due)');
});
});
describe('when dueDate is in the future', () => {
const dueDate = '2021-02-14T00:00:00.000Z';
useFakeDate(2020, 12, 20);
it('renders formatted dueDate', () => {
createComponent({
props: {
dueDate,
},
});
expect(findDueDateValue().text()).toBe('Feb 14, 2021');
});
});
});
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Assignee from 'ee/integrations/jira/issues_show/components/sidebar/assignee.vue'; import Assignee from 'ee/integrations/jira/issues_show/components/sidebar/assignee.vue';
import IssueDueDate from 'ee/integrations/jira/issues_show/components/sidebar/issue_due_date.vue';
import IssueReference from 'ee/integrations/jira/issues_show/components/sidebar/issue_reference.vue'; import IssueReference from 'ee/integrations/jira/issues_show/components/sidebar/issue_reference.vue';
import Sidebar from 'ee/integrations/jira/issues_show/components/sidebar/jira_issues_sidebar_root.vue'; import Sidebar from 'ee/integrations/jira/issues_show/components/sidebar/jira_issues_sidebar_root.vue';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
...@@ -31,16 +32,17 @@ describe('JiraIssuesSidebar', () => { ...@@ -31,16 +32,17 @@ describe('JiraIssuesSidebar', () => {
const findLabelsSelect = () => wrapper.findComponent(LabelsSelect); const findLabelsSelect = () => wrapper.findComponent(LabelsSelect);
const findAssignee = () => wrapper.findComponent(Assignee); const findAssignee = () => wrapper.findComponent(Assignee);
const findIssueDueDate = () => wrapper.findComponent(IssueDueDate);
const findIssueReference = () => wrapper.findComponent(IssueReference); const findIssueReference = () => wrapper.findComponent(IssueReference);
it('renders Labels block', async () => { it('renders Labels block', () => {
createComponent(); createComponent();
expect(findLabelsSelect().exists()).toBe(true); expect(findLabelsSelect().exists()).toBe(true);
expect(findLabelsSelect().props('selectedLabels')).toEqual(mockJiraIssue.labels); expect(findLabelsSelect().props('selectedLabels')).toEqual(mockJiraIssue.labels);
}); });
it('renders Assignee block', async () => { it('renders Assignee block', () => {
createComponent(); createComponent();
const assignee = findAssignee(); const assignee = findAssignee();
...@@ -48,6 +50,14 @@ describe('JiraIssuesSidebar', () => { ...@@ -48,6 +50,14 @@ describe('JiraIssuesSidebar', () => {
expect(assignee.props('assignee')).toEqual(mockJiraIssue.assignees[0]); expect(assignee.props('assignee')).toEqual(mockJiraIssue.assignees[0]);
}); });
it('renders IssueDueDate', () => {
createComponent();
const dueDate = findIssueDueDate();
expect(dueDate.exists()).toBe(true);
expect(dueDate.props('dueDate')).toEqual(mockJiraIssue.dueDate);
});
describe('when references.relative is null', () => { describe('when references.relative is null', () => {
it('does not render IssueReference', () => { it('does not render IssueReference', () => {
createComponent({ createComponent({
......
export const mockJiraIssue = { export const mockJiraIssue = {
title_html: title: 'FE-2 The second FE issue on Jira',
'<a href="https://jira.reali.sh:8080/projects/FE/issues/FE-2">FE-2</a> The second FE issue on Jira',
description_html: description_html:
'<a href="https://jira.reali.sh:8080/projects/FE/issues/FE-2">FE-2</a> The second FE issue on Jira', '<a href="https://jira.reali.sh:8080/projects/FE/issues/FE-2">FE-2</a> The second FE issue on Jira',
created_at: '"2021-02-01T04:04:40.833Z"', created_at: '"2021-02-01T04:04:40.833Z"',
...@@ -16,6 +15,7 @@ export const mockJiraIssue = { ...@@ -16,6 +15,7 @@ export const mockJiraIssue = {
avatar_url: 'http://127.0.0.1:3000/uploads/-/system/user/avatar/1/avatar.png?width=90', avatar_url: 'http://127.0.0.1:3000/uploads/-/system/user/avatar/1/avatar.png?width=90',
}, },
], ],
due_date: '2021-02-14T00:00:00.000Z',
labels: [ labels: [
{ {
title: 'In Progress', title: 'In Progress',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment