diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/frontend/snippets/components/snippet_title_spec.js | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/frontend/snippets/components/snippet_title_spec.js')
-rw-r--r-- | spec/frontend/snippets/components/snippet_title_spec.js | 123 |
1 files changed, 78 insertions, 45 deletions
diff --git a/spec/frontend/snippets/components/snippet_title_spec.js b/spec/frontend/snippets/components/snippet_title_spec.js index 0a3b57c9244..9e6a30885d4 100644 --- a/spec/frontend/snippets/components/snippet_title_spec.js +++ b/spec/frontend/snippets/components/snippet_title_spec.js @@ -1,71 +1,104 @@ -import { GlSprintf } from '@gitlab/ui'; +import { GlSprintf, GlIcon } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import SnippetDescription from '~/snippets/components/snippet_description_view.vue'; +import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import SnippetTitle from '~/snippets/components/snippet_title.vue'; -describe('Snippet header component', () => { +describe('Snippet title component', () => { let wrapper; const title = 'The property of Thor'; const description = 'Do not touch this hammer'; const descriptionHtml = `<h2>${description}</h2>`; - const snippet = { - snippet: { - title, - description, - descriptionHtml, - }, - }; - - function createComponent({ props = snippet } = {}) { - const defaultProps = { ...props }; + function createComponent({ propsData = {} } = {}) { wrapper = shallowMount(SnippetTitle, { propsData: { - ...defaultProps, + snippet: { + title, + description, + descriptionHtml, + }, + ...propsData, + }, + directives: { + GlTooltip: createMockDirective('gl-tooltip'), }, }); } - it('renders itself', () => { - createComponent(); - expect(wrapper.find('.snippet-header').exists()).toBe(true); - }); + const findIcon = () => wrapper.findComponent(GlIcon); + const findTooltip = () => getBinding(findIcon().element, 'gl-tooltip'); - it('renders snippets title and description', () => { - createComponent(); + describe('default state', () => { + beforeEach(() => { + createComponent(); + }); - expect(wrapper.text().trim()).toContain(title); - expect(wrapper.findComponent(SnippetDescription).props('description')).toBe(descriptionHtml); - }); + it('renders itself', () => { + expect(wrapper.find('.snippet-header').exists()).toBe(true); + }); - it('does not render recent changes time stamp if there were no updates', () => { - createComponent(); - expect(wrapper.findComponent(GlSprintf).exists()).toBe(false); - }); + it('does not render spam icon when author is not banned', () => { + expect(findIcon().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', - }, + it('renders snippets title and description', () => { + expect(wrapper.text().trim()).toContain(title); + expect(wrapper.findComponent(SnippetDescription).props('description')).toBe(descriptionHtml); }); - createComponent({ props }); - expect(wrapper.findComponent(GlSprintf).exists()).toBe(false); - }); + it('does not render recent changes time stamp if there were no updates', () => { + expect(wrapper.findComponent(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', - }, + it('does not render recent changes time stamp if the time for creation and updates match', () => { + createComponent({ + propsData: { + snippet: { + createdAt: '2019-12-16T21:45:36Z', + updatedAt: '2019-12-16T21:45:36Z', + }, + }, + }); + + expect(wrapper.findComponent(GlSprintf).exists()).toBe(false); + }); + + it('renders translated string with most recent changes timestamp if changes were made', () => { + createComponent({ + propsData: { + snippet: { + createdAt: '2019-12-16T21:45:36Z', + updatedAt: '2019-15-16T21:45:36Z', + }, + }, + }); + + expect(wrapper.findComponent(GlSprintf).exists()).toBe(true); }); - createComponent({ props }); + }); + + describe('when author is snippet is banned', () => { + it('renders spam icon and tooltip when author is banned', () => { + createComponent({ + propsData: { + snippet: { + hidden: true, + }, + }, + }); + + expect(findIcon().props()).toMatchObject({ + ariaLabel: 'Hidden', + name: 'spam', + size: 16, + }); - expect(wrapper.findComponent(GlSprintf).exists()).toBe(true); + expect(findIcon().attributes('title')).toBe( + 'This snippet is hidden because its author has been banned', + ); + + expect(findTooltip()).toBeDefined(); + }); }); }); |