debian-mirror-gitlab/spec/frontend/snippets/components/snippet_title_spec.js

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

72 lines
2 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import { GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
2020-10-24 23:57:45 +05:30
import SnippetDescription from '~/snippets/components/snippet_description_view.vue';
2021-03-11 19:13:27 +05:30
import SnippetTitle from '~/snippets/components/snippet_title.vue';
2020-03-13 15:44:24 +05:30
describe('Snippet header component', () => {
let wrapper;
const title = 'The property of Thor';
const description = 'Do not touch this hammer';
2020-04-08 14:13:33 +05:30
const descriptionHtml = `<h2>${description}</h2>`;
2020-03-13 15:44:24 +05:30
const snippet = {
snippet: {
title,
description,
2020-04-08 14:13:33 +05:30
descriptionHtml,
2020-03-13 15:44:24 +05:30
},
};
function createComponent({ props = snippet } = {}) {
2020-05-24 23:13:21 +05:30
const defaultProps = { ...props };
2020-03-13 15:44:24 +05:30
wrapper = shallowMount(SnippetTitle, {
propsData: {
...defaultProps,
},
});
}
it('renders itself', () => {
createComponent();
expect(wrapper.find('.snippet-header').exists()).toBe(true);
});
it('renders snippets title and description', () => {
createComponent();
2020-05-24 23:13:21 +05:30
2020-03-13 15:44:24 +05:30
expect(wrapper.text().trim()).toContain(title);
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(SnippetDescription).props('description')).toBe(descriptionHtml);
2020-03-13 15:44:24 +05:30
});
it('does not render recent changes time stamp if there were no updates', () => {
createComponent();
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(GlSprintf).exists()).toBe(false);
2020-03-13 15:44:24 +05:30
});
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 });
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(GlSprintf).exists()).toBe(false);
2020-03-13 15:44:24 +05:30
});
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 });
2022-11-25 23:54:43 +05:30
expect(wrapper.findComponent(GlSprintf).exists()).toBe(true);
2020-03-13 15:44:24 +05:30
});
});