diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/frontend/vue_shared/components/notes/noteable_warning_spec.js | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/frontend/vue_shared/components/notes/noteable_warning_spec.js')
-rw-r--r-- | spec/frontend/vue_shared/components/notes/noteable_warning_spec.js | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/spec/frontend/vue_shared/components/notes/noteable_warning_spec.js b/spec/frontend/vue_shared/components/notes/noteable_warning_spec.js new file mode 100644 index 00000000000..ae8c9a0928e --- /dev/null +++ b/spec/frontend/vue_shared/components/notes/noteable_warning_spec.js @@ -0,0 +1,196 @@ +import { shallowMount } from '@vue/test-utils'; +import NoteableWarning from '~/vue_shared/components/notes/noteable_warning.vue'; +import Icon from '~/vue_shared/components/icon.vue'; + +describe('Issue Warning Component', () => { + let wrapper; + + const findIcon = (w = wrapper) => w.find(Icon); + const findLockedBlock = (w = wrapper) => w.find({ ref: 'locked' }); + const findConfidentialBlock = (w = wrapper) => w.find({ ref: 'confidential' }); + const findLockedAndConfidentialBlock = (w = wrapper) => w.find({ ref: 'lockedAndConfidential' }); + + const createComponent = props => + shallowMount(NoteableWarning, { + propsData: { + ...props, + }, + }); + + afterEach(() => { + if (wrapper) { + wrapper.destroy(); + wrapper = null; + } + }); + + describe('when issue is locked but not confidential', () => { + beforeEach(() => { + wrapper = createComponent({ + isLocked: true, + lockedNoteableDocsPath: '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('when noteable is confidential but not locked', () => { + beforeEach(() => { + wrapper = createComponent({ + isLocked: false, + isConfidential: true, + confidentialNoteableDocsPath: 'confidential-path', + }); + }); + + it('renders information about confidential issue', async () => { + expect(findConfidentialBlock().exists()).toBe(true); + expect(findConfidentialBlock().element).toMatchSnapshot(); + + await wrapper.vm.$nextTick(); + expect(findConfidentialBlock(wrapper).text()).toContain('This is a confidential issue.'); + }); + + it('renders warning icon', () => { + expect(wrapper.find(Icon).exists()).toBe(true); + }); + + it('does not render information about locked noteable', () => { + expect(findLockedBlock().exists()).toBe(false); + }); + + it('does not render information about locked and confidential noteable', () => { + expect(findLockedAndConfidentialBlock().exists()).toBe(false); + }); + }); + + describe('when noteable is locked and confidential', () => { + beforeEach(() => { + wrapper = createComponent({ + isLocked: true, + isConfidential: true, + }); + }); + + it('renders information about locked and confidential noteable', () => { + 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 noteable', () => { + expect(findLockedBlock().exists()).toBe(false); + }); + + it('does not render information about confidential noteable', () => { + expect(findConfidentialBlock().exists()).toBe(false); + }); + }); + + describe('when noteableType prop is defined', () => { + let wrapperLocked; + let wrapperConfidential; + let wrapperLockedAndConfidential; + + beforeEach(() => { + wrapperLocked = createComponent({ + isLocked: true, + isConfidential: false, + }); + wrapperConfidential = createComponent({ + isLocked: false, + isConfidential: true, + }); + wrapperLockedAndConfidential = createComponent({ + isLocked: true, + isConfidential: true, + }); + }); + + afterEach(() => { + wrapperLocked.destroy(); + wrapperConfidential.destroy(); + wrapperLockedAndConfidential.destroy(); + }); + + it('renders confidential & locked messages with noteable "issue"', () => { + expect(findLockedBlock(wrapperLocked).text()).toContain('This issue is locked.'); + expect(findConfidentialBlock(wrapperConfidential).text()).toContain( + 'This is a confidential issue.', + ); + expect(findLockedAndConfidentialBlock(wrapperLockedAndConfidential).text()).toContain( + 'This issue is confidential and locked.', + ); + }); + + it('renders confidential & locked messages with noteable "epic"', async () => { + wrapperLocked.setProps({ + noteableType: 'Epic', + }); + wrapperConfidential.setProps({ + noteableType: 'Epic', + }); + wrapperLockedAndConfidential.setProps({ + noteableType: 'Epic', + }); + + await wrapperLocked.vm.$nextTick(); + expect(findLockedBlock(wrapperLocked).text()).toContain('This epic is locked.'); + + await wrapperConfidential.vm.$nextTick(); + expect(findConfidentialBlock(wrapperConfidential).text()).toContain( + 'This is a confidential epic.', + ); + + await wrapperLockedAndConfidential.vm.$nextTick(); + expect(findLockedAndConfidentialBlock(wrapperLockedAndConfidential).text()).toContain( + 'This epic is confidential and locked.', + ); + }); + + it('renders confidential & locked messages with noteable "merge request"', async () => { + wrapperLocked.setProps({ + noteableType: 'MergeRequest', + }); + wrapperConfidential.setProps({ + noteableType: 'MergeRequest', + }); + wrapperLockedAndConfidential.setProps({ + noteableType: 'MergeRequest', + }); + + await wrapperLocked.vm.$nextTick(); + expect(findLockedBlock(wrapperLocked).text()).toContain('This merge request is locked.'); + + await wrapperConfidential.vm.$nextTick(); + expect(findConfidentialBlock(wrapperConfidential).text()).toContain( + 'This is a confidential merge request.', + ); + + await wrapperLockedAndConfidential.vm.$nextTick(); + expect(findLockedAndConfidentialBlock(wrapperLockedAndConfidential).text()).toContain( + 'This merge request is confidential and locked.', + ); + }); + }); +}); |