diff options
Diffstat (limited to 'spec/frontend/sidebar/confidential/edit_form_buttons_spec.js')
-rw-r--r-- | spec/frontend/sidebar/confidential/edit_form_buttons_spec.js | 108 |
1 files changed, 48 insertions, 60 deletions
diff --git a/spec/frontend/sidebar/confidential/edit_form_buttons_spec.js b/spec/frontend/sidebar/confidential/edit_form_buttons_spec.js index 15493d3087f..2f11c6a07c2 100644 --- a/spec/frontend/sidebar/confidential/edit_form_buttons_spec.js +++ b/spec/frontend/sidebar/confidential/edit_form_buttons_spec.js @@ -1,10 +1,10 @@ import { shallowMount } from '@vue/test-utils'; import { GlLoadingIcon } from '@gitlab/ui'; +import waitForPromises from 'helpers/wait_for_promises'; import EditFormButtons from '~/sidebar/components/confidential/edit_form_buttons.vue'; import eventHub from '~/sidebar/event_hub'; import createStore from '~/notes/stores'; -import waitForPromises from 'helpers/wait_for_promises'; -import flash from '~/flash'; +import { deprecatedCreateFlash as flash } from '~/flash'; jest.mock('~/sidebar/event_hub', () => ({ $emit: jest.fn() })); jest.mock('~/flash'); @@ -14,12 +14,7 @@ describe('Edit Form Buttons', () => { let store; const findConfidentialToggle = () => wrapper.find('[data-testid="confidential-toggle"]'); - const createComponent = ({ - props = {}, - data = {}, - confidentialApolloSidebar = false, - resolved = true, - }) => { + const createComponent = ({ props = {}, data = {}, resolved = true }) => { store = createStore(); if (resolved) { jest.spyOn(store, 'dispatch').mockResolvedValue(); @@ -38,11 +33,6 @@ describe('Edit Form Buttons', () => { ...data, }; }, - provide: { - glFeatures: { - confidentialApolloSidebar, - }, - }, store, }); }; @@ -54,9 +44,11 @@ describe('Edit Form Buttons', () => { describe('when isLoading', () => { beforeEach(() => { - createComponent({}); - - wrapper.vm.$store.state.noteableData.confidential = false; + createComponent({ + props: { + confidential: false, + }, + }); }); it('renders "Applying" in the toggle button', () => { @@ -78,6 +70,9 @@ describe('Edit Form Buttons', () => { data: { isLoading: false, }, + props: { + confidential: false, + }, }); expect(findConfidentialToggle().text()).toBe('Turn On'); @@ -90,70 +85,63 @@ describe('Edit Form Buttons', () => { data: { isLoading: false, }, + props: { + confidential: true, + }, }); - - wrapper.vm.$store.state.noteableData.confidential = true; }); it('renders on or off text based on confidentiality', () => { expect(findConfidentialToggle().text()).toBe('Turn Off'); }); - - describe('when clicking on the confidential toggle', () => { - it('emits updateConfidentialAttribute', () => { - findConfidentialToggle().trigger('click'); - - expect(eventHub.$emit).toHaveBeenCalledWith('updateConfidentialAttribute'); - }); - }); }); - describe('when confidentialApolloSidebar is turned on', () => { - const isConfidential = true; + describe('when succeeds', () => { + beforeEach(() => { + createComponent({ data: { isLoading: false }, props: { confidential: true } }); + findConfidentialToggle().trigger('click'); + }); - describe('when succeeds', () => { - beforeEach(() => { - createComponent({ data: { isLoading: false }, confidentialApolloSidebar: true }); - wrapper.vm.$store.state.noteableData.confidential = isConfidential; - findConfidentialToggle().trigger('click'); + it('dispatches the correct action', () => { + expect(store.dispatch).toHaveBeenCalledWith('updateConfidentialityOnIssuable', { + confidential: false, + fullPath: '', }); + }); - it('dispatches the correct action', () => { - expect(store.dispatch).toHaveBeenCalledWith('updateConfidentialityOnIssue', { - confidential: !isConfidential, - fullPath: '', - }); + it('resets loading', () => { + return waitForPromises().then(() => { + expect(wrapper.find(GlLoadingIcon).exists()).toBe(false); }); + }); - it('resets loading', () => { - return waitForPromises().then(() => { - expect(wrapper.find(GlLoadingIcon).exists()).toBe(false); - }); + it('emits close form', () => { + return waitForPromises().then(() => { + expect(eventHub.$emit).toHaveBeenCalledWith('closeConfidentialityForm'); }); + }); - it('emits close form', () => { - return waitForPromises().then(() => { - expect(eventHub.$emit).toHaveBeenCalledWith('closeConfidentialityForm'); - }); + it('emits updateOnConfidentiality event', () => { + return waitForPromises().then(() => { + expect(eventHub.$emit).toHaveBeenCalledWith('updateIssuableConfidentiality', false); }); }); + }); - describe('when fails', () => { - beforeEach(() => { - createComponent({ - data: { isLoading: false }, - confidentialApolloSidebar: true, - resolved: false, - }); - wrapper.vm.$store.state.noteableData.confidential = isConfidential; - findConfidentialToggle().trigger('click'); + describe('when fails', () => { + beforeEach(() => { + createComponent({ + data: { isLoading: false }, + props: { confidential: true }, + resolved: false, }); + findConfidentialToggle().trigger('click'); + }); - it('calls flash with the correct message', () => { - expect(flash).toHaveBeenCalledWith( - 'Something went wrong trying to change the confidentiality of this issue', - ); - }); + it('calls flash with the correct message', () => { + expect(flash).toHaveBeenCalledWith( + 'Something went wrong trying to change the confidentiality of this issue', + ); }); }); }); |