2019-12-18 15:08:03 +00:00
|
|
|
import SnippetTitle from '~/snippets/components/snippet_title.vue';
|
2020-05-07 15:09:29 +00:00
|
|
|
import SnippetDescription from '~/snippets/components/snippet_description_view.vue';
|
2019-12-18 15:08:03 +00:00
|
|
|
import { GlSprintf } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
|
|
|
|
describe('Snippet header component', () => {
|
|
|
|
let wrapper;
|
|
|
|
const title = 'The property of Thor';
|
|
|
|
const description = 'Do not touch this hammer';
|
2020-03-12 12:09:17 +00:00
|
|
|
const descriptionHtml = `<h2>${description}</h2>`;
|
2019-12-18 15:08:03 +00:00
|
|
|
const snippet = {
|
|
|
|
snippet: {
|
|
|
|
title,
|
|
|
|
description,
|
2020-03-12 12:09:17 +00:00
|
|
|
descriptionHtml,
|
2019-12-18 15:08:03 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
function createComponent({ props = snippet } = {}) {
|
2020-05-07 21:09:26 +00:00
|
|
|
const defaultProps = { ...props };
|
2019-12-18 15:08:03 +00:00
|
|
|
|
|
|
|
wrapper = shallowMount(SnippetTitle, {
|
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders itself', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(wrapper.find('.snippet-header').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders snippets title and description', () => {
|
|
|
|
createComponent();
|
2020-05-07 15:09:29 +00:00
|
|
|
|
2019-12-18 15:08:03 +00:00
|
|
|
expect(wrapper.text().trim()).toContain(title);
|
2020-05-07 15:09:29 +00:00
|
|
|
expect(wrapper.find(SnippetDescription).props('description')).toBe(descriptionHtml);
|
2019-12-18 15:08:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render recent changes time stamp if there were no updates', () => {
|
|
|
|
createComponent();
|
|
|
|
expect(wrapper.find(GlSprintf).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render recent changes time stamp if the time for creation and updates match', () => {
|
|
|
|
const props = Object.assign(snippet, {
|
|
|
|
snippet: {
|
|
|
|
...snippet.snippet,
|
|
|
|
createdAt: '2019-12-16T21:45:36Z',
|
|
|
|
updatedAt: '2019-12-16T21:45:36Z',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
createComponent({ props });
|
|
|
|
|
|
|
|
expect(wrapper.find(GlSprintf).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders translated string with most recent changes timestamp if changes were made', () => {
|
|
|
|
const props = Object.assign(snippet, {
|
|
|
|
snippet: {
|
|
|
|
...snippet.snippet,
|
|
|
|
createdAt: '2019-12-16T21:45:36Z',
|
|
|
|
updatedAt: '2019-15-16T21:45:36Z',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
createComponent({ props });
|
|
|
|
|
|
|
|
expect(wrapper.find(GlSprintf).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|