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.

51 lines
1.7 KiB
JavaScript
Raw Normal View History

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';
2022-11-25 23:54:43 +05:30
const timeago = getTimeago();
2022-08-13 15:12:31 +05:30
describe('Edited component', () => {
let wrapper;
const findAuthorLink = () => wrapper.find('a');
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 });
const updatedAt = '2017-05-15T12:31:04.428Z';
2022-08-13 15:12:31 +05:30
it('renders an edited at+by string', () => {
wrapper = mountComponent({
2022-11-25 23:54:43 +05:30
updatedAt,
2022-08-13 15:12:31 +05:30
updatedByName: 'Some User',
updatedByPath: '/some_user',
});
2022-11-25 23:54:43 +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');
expect(findTimeAgoTooltip().exists()).toBe(true);
2017-08-17 22:00:37 +05:30
});
it('if no updatedAt is provided, no time element will be rendered', () => {
2022-08-13 15:12:31 +05:30
wrapper = mountComponent({
updatedByName: 'Some User',
updatedByPath: '/some_user',
});
expect(formatText(wrapper.text())).toBe('Edited by Some User');
expect(findAuthorLink().attributes('href')).toBe('/some_user');
expect(findTimeAgoTooltip().exists()).toBe(false);
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
});
});