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', () => {
localVue,
});
spyOn(wrapper.vm.$store, 'dispatch').and.stub();
jest.spyOn(wrapper.vm.$store, 'dispatch').mockImplementation();
});
afterEach(() => {
......@@ -91,7 +91,7 @@ describe('Batch comments draft note component', () => {
describe('deleteDraft', () => {
it('dispatches deleteDraft', () => {
spyOn(window, 'confirm').and.callFake(() => true);
jest.spyOn(window, 'confirm').mockImplementation(() => true);
const note = wrapper.find(NoteableNote);
......
import Vue from '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';
describe('Batch comments drafts count component', () => {
......
import Vue from '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 diffsModule from '~/diffs/store/modules';
import notesModule from '~/notes/stores/modules';
......@@ -52,7 +52,7 @@ describe('Batch comments draft preview item component', () => {
it('scrolls to draft on click', () => {
createComponent();
spyOn(vm.$store, 'dispatch').and.stub();
jest.spyOn(vm.$store, 'dispatch').mockImplementation();
vm.$el.click();
......
import Vue from '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';
describe('Batch comments publish button component', () => {
......@@ -16,7 +16,7 @@ describe('Batch comments publish button component', () => {
vm = mountComponentWithStore(Component, { store, props: { shouldPublish: true } });
spyOn(vm.$store, 'dispatch').and.stub();
jest.spyOn(vm.$store, 'dispatch').mockImplementation();
});
afterEach(() => {
......
import Vue from '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 '~/behaviors/markdown/render_gfm';
import { createDraft } from '../mock_data';
......@@ -29,16 +29,16 @@ describe('Batch comments publish dropdown component', () => {
it('toggles dropdown when clicking button', done => {
createComponent();
spyOn(vm.$store, 'dispatch').and.callThrough();
jest.spyOn(vm.$store, 'dispatch');
vm.$el.querySelector('.review-preview-dropdown-toggle').click();
expect(vm.$store.dispatch).toHaveBeenCalledWith(
'batchComments/toggleReviewDropdown',
jasmine.anything(),
expect.anything(),
);
setTimeout(() => {
setImmediate(() => {
expect(vm.$el.classList).toContain('show');
done();
......@@ -50,7 +50,7 @@ describe('Batch comments publish dropdown component', () => {
vm.$store.state.batchComments.showPreviewDropdown = true;
spyOn(vm.$store, 'dispatch').and.stub();
jest.spyOn(vm.$store, 'dispatch').mockImplementation();
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 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 axios from '~/lib/utils/axios_utils';
......@@ -31,7 +31,7 @@ describe('Batch comments store actions', () => {
describe('saveDraft', () => {
it('dispatches saveNote on root', () => {
const dispatch = jasmine.createSpy();
const dispatch = jest.fn();
actions.saveDraft({ dispatch }, { id: 1 });
......@@ -109,7 +109,7 @@ describe('Batch comments store actions', () => {
});
it('commits DELETE_DRAFT if no errors returned', done => {
const commit = jasmine.createSpy('commit');
const commit = jest.fn();
const context = {
getters,
commit,
......@@ -127,7 +127,7 @@ describe('Batch comments store actions', () => {
});
it('does not commit DELETE_DRAFT if errors returned', done => {
const commit = jasmine.createSpy('commit');
const commit = jest.fn();
const context = {
getters,
commit,
......@@ -156,7 +156,7 @@ describe('Batch comments store actions', () => {
});
it('commits SET_BATCH_COMMENTS_DRAFTS with returned data', done => {
const commit = jasmine.createSpy('commit');
const commit = jest.fn();
const context = {
getters,
commit,
......@@ -181,8 +181,8 @@ describe('Batch comments store actions', () => {
let rootGetters;
beforeEach(() => {
dispatch = jasmine.createSpy('dispatch');
commit = jasmine.createSpy('commit');
dispatch = jest.fn();
commit = jest.fn();
getters = {
getNotesData: { draftsPublishPath: gl.TEST_HOST, discussionsPath: gl.TEST_HOST },
};
......@@ -195,10 +195,10 @@ describe('Batch comments store actions', () => {
actions
.publishReview({ dispatch, commit, getters, rootGetters })
.then(() => {
expect(commit.calls.argsFor(0)).toEqual(['REQUEST_PUBLISH_REVIEW']);
expect(commit.calls.argsFor(1)).toEqual(['RECEIVE_PUBLISH_REVIEW_SUCCESS']);
expect(commit.mock.calls[0]).toEqual(['REQUEST_PUBLISH_REVIEW']);
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)
.catch(done.fail);
......@@ -210,8 +210,8 @@ describe('Batch comments store actions', () => {
actions
.publishReview({ dispatch, commit, getters, rootGetters })
.then(() => {
expect(commit.calls.argsFor(0)).toEqual(['REQUEST_PUBLISH_REVIEW']);
expect(commit.calls.argsFor(1)).toEqual(['RECEIVE_PUBLISH_REVIEW_ERROR']);
expect(commit.mock.calls[0]).toEqual(['REQUEST_PUBLISH_REVIEW']);
expect(commit.mock.calls[1]).toEqual(['RECEIVE_PUBLISH_REVIEW_ERROR']);
})
.then(done)
.catch(done.fail);
......@@ -223,14 +223,14 @@ describe('Batch comments store actions', () => {
const getters = {
getNotesData: { draftsDiscardPath: gl.TEST_HOST },
};
const commit = jasmine.createSpy('commit');
const commit = jest.fn();
mock.onAny().reply(200);
actions
.discardReview({ getters, commit })
.then(() => {
expect(commit.calls.argsFor(0)).toEqual(['REQUEST_DISCARD_REVIEW']);
expect(commit.calls.argsFor(1)).toEqual(['RECEIVE_DISCARD_REVIEW_SUCCESS']);
expect(commit.mock.calls[0]).toEqual(['REQUEST_DISCARD_REVIEW']);
expect(commit.mock.calls[1]).toEqual(['RECEIVE_DISCARD_REVIEW_SUCCESS']);
})
.then(done)
.catch(done.fail);
......@@ -240,14 +240,14 @@ describe('Batch comments store actions', () => {
const getters = {
getNotesData: { draftsDiscardPath: gl.TEST_HOST },
};
const commit = jasmine.createSpy('commit');
const commit = jest.fn();
mock.onAny().reply(500);
actions
.discardReview({ getters, commit })
.then(() => {
expect(commit.calls.argsFor(0)).toEqual(['REQUEST_DISCARD_REVIEW']);
expect(commit.calls.argsFor(1)).toEqual(['RECEIVE_DISCARD_REVIEW_ERROR']);
expect(commit.mock.calls[0]).toEqual(['REQUEST_DISCARD_REVIEW']);
expect(commit.mock.calls[1]).toEqual(['RECEIVE_DISCARD_REVIEW_ERROR']);
})
.then(done)
.catch(done.fail);
......@@ -266,7 +266,7 @@ describe('Batch comments store actions', () => {
});
it('commits RECEIVE_DRAFT_UPDATE_SUCCESS with returned data', done => {
const commit = jasmine.createSpy('commit');
const commit = jest.fn();
const context = {
getters,
commit,
......@@ -284,12 +284,12 @@ describe('Batch comments store actions', () => {
});
it('calls passed callback', done => {
const commit = jasmine.createSpy('commit');
const commit = jest.fn();
const context = {
getters,
commit,
};
const callback = jasmine.createSpy('callback');
const callback = jest.fn();
res = { id: 1 };
mock.onAny().reply(200, res);
......@@ -383,12 +383,12 @@ describe('Batch comments store actions', () => {
beforeEach(() => {
window.mrTabs = {
currentAction: 'notes',
tabShown: jasmine.createSpy('tabShown'),
tabShown: jest.fn(),
};
});
it('scrolls to draft item', () => {
const dispatch = jasmine.createSpy('dispatch');
const dispatch = jest.fn();
const rootGetters = {
getDiscussion: () => ({
id: '1',
......@@ -402,9 +402,9 @@ describe('Batch comments store actions', () => {
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',
{ discussionId: '1' },
{ root: true },
......
// eslint-disable-next-line import/prefer-default-export
export const createDraft = () => ({
author: {
id: 1,
name: 'Test',
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,
});
// No new code should be added to this file. Instead, modify the
// file this one re-exports from. For more detail about why, see:
// https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/31349
export * from '../../frontend/batch_comments/mock_data';
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