diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-23 18:08:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-23 18:08:53 +0000 |
commit | d933bc5a8738d24898c5a82cc72ee9bd050425e6 (patch) | |
tree | 6d4c5ffedc32dc82c3fd6e4e3031f7981505655a /spec/frontend/vue_shared/components/issue | |
parent | 3f9e1b261121f4dbd045341241f81b47356c99cf (diff) | |
download | gitlab-ce-d933bc5a8738d24898c5a82cc72ee9bd050425e6.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared/components/issue')
-rw-r--r-- | spec/frontend/vue_shared/components/issue/__snapshots__/issue_warning_spec.js.snap | 62 | ||||
-rw-r--r-- | spec/frontend/vue_shared/components/issue/issue_warning_spec.js | 134 |
2 files changed, 149 insertions, 47 deletions
diff --git a/spec/frontend/vue_shared/components/issue/__snapshots__/issue_warning_spec.js.snap b/spec/frontend/vue_shared/components/issue/__snapshots__/issue_warning_spec.js.snap new file mode 100644 index 00000000000..49b18d3e106 --- /dev/null +++ b/spec/frontend/vue_shared/components/issue/__snapshots__/issue_warning_spec.js.snap @@ -0,0 +1,62 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Issue Warning Component when issue is confidential but not locked renders information about confidential issue 1`] = ` +<span> + + This is a confidential issue. + People without permission will never get a notification. + + <gl-link-stub + href="confidential-path" + target="_blank" + > + + Learn more + + </gl-link-stub> +</span> +`; + +exports[`Issue Warning Component when issue is locked and confidential renders information about locked and confidential issue 1`] = ` +<span> + <span> + This issue is + <a + href="" + rel="noopener noreferrer" + target="_blank" + > + confidential + </a> + and + <a + href="" + rel="noopener noreferrer" + target="_blank" + > + locked + </a> + . + </span> + + People without permission will never get a notification and won't be able to comment. + +</span> +`; + +exports[`Issue Warning Component when issue is locked but not confidential renders information about locked issue 1`] = ` +<span> + + This issue is locked. + Only project members can comment. + + <gl-link-stub + href="locked-path" + target="_blank" + > + + Learn more + + </gl-link-stub> +</span> +`; diff --git a/spec/frontend/vue_shared/components/issue/issue_warning_spec.js b/spec/frontend/vue_shared/components/issue/issue_warning_spec.js index 7bb054b4e6c..891c70bcb5c 100644 --- a/spec/frontend/vue_shared/components/issue/issue_warning_spec.js +++ b/spec/frontend/vue_shared/components/issue/issue_warning_spec.js @@ -1,65 +1,105 @@ -import Vue from 'vue'; -import mountComponent from 'helpers/vue_mount_component_helper'; -import issueWarning from '~/vue_shared/components/issue/issue_warning.vue'; +import { shallowMount } from '@vue/test-utils'; +import IssueWarning from '~/vue_shared/components/issue/issue_warning.vue'; +import Icon from '~/vue_shared/components/icon.vue'; -const IssueWarning = Vue.extend(issueWarning); +describe('Issue Warning Component', () => { + let wrapper; -function formatWarning(string) { - // Replace newlines with a space then replace multiple spaces with one space - return string - .trim() - .replace(/\n/g, ' ') - .replace(/\s\s+/g, ' '); -} + const findIcon = () => wrapper.find(Icon); + const findLockedBlock = () => wrapper.find({ ref: 'locked' }); + const findConfidentialBlock = () => wrapper.find({ ref: 'confidential' }); + const findLockedAndConfidentialBlock = () => wrapper.find({ ref: 'lockedAndConfidential' }); -describe('Issue Warning Component', () => { - describe('isLocked', () => { - it('should render locked issue warning information', () => { - const props = { + const createComponent = props => { + wrapper = shallowMount(IssueWarning, { + propsData: { + ...props, + }, + }); + }; + + afterEach(() => { + wrapper.destroy(); + wrapper = null; + }); + + describe('when issue is locked but not confidential', () => { + beforeEach(() => { + createComponent({ isLocked: true, - lockedIssueDocsPath: 'docs/issues/locked', - }; - const vm = mountComponent(IssueWarning, props); - - expect( - vm.$el.querySelector('.icon use').getAttributeNS('http://www.w3.org/1999/xlink', 'href'), - ).toMatch(/lock$/); - expect(formatWarning(vm.$el.querySelector('span').textContent)).toEqual( - 'This issue is locked. Only project members can comment. Learn more', - ); - expect(vm.$el.querySelector('a').href).toContain(props.lockedIssueDocsPath); + lockedIssueDocsPath: 'locked-path', + isConfidential: false, + }); + }); + + it('renders information about locked issue', () => { + expect(findLockedBlock().exists()).toBe(true); + expect(findLockedBlock().element).toMatchSnapshot(); + }); + + it('renders warning icon', () => { + expect(findIcon().exists()).toBe(true); + }); + + it('does not render information about locked and confidential issue', () => { + expect(findLockedAndConfidentialBlock().exists()).toBe(false); + }); + + it('does not render information about confidential issue', () => { + expect(findConfidentialBlock().exists()).toBe(false); }); }); - describe('isConfidential', () => { - it('should render confidential issue warning information', () => { - const props = { + describe('when issue is confidential but not locked', () => { + beforeEach(() => { + createComponent({ + isLocked: false, isConfidential: true, - confidentialIssueDocsPath: '/docs/issues/confidential', - }; - const vm = mountComponent(IssueWarning, props); - - expect( - vm.$el.querySelector('.icon use').getAttributeNS('http://www.w3.org/1999/xlink', 'href'), - ).toMatch(/eye-slash$/); - expect(formatWarning(vm.$el.querySelector('span').textContent)).toEqual( - 'This is a confidential issue. People without permission will never get a notification. Learn more', - ); - expect(vm.$el.querySelector('a').href).toContain(props.confidentialIssueDocsPath); + confidentialIssueDocsPath: 'confidential-path', + }); + }); + + it('renders information about confidential issue', () => { + expect(findConfidentialBlock().exists()).toBe(true); + expect(findConfidentialBlock().element).toMatchSnapshot(); + }); + + it('renders warning icon', () => { + expect(wrapper.find(Icon).exists()).toBe(true); + }); + + it('does not render information about locked issue', () => { + expect(findLockedBlock().exists()).toBe(false); + }); + + it('does not render information about locked and confidential issue', () => { + expect(findLockedAndConfidentialBlock().exists()).toBe(false); }); }); - describe('isLocked and isConfidential', () => { - it('should render locked and confidential issue warning information', () => { - const vm = mountComponent(IssueWarning, { + describe('when issue is locked and confidential', () => { + beforeEach(() => { + createComponent({ isLocked: true, isConfidential: true, }); + }); + + it('renders information about locked and confidential issue', () => { + expect(findLockedAndConfidentialBlock().exists()).toBe(true); + expect(findLockedAndConfidentialBlock().element).toMatchSnapshot(); + }); + + it('does not render warning icon', () => { + expect(wrapper.find(Icon).exists()).toBe(false); + }); + + it('does not render information about locked issue', () => { + expect(findLockedBlock().exists()).toBe(false); + }); - expect(vm.$el.querySelector('.icon')).toBeFalsy(); - expect(formatWarning(vm.$el.querySelector('span').textContent)).toEqual( - "This issue is confidential and locked. People without permission will never get a notification and won't be able to comment.", - ); + it('does not render information about confidential issue', () => { + expect(findConfidentialBlock().exists()).toBe(false); }); }); }); |