debian-mirror-gitlab/spec/frontend/issues/show/components/edited_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
3.2 KiB
JavaScript
Raw Normal View History

2023-06-20 00:43:36 +05:30
import { GlLink } from '@gitlab/ui';
2022-11-25 23:54:43 +05:30
import { mount } from '@vue/test-utils';
import { getTimeago } from '~/lib/utils/datetime_utility';
2022-08-13 15:12:31 +05:30
import Edited from '~/issues/show/components/edited.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
describe('Edited component', () => {
let wrapper;
2023-06-20 00:43:36 +05:30
const timeago = getTimeago();
const updatedAt = '2017-05-15T12:31:04.428Z';
const findAuthorLink = () => wrapper.findComponent(GlLink);
2022-08-13 15:12:31 +05:30
const findTimeAgoTooltip = () => wrapper.findComponent(TimeAgoTooltip);
const formatText = (text) => text.trim().replace(/\s\s+/g, ' ');
2022-11-25 23:54:43 +05:30
const mountComponent = (propsData) => mount(Edited, { propsData });
2022-08-13 15:12:31 +05:30
2023-06-20 00:43:36 +05:30
describe('task status section', () => {
describe('task status text', () => {
it('renders when there is a task status', () => {
wrapper = mountComponent({ taskCompletionStatus: { completed_count: 1, count: 3 } });
expect(wrapper.text()).toContain('1 of 3 checklist items completed');
});
it('does not render when task count is 0', () => {
wrapper = mountComponent({ taskCompletionStatus: { completed_count: 0, count: 0 } });
expect(wrapper.text()).not.toContain('0 of 0 checklist items completed');
});
2022-08-13 15:12:31 +05:30
});
2023-06-20 00:43:36 +05:30
describe('checkmark', () => {
it('renders when all tasks are completed', () => {
wrapper = mountComponent({ taskCompletionStatus: { completed_count: 3, count: 3 } });
expect(wrapper.text()).toContain('✓');
});
it('does not render when tasks are incomplete', () => {
wrapper = mountComponent({ taskCompletionStatus: { completed_count: 2, count: 3 } });
expect(wrapper.text()).not.toContain('✓');
});
it('does not render when task count is 0', () => {
wrapper = mountComponent({ taskCompletionStatus: { completed_count: 0, count: 0 } });
expect(wrapper.text()).not.toContain('✓');
});
});
describe('middot', () => {
it('renders when there is also "Edited by" text', () => {
wrapper = mountComponent({
taskCompletionStatus: { completed_count: 3, count: 3 },
updatedAt,
});
expect(wrapper.text()).toContain('·');
});
it('does not render when there is no "Edited by" text', () => {
wrapper = mountComponent({ taskCompletionStatus: { completed_count: 3, count: 3 } });
expect(wrapper.text()).not.toContain('·');
});
});
2017-08-17 22:00:37 +05:30
});
2023-06-20 00:43:36 +05:30
it('renders an edited at+by string', () => {
2022-08-13 15:12:31 +05:30
wrapper = mountComponent({
2023-06-20 00:43:36 +05:30
updatedAt,
2022-08-13 15:12:31 +05:30
updatedByName: 'Some User',
updatedByPath: '/some_user',
});
2023-06-20 00:43:36 +05:30
expect(formatText(wrapper.text())).toBe(`Edited ${timeago.format(updatedAt)} by Some User`);
2022-08-13 15:12:31 +05:30
expect(findAuthorLink().attributes('href')).toBe('/some_user');
2023-06-20 00:43:36 +05:30
expect(findTimeAgoTooltip().exists()).toBe(true);
2017-08-17 22:00:37 +05:30
});
it('if no updatedByName and updatedByPath is provided, no user element will be rendered', () => {
2022-08-13 15:12:31 +05:30
wrapper = mountComponent({
2022-11-25 23:54:43 +05:30
updatedAt,
2022-08-13 15:12:31 +05:30
});
2022-11-25 23:54:43 +05:30
expect(formatText(wrapper.text())).toBe(`Edited ${timeago.format(updatedAt)}`);
2022-08-13 15:12:31 +05:30
expect(findAuthorLink().exists()).toBe(false);
expect(findTimeAgoTooltip().exists()).toBe(true);
2017-08-17 22:00:37 +05:30
});
});