diff options
Diffstat (limited to 'spec/frontend/snippets/components')
-rw-r--r-- | spec/frontend/snippets/components/snippet_title_spec.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/frontend/snippets/components/snippet_title_spec.js b/spec/frontend/snippets/components/snippet_title_spec.js new file mode 100644 index 00000000000..fb2193b26b0 --- /dev/null +++ b/spec/frontend/snippets/components/snippet_title_spec.js @@ -0,0 +1,72 @@ +import SnippetTitle from '~/snippets/components/snippet_title.vue'; +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'; + const snippet = { + snippet: { + title, + description, + }, + }; + + function createComponent({ props = snippet } = {}) { + const defaultProps = Object.assign({}, props); + + wrapper = shallowMount(SnippetTitle, { + sync: false, + propsData: { + ...defaultProps, + }, + }); + } + + afterEach(() => { + wrapper.destroy(); + }); + + it('renders itself', () => { + createComponent(); + expect(wrapper.find('.snippet-header').exists()).toBe(true); + }); + + it('renders snippets title and description', () => { + createComponent(); + expect(wrapper.text().trim()).toContain(title); + expect(wrapper.text().trim()).toContain(description); + }); + + 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); + }); +}); |