diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-15 09:09:28 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-15 09:09:28 +0000 |
commit | 74e6480896d7fd478930426460021883ba3b83a4 (patch) | |
tree | a009740bef901aed261355507cb5869f4be4607e /spec/frontend/batch_comments | |
parent | e75da32ffd5360a31279e28ecd6060e86a6092b3 (diff) | |
download | gitlab-ce-74e6480896d7fd478930426460021883ba3b83a4.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/batch_comments')
-rw-r--r-- | spec/frontend/batch_comments/components/submit_dropdown_spec.js | 69 | ||||
-rw-r--r-- | spec/frontend/batch_comments/stores/modules/batch_comments/actions_spec.js | 10 |
2 files changed, 79 insertions, 0 deletions
diff --git a/spec/frontend/batch_comments/components/submit_dropdown_spec.js b/spec/frontend/batch_comments/components/submit_dropdown_spec.js new file mode 100644 index 00000000000..4f5ff797230 --- /dev/null +++ b/spec/frontend/batch_comments/components/submit_dropdown_spec.js @@ -0,0 +1,69 @@ +import Vue from 'vue'; +import Vuex from 'vuex'; +import { mountExtended } from 'helpers/vue_test_utils_helper'; +import SubmitDropdown from '~/batch_comments/components/submit_dropdown.vue'; + +Vue.use(Vuex); + +let wrapper; +let publishReview; + +function factory() { + publishReview = jest.fn(); + + const store = new Vuex.Store({ + getters: { + getNotesData: () => ({ + markdownDocsPath: '/markdown/docs', + quickActionsDocsPath: '/quickactions/docs', + }), + getNoteableData: () => ({ id: 1, preview_note_path: '/preview' }), + noteableType: () => 'merge_request', + }, + modules: { + batchComments: { + namespaced: true, + actions: { + publishReview, + }, + }, + }, + }); + wrapper = mountExtended(SubmitDropdown, { + store, + }); +} + +const findCommentTextarea = () => wrapper.findByTestId('comment-textarea'); +const findSubmitButton = () => wrapper.findByTestId('submit-review-button'); +const findForm = () => wrapper.findByTestId('submit-gl-form'); + +describe('Batch comments submit dropdown', () => { + afterEach(() => { + wrapper.destroy(); + }); + + it('calls publishReview with note data', async () => { + factory(); + + findCommentTextarea().setValue('Hello world'); + + await findForm().vm.$emit('submit', { preventDefault: jest.fn() }); + + expect(publishReview).toHaveBeenCalledWith(expect.anything(), { + noteable_type: 'merge_request', + noteable_id: 1, + note: 'Hello world', + }); + }); + + it('sets submit dropdown to loading', async () => { + factory(); + + findCommentTextarea().setValue('Hello world'); + + await findForm().vm.$emit('submit', { preventDefault: jest.fn() }); + + expect(findSubmitButton().props('loading')).toBe(true); + }); +}); diff --git a/spec/frontend/batch_comments/stores/modules/batch_comments/actions_spec.js b/spec/frontend/batch_comments/stores/modules/batch_comments/actions_spec.js index e9535d8cc12..172b510645d 100644 --- a/spec/frontend/batch_comments/stores/modules/batch_comments/actions_spec.js +++ b/spec/frontend/batch_comments/stores/modules/batch_comments/actions_spec.js @@ -179,6 +179,16 @@ describe('Batch comments store actions', () => { }); }); + it('calls service with notes data', () => { + jest.spyOn(axios, 'post'); + + return actions + .publishReview({ dispatch, commit, getters, rootGetters }, { note: 'test' }) + .then(() => { + expect(axios.post.mock.calls[0]).toEqual(['http://test.host', { note: 'test' }]); + }); + }); + it('dispatches error commits', () => { mock.onAny().reply(500); |