Commit 140ce338 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'himkp-jest-batch-comments' into 'master'

Migrate ee/spec/javascripts/batch_comments/ to Jest

See merge request gitlab-org/gitlab!31535
parents 25ddba8a 89781e30
...@@ -22,7 +22,7 @@ describe('Batch comments draft note component', () => { ...@@ -22,7 +22,7 @@ describe('Batch comments draft note component', () => {
localVue, localVue,
}); });
spyOn(wrapper.vm.$store, 'dispatch').and.stub(); jest.spyOn(wrapper.vm.$store, 'dispatch').mockImplementation();
}); });
afterEach(() => { afterEach(() => {
...@@ -91,7 +91,7 @@ describe('Batch comments draft note component', () => { ...@@ -91,7 +91,7 @@ describe('Batch comments draft note component', () => {
describe('deleteDraft', () => { describe('deleteDraft', () => {
it('dispatches deleteDraft', () => { it('dispatches deleteDraft', () => {
spyOn(window, 'confirm').and.callFake(() => true); jest.spyOn(window, 'confirm').mockImplementation(() => true);
const note = wrapper.find(NoteableNote); const note = wrapper.find(NoteableNote);
......
import Vue from 'vue'; import Vue from 'vue';
import DraftsCount from 'ee/batch_comments/components/drafts_count.vue'; import DraftsCount from 'ee/batch_comments/components/drafts_count.vue';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { createStore } from 'ee/batch_comments/stores'; import { createStore } from 'ee/batch_comments/stores';
describe('Batch comments drafts count component', () => { describe('Batch comments drafts count component', () => {
......
import Vue from 'vue'; import Vue from 'vue';
import PreviewItem from 'ee/batch_comments/components/preview_item.vue'; import PreviewItem from 'ee/batch_comments/components/preview_item.vue';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { createStore } from 'ee/batch_comments/stores'; import { createStore } from 'ee/batch_comments/stores';
import diffsModule from '~/diffs/store/modules'; import diffsModule from '~/diffs/store/modules';
import notesModule from '~/notes/stores/modules'; import notesModule from '~/notes/stores/modules';
...@@ -52,7 +52,7 @@ describe('Batch comments draft preview item component', () => { ...@@ -52,7 +52,7 @@ describe('Batch comments draft preview item component', () => {
it('scrolls to draft on click', () => { it('scrolls to draft on click', () => {
createComponent(); createComponent();
spyOn(vm.$store, 'dispatch').and.stub(); jest.spyOn(vm.$store, 'dispatch').mockImplementation();
vm.$el.click(); vm.$el.click();
......
import Vue from 'vue'; import Vue from 'vue';
import PublishButton from 'ee/batch_comments/components/publish_button.vue'; import PublishButton from 'ee/batch_comments/components/publish_button.vue';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { createStore } from 'ee/batch_comments/stores'; import { createStore } from 'ee/batch_comments/stores';
describe('Batch comments publish button component', () => { describe('Batch comments publish button component', () => {
...@@ -16,7 +16,7 @@ describe('Batch comments publish button component', () => { ...@@ -16,7 +16,7 @@ describe('Batch comments publish button component', () => {
vm = mountComponentWithStore(Component, { store, props: { shouldPublish: true } }); vm = mountComponentWithStore(Component, { store, props: { shouldPublish: true } });
spyOn(vm.$store, 'dispatch').and.stub(); jest.spyOn(vm.$store, 'dispatch').mockImplementation();
}); });
afterEach(() => { afterEach(() => {
......
import Vue from 'vue'; import Vue from 'vue';
import PreviewDropdown from 'ee/batch_comments/components/preview_dropdown.vue'; import PreviewDropdown from 'ee/batch_comments/components/preview_dropdown.vue';
import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import { createStore } from 'ee/mr_notes/stores'; import { createStore } from 'ee/mr_notes/stores';
import '~/behaviors/markdown/render_gfm'; import '~/behaviors/markdown/render_gfm';
import { createDraft } from '../mock_data'; import { createDraft } from '../mock_data';
...@@ -29,16 +29,16 @@ describe('Batch comments publish dropdown component', () => { ...@@ -29,16 +29,16 @@ describe('Batch comments publish dropdown component', () => {
it('toggles dropdown when clicking button', done => { it('toggles dropdown when clicking button', done => {
createComponent(); createComponent();
spyOn(vm.$store, 'dispatch').and.callThrough(); jest.spyOn(vm.$store, 'dispatch');
vm.$el.querySelector('.review-preview-dropdown-toggle').click(); vm.$el.querySelector('.review-preview-dropdown-toggle').click();
expect(vm.$store.dispatch).toHaveBeenCalledWith( expect(vm.$store.dispatch).toHaveBeenCalledWith(
'batchComments/toggleReviewDropdown', 'batchComments/toggleReviewDropdown',
jasmine.anything(), expect.anything(),
); );
setTimeout(() => { setImmediate(() => {
expect(vm.$el.classList).toContain('show'); expect(vm.$el.classList).toContain('show');
done(); done();
...@@ -50,7 +50,7 @@ describe('Batch comments publish dropdown component', () => { ...@@ -50,7 +50,7 @@ describe('Batch comments publish dropdown component', () => {
vm.$store.state.batchComments.showPreviewDropdown = true; vm.$store.state.batchComments.showPreviewDropdown = true;
spyOn(vm.$store, 'dispatch').and.stub(); jest.spyOn(vm.$store, 'dispatch').mockImplementation();
document.body.click(); document.body.click();
......
import { TEST_HOST } from 'spec/test_constants';
export const createDraft = () => ({
author: {
id: 1,
name: 'Test',
username: 'test',
state: 'active',
avatar_url: TEST_HOST,
},
current_user: { can_edit: true, can_award_emoji: false, can_resolve: false },
discussion_id: null,
file_hash: null,
file_path: null,
id: 1,
line_code: null,
merge_request_id: 1,
note: 'a',
note_html: '<p>Test</p>',
noteable_type: 'MergeRequest',
references: { users: [], commands: '' },
resolve_discussion: false,
isDraft: true,
position: null,
});
export default () => {};
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import testAction from 'spec/helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import * as actions from 'ee/batch_comments/stores/modules/batch_comments/actions'; import * as actions from 'ee/batch_comments/stores/modules/batch_comments/actions';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -31,7 +31,7 @@ describe('Batch comments store actions', () => { ...@@ -31,7 +31,7 @@ describe('Batch comments store actions', () => {
describe('saveDraft', () => { describe('saveDraft', () => {
it('dispatches saveNote on root', () => { it('dispatches saveNote on root', () => {
const dispatch = jasmine.createSpy(); const dispatch = jest.fn();
actions.saveDraft({ dispatch }, { id: 1 }); actions.saveDraft({ dispatch }, { id: 1 });
...@@ -109,7 +109,7 @@ describe('Batch comments store actions', () => { ...@@ -109,7 +109,7 @@ describe('Batch comments store actions', () => {
}); });
it('commits DELETE_DRAFT if no errors returned', done => { it('commits DELETE_DRAFT if no errors returned', done => {
const commit = jasmine.createSpy('commit'); const commit = jest.fn();
const context = { const context = {
getters, getters,
commit, commit,
...@@ -127,7 +127,7 @@ describe('Batch comments store actions', () => { ...@@ -127,7 +127,7 @@ describe('Batch comments store actions', () => {
}); });
it('does not commit DELETE_DRAFT if errors returned', done => { it('does not commit DELETE_DRAFT if errors returned', done => {
const commit = jasmine.createSpy('commit'); const commit = jest.fn();
const context = { const context = {
getters, getters,
commit, commit,
...@@ -156,7 +156,7 @@ describe('Batch comments store actions', () => { ...@@ -156,7 +156,7 @@ describe('Batch comments store actions', () => {
}); });
it('commits SET_BATCH_COMMENTS_DRAFTS with returned data', done => { it('commits SET_BATCH_COMMENTS_DRAFTS with returned data', done => {
const commit = jasmine.createSpy('commit'); const commit = jest.fn();
const context = { const context = {
getters, getters,
commit, commit,
...@@ -181,8 +181,8 @@ describe('Batch comments store actions', () => { ...@@ -181,8 +181,8 @@ describe('Batch comments store actions', () => {
let rootGetters; let rootGetters;
beforeEach(() => { beforeEach(() => {
dispatch = jasmine.createSpy('dispatch'); dispatch = jest.fn();
commit = jasmine.createSpy('commit'); commit = jest.fn();
getters = { getters = {
getNotesData: { draftsPublishPath: gl.TEST_HOST, discussionsPath: gl.TEST_HOST }, getNotesData: { draftsPublishPath: gl.TEST_HOST, discussionsPath: gl.TEST_HOST },
}; };
...@@ -195,10 +195,10 @@ describe('Batch comments store actions', () => { ...@@ -195,10 +195,10 @@ describe('Batch comments store actions', () => {
actions actions
.publishReview({ dispatch, commit, getters, rootGetters }) .publishReview({ dispatch, commit, getters, rootGetters })
.then(() => { .then(() => {
expect(commit.calls.argsFor(0)).toEqual(['REQUEST_PUBLISH_REVIEW']); expect(commit.mock.calls[0]).toEqual(['REQUEST_PUBLISH_REVIEW']);
expect(commit.calls.argsFor(1)).toEqual(['RECEIVE_PUBLISH_REVIEW_SUCCESS']); expect(commit.mock.calls[1]).toEqual(['RECEIVE_PUBLISH_REVIEW_SUCCESS']);
expect(dispatch.calls.argsFor(0)).toEqual(['updateDiscussionsAfterPublish']); expect(dispatch.mock.calls[0]).toEqual(['updateDiscussionsAfterPublish']);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -210,8 +210,8 @@ describe('Batch comments store actions', () => { ...@@ -210,8 +210,8 @@ describe('Batch comments store actions', () => {
actions actions
.publishReview({ dispatch, commit, getters, rootGetters }) .publishReview({ dispatch, commit, getters, rootGetters })
.then(() => { .then(() => {
expect(commit.calls.argsFor(0)).toEqual(['REQUEST_PUBLISH_REVIEW']); expect(commit.mock.calls[0]).toEqual(['REQUEST_PUBLISH_REVIEW']);
expect(commit.calls.argsFor(1)).toEqual(['RECEIVE_PUBLISH_REVIEW_ERROR']); expect(commit.mock.calls[1]).toEqual(['RECEIVE_PUBLISH_REVIEW_ERROR']);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -223,14 +223,14 @@ describe('Batch comments store actions', () => { ...@@ -223,14 +223,14 @@ describe('Batch comments store actions', () => {
const getters = { const getters = {
getNotesData: { draftsDiscardPath: gl.TEST_HOST }, getNotesData: { draftsDiscardPath: gl.TEST_HOST },
}; };
const commit = jasmine.createSpy('commit'); const commit = jest.fn();
mock.onAny().reply(200); mock.onAny().reply(200);
actions actions
.discardReview({ getters, commit }) .discardReview({ getters, commit })
.then(() => { .then(() => {
expect(commit.calls.argsFor(0)).toEqual(['REQUEST_DISCARD_REVIEW']); expect(commit.mock.calls[0]).toEqual(['REQUEST_DISCARD_REVIEW']);
expect(commit.calls.argsFor(1)).toEqual(['RECEIVE_DISCARD_REVIEW_SUCCESS']); expect(commit.mock.calls[1]).toEqual(['RECEIVE_DISCARD_REVIEW_SUCCESS']);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -240,14 +240,14 @@ describe('Batch comments store actions', () => { ...@@ -240,14 +240,14 @@ describe('Batch comments store actions', () => {
const getters = { const getters = {
getNotesData: { draftsDiscardPath: gl.TEST_HOST }, getNotesData: { draftsDiscardPath: gl.TEST_HOST },
}; };
const commit = jasmine.createSpy('commit'); const commit = jest.fn();
mock.onAny().reply(500); mock.onAny().reply(500);
actions actions
.discardReview({ getters, commit }) .discardReview({ getters, commit })
.then(() => { .then(() => {
expect(commit.calls.argsFor(0)).toEqual(['REQUEST_DISCARD_REVIEW']); expect(commit.mock.calls[0]).toEqual(['REQUEST_DISCARD_REVIEW']);
expect(commit.calls.argsFor(1)).toEqual(['RECEIVE_DISCARD_REVIEW_ERROR']); expect(commit.mock.calls[1]).toEqual(['RECEIVE_DISCARD_REVIEW_ERROR']);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -266,7 +266,7 @@ describe('Batch comments store actions', () => { ...@@ -266,7 +266,7 @@ describe('Batch comments store actions', () => {
}); });
it('commits RECEIVE_DRAFT_UPDATE_SUCCESS with returned data', done => { it('commits RECEIVE_DRAFT_UPDATE_SUCCESS with returned data', done => {
const commit = jasmine.createSpy('commit'); const commit = jest.fn();
const context = { const context = {
getters, getters,
commit, commit,
...@@ -284,12 +284,12 @@ describe('Batch comments store actions', () => { ...@@ -284,12 +284,12 @@ describe('Batch comments store actions', () => {
}); });
it('calls passed callback', done => { it('calls passed callback', done => {
const commit = jasmine.createSpy('commit'); const commit = jest.fn();
const context = { const context = {
getters, getters,
commit, commit,
}; };
const callback = jasmine.createSpy('callback'); const callback = jest.fn();
res = { id: 1 }; res = { id: 1 };
mock.onAny().reply(200, res); mock.onAny().reply(200, res);
...@@ -383,12 +383,12 @@ describe('Batch comments store actions', () => { ...@@ -383,12 +383,12 @@ describe('Batch comments store actions', () => {
beforeEach(() => { beforeEach(() => {
window.mrTabs = { window.mrTabs = {
currentAction: 'notes', currentAction: 'notes',
tabShown: jasmine.createSpy('tabShown'), tabShown: jest.fn(),
}; };
}); });
it('scrolls to draft item', () => { it('scrolls to draft item', () => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn();
const rootGetters = { const rootGetters = {
getDiscussion: () => ({ getDiscussion: () => ({
id: '1', id: '1',
...@@ -402,9 +402,9 @@ describe('Batch comments store actions', () => { ...@@ -402,9 +402,9 @@ describe('Batch comments store actions', () => {
actions.scrollToDraft({ dispatch, rootGetters }, draft); actions.scrollToDraft({ dispatch, rootGetters }, draft);
expect(dispatch.calls.argsFor(0)).toEqual(['closeReviewDropdown']); expect(dispatch.mock.calls[0]).toEqual(['closeReviewDropdown']);
expect(dispatch.calls.argsFor(1)).toEqual([ expect(dispatch.mock.calls[1]).toEqual([
'expandDiscussion', 'expandDiscussion',
{ discussionId: '1' }, { discussionId: '1' },
{ root: true }, { root: true },
......
// eslint-disable-next-line import/prefer-default-export // No new code should be added to this file. Instead, modify the
export const createDraft = () => ({ // file this one re-exports from. For more detail about why, see:
author: { // https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/31349
id: 1,
name: 'Test', export * from '../../frontend/batch_comments/mock_data';
username: 'test',
state: 'active',
avatar_url: gl.TEST_HOST,
},
current_user: { can_edit: true, can_award_emoji: false, can_resolve: false },
discussion_id: null,
file_hash: null,
file_path: null,
id: 1,
line_code: null,
merge_request_id: 1,
note: 'a',
note_html: '<p>Test</p>',
noteable_type: 'MergeRequest',
references: { users: [], commands: '' },
resolve_discussion: false,
isDraft: true,
position: null,
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment