diff options
Diffstat (limited to 'spec/frontend/notes')
-rw-r--r-- | spec/frontend/notes/components/comment_form_spec.js | 14 | ||||
-rw-r--r-- | spec/frontend/notes/components/discussion_notes_spec.js | 14 | ||||
-rw-r--r-- | spec/frontend/notes/components/noteable_note_spec.js | 7 | ||||
-rw-r--r-- | spec/frontend/notes/stores/actions_spec.js | 75 |
4 files changed, 58 insertions, 52 deletions
diff --git a/spec/frontend/notes/components/comment_form_spec.js b/spec/frontend/notes/components/comment_form_spec.js index 537622b7918..bb79b43205b 100644 --- a/spec/frontend/notes/components/comment_form_spec.js +++ b/spec/frontend/notes/components/comment_form_spec.js @@ -7,7 +7,7 @@ import Vuex from 'vuex'; import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import batchComments from '~/batch_comments/stores/modules/batch_comments'; import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests'; -import { deprecatedCreateFlash as flash } from '~/flash'; +import createFlash from '~/flash'; import axios from '~/lib/utils/axios_utils'; import CommentForm from '~/notes/components/comment_form.vue'; import * as constants from '~/notes/constants'; @@ -464,9 +464,9 @@ describe('issue_comment_form component', () => { await wrapper.vm.$nextTick; await wrapper.vm.$nextTick; - expect(flash).toHaveBeenCalledWith( - `Something went wrong while closing the ${type}. Please try again later.`, - ); + expect(createFlash).toHaveBeenCalledWith({ + message: `Something went wrong while closing the ${type}. Please try again later.`, + }); }); }); @@ -500,9 +500,9 @@ describe('issue_comment_form component', () => { await wrapper.vm.$nextTick; await wrapper.vm.$nextTick; - expect(flash).toHaveBeenCalledWith( - `Something went wrong while reopening the ${type}. Please try again later.`, - ); + expect(createFlash).toHaveBeenCalledWith({ + message: `Something went wrong while reopening the ${type}. Please try again later.`, + }); }); }); diff --git a/spec/frontend/notes/components/discussion_notes_spec.js b/spec/frontend/notes/components/discussion_notes_spec.js index cd24b9afbdf..59ac75f00e6 100644 --- a/spec/frontend/notes/components/discussion_notes_spec.js +++ b/spec/frontend/notes/components/discussion_notes_spec.js @@ -1,5 +1,5 @@ import { getByRole } from '@testing-library/dom'; -import { shallowMount } from '@vue/test-utils'; +import { shallowMount, mount } from '@vue/test-utils'; import '~/behaviors/markdown/render_gfm'; import DiscussionNotes from '~/notes/components/discussion_notes.vue'; import NoteableNote from '~/notes/components/noteable_note.vue'; @@ -23,8 +23,8 @@ describe('DiscussionNotes', () => { let wrapper; const getList = () => getByRole(wrapper.element, 'list'); - const createComponent = (props) => { - wrapper = shallowMount(DiscussionNotes, { + const createComponent = (props, mountingMethod = shallowMount) => { + wrapper = mountingMethod(DiscussionNotes, { store, propsData: { discussion: discussionMock, @@ -33,7 +33,11 @@ describe('DiscussionNotes', () => { ...props, }, scopedSlots: { - footer: '<p slot-scope="{ showReplies }">showReplies:{{showReplies}}</p>', + footer: ` + <template #default="{ showReplies }"> + <p>showReplies:{{ showReplies }}</p>, + </template> + `, }, slots: { 'avatar-badge': '<span class="avatar-badge-slot-content" />', @@ -112,7 +116,7 @@ describe('DiscussionNotes', () => { }); it('passes down avatar-badge slot content', () => { - createComponent(); + createComponent({}, mount); expect(wrapper.find('.avatar-badge-slot-content').exists()).toBe(true); }); }); diff --git a/spec/frontend/notes/components/noteable_note_spec.js b/spec/frontend/notes/components/noteable_note_spec.js index 7444c441e06..f217dfd2e48 100644 --- a/spec/frontend/notes/components/noteable_note_spec.js +++ b/spec/frontend/notes/components/noteable_note_spec.js @@ -1,5 +1,4 @@ import { mount } from '@vue/test-utils'; -import { escape } from 'lodash'; import Vue from 'vue'; import Vuex from 'vuex'; @@ -263,7 +262,9 @@ describe('issue_note', () => { await waitForPromises(); expect(alertSpy).not.toHaveBeenCalled(); - expect(wrapper.vm.note.note_html).toBe(escape(noteBody)); + expect(wrapper.vm.note.note_html).toBe( + '<p><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"></p>\n', + ); }); }); @@ -291,7 +292,7 @@ describe('issue_note', () => { await wrapper.vm.$nextTick(); let noteBodyProps = noteBody.props(); - expect(noteBodyProps.note.note_html).toBe(updatedText); + expect(noteBodyProps.note.note_html).toBe(`<p>${updatedText}</p>\n`); noteBody.vm.$emit('cancelForm'); await wrapper.vm.$nextTick(); diff --git a/spec/frontend/notes/stores/actions_spec.js b/spec/frontend/notes/stores/actions_spec.js index 7eef2017dfb..2ff65d3f47e 100644 --- a/spec/frontend/notes/stores/actions_spec.js +++ b/spec/frontend/notes/stores/actions_spec.js @@ -2,7 +2,7 @@ import AxiosMockAdapter from 'axios-mock-adapter'; import testAction from 'helpers/vuex_action_helper'; import { TEST_HOST } from 'spec/test_constants'; import Api from '~/api'; -import { deprecatedCreateFlash as Flash } from '~/flash'; +import createFlash from '~/flash'; import { EVENT_ISSUABLE_VUE_APP_CHANGE } from '~/issuable/constants'; import axios from '~/lib/utils/axios_utils'; import * as notesConstants from '~/notes/constants'; @@ -33,10 +33,7 @@ jest.mock('~/flash', () => { }; }); - return { - createFlash: flash, - deprecatedCreateFlash: flash, - }; + return flash; }); describe('Actions Notes Store', () => { @@ -348,13 +345,13 @@ describe('Actions Notes Store', () => { await startPolling(); expect(axiosMock.history.get).toHaveLength(1); - expect(Flash).not.toHaveBeenCalled(); + expect(createFlash).not.toHaveBeenCalled(); await advanceXMoreIntervals(1); expect(axiosMock.history.get).toHaveLength(2); - expect(Flash).toHaveBeenCalled(); - expect(Flash).toHaveBeenCalledTimes(1); + expect(createFlash).toHaveBeenCalled(); + expect(createFlash).toHaveBeenCalledTimes(1); }); it('resets the failure counter on success', async () => { @@ -375,14 +372,14 @@ describe('Actions Notes Store', () => { await advanceXMoreIntervals(1); // Failure #2 // That was the first failure AFTER a success, so we should NOT see the error displayed - expect(Flash).not.toHaveBeenCalled(); + expect(createFlash).not.toHaveBeenCalled(); // Now we'll allow another failure await advanceXMoreIntervals(1); // Failure #3 // Since this is the second failure in a row, the error should happen - expect(Flash).toHaveBeenCalled(); - expect(Flash).toHaveBeenCalledTimes(1); + expect(createFlash).toHaveBeenCalled(); + expect(createFlash).toHaveBeenCalledTimes(1); }); it('hides the error display if it exists on success', async () => { @@ -393,8 +390,8 @@ describe('Actions Notes Store', () => { await advanceXMoreIntervals(2); // After two errors, the error should be displayed - expect(Flash).toHaveBeenCalled(); - expect(Flash).toHaveBeenCalledTimes(1); + expect(createFlash).toHaveBeenCalled(); + expect(createFlash).toHaveBeenCalledTimes(1); axiosMock.reset(); successMock(); @@ -906,7 +903,7 @@ describe('Actions Notes Store', () => { .then(() => done.fail('Expected error to be thrown!')) .catch((err) => { expect(err).toBe(error); - expect(Flash).not.toHaveBeenCalled(); + expect(createFlash).not.toHaveBeenCalled(); }) .then(done) .catch(done.fail); @@ -928,11 +925,10 @@ describe('Actions Notes Store', () => { ) .then((resp) => { expect(resp.hasFlash).toBe(true); - expect(Flash).toHaveBeenCalledWith( - 'Your comment could not be submitted because something went wrong', - 'alert', - flashContainer, - ); + expect(createFlash).toHaveBeenCalledWith({ + message: 'Your comment could not be submitted because something went wrong', + parent: flashContainer, + }); }) .catch(() => done.fail('Expected success response!')) .then(done) @@ -954,7 +950,7 @@ describe('Actions Notes Store', () => { ) .then((data) => { expect(data).toBe(res); - expect(Flash).not.toHaveBeenCalled(); + expect(createFlash).not.toHaveBeenCalled(); }) .then(done) .catch(done.fail); @@ -997,7 +993,7 @@ describe('Actions Notes Store', () => { ['resolveDiscussion', { discussionId }], ['restartPolling'], ]); - expect(Flash).not.toHaveBeenCalled(); + expect(createFlash).not.toHaveBeenCalled(); }); }); @@ -1012,7 +1008,10 @@ describe('Actions Notes Store', () => { [mutationTypes.SET_RESOLVING_DISCUSSION, false], ]); expect(dispatch.mock.calls).toEqual([['stopPolling'], ['restartPolling']]); - expect(Flash).toHaveBeenCalledWith(TEST_ERROR_MESSAGE, 'alert', flashContainer); + expect(createFlash).toHaveBeenCalledWith({ + message: TEST_ERROR_MESSAGE, + parent: flashContainer, + }); }); }); @@ -1027,11 +1026,10 @@ describe('Actions Notes Store', () => { [mutationTypes.SET_RESOLVING_DISCUSSION, false], ]); expect(dispatch.mock.calls).toEqual([['stopPolling'], ['restartPolling']]); - expect(Flash).toHaveBeenCalledWith( - 'Something went wrong while applying the suggestion. Please try again.', - 'alert', - flashContainer, - ); + expect(createFlash).toHaveBeenCalledWith({ + message: 'Something went wrong while applying the suggestion. Please try again.', + parent: flashContainer, + }); }); }); @@ -1039,7 +1037,7 @@ describe('Actions Notes Store', () => { dispatch.mockReturnValue(Promise.reject()); testSubmitSuggestion(done, () => { - expect(Flash).not.toHaveBeenCalled(); + expect(createFlash).not.toHaveBeenCalled(); }); }); }); @@ -1083,7 +1081,7 @@ describe('Actions Notes Store', () => { ['restartPolling'], ]); - expect(Flash).not.toHaveBeenCalled(); + expect(createFlash).not.toHaveBeenCalled(); }); }); @@ -1101,7 +1099,10 @@ describe('Actions Notes Store', () => { ]); expect(dispatch.mock.calls).toEqual([['stopPolling'], ['restartPolling']]); - expect(Flash).toHaveBeenCalledWith(TEST_ERROR_MESSAGE, 'alert', flashContainer); + expect(createFlash).toHaveBeenCalledWith({ + message: TEST_ERROR_MESSAGE, + parent: flashContainer, + }); }); }); @@ -1119,11 +1120,11 @@ describe('Actions Notes Store', () => { ]); expect(dispatch.mock.calls).toEqual([['stopPolling'], ['restartPolling']]); - expect(Flash).toHaveBeenCalledWith( - 'Something went wrong while applying the batch of suggestions. Please try again.', - 'alert', - flashContainer, - ); + expect(createFlash).toHaveBeenCalledWith({ + message: + 'Something went wrong while applying the batch of suggestions. Please try again.', + parent: flashContainer, + }); }); }); @@ -1139,7 +1140,7 @@ describe('Actions Notes Store', () => { [mutationTypes.SET_RESOLVING_DISCUSSION, false], ]); - expect(Flash).not.toHaveBeenCalled(); + expect(createFlash).not.toHaveBeenCalled(); }); }); }); @@ -1283,7 +1284,7 @@ describe('Actions Notes Store', () => { ) .then(() => done.fail('Expected error to be thrown')) .catch(() => { - expect(Flash).toHaveBeenCalled(); + expect(createFlash).toHaveBeenCalled(); done(); }); }); |