summaryrefslogtreecommitdiff
path: root/spec/frontend/batch_comments
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/frontend/batch_comments
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/frontend/batch_comments')
-rw-r--r--spec/frontend/batch_comments/stores/modules/batch_comments/actions_spec.js59
1 files changed, 33 insertions, 26 deletions
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 885e02ef60f..da19265ce82 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
@@ -1,6 +1,7 @@
import MockAdapter from 'axios-mock-adapter';
import { TEST_HOST } from 'helpers/test_constants';
import testAction from 'helpers/vuex_action_helper';
+import service from '~/batch_comments/services/drafts_service';
import * as actions from '~/batch_comments/stores/modules/batch_comments/actions';
import axios from '~/lib/utils/axios_utils';
@@ -201,6 +202,12 @@ describe('Batch comments store actions', () => {
describe('updateDraft', () => {
let getters;
+ service.update = jest.fn();
+ service.update.mockResolvedValue({ data: { id: 1 } });
+
+ const commit = jest.fn();
+ let context;
+ let params;
beforeEach(() => {
getters = {
@@ -208,43 +215,43 @@ describe('Batch comments store actions', () => {
draftsPath: TEST_HOST,
},
};
- });
- it('commits RECEIVE_DRAFT_UPDATE_SUCCESS with returned data', (done) => {
- const commit = jest.fn();
- const context = {
+ context = {
getters,
commit,
};
res = { id: 1 };
mock.onAny().reply(200, res);
+ params = { note: { id: 1 }, noteText: 'test' };
+ });
- actions
- .updateDraft(context, { note: { id: 1 }, noteText: 'test', callback() {} })
- .then(() => {
- expect(commit).toHaveBeenCalledWith('RECEIVE_DRAFT_UPDATE_SUCCESS', { id: 1 });
- })
- .then(done)
- .catch(done.fail);
+ afterEach(() => jest.clearAllMocks());
+
+ it('commits RECEIVE_DRAFT_UPDATE_SUCCESS with returned data', () => {
+ return actions.updateDraft(context, { ...params, callback() {} }).then(() => {
+ expect(commit).toHaveBeenCalledWith('RECEIVE_DRAFT_UPDATE_SUCCESS', { id: 1 });
+ });
});
- it('calls passed callback', (done) => {
- const commit = jest.fn();
- const context = {
- getters,
- commit,
- };
+ it('calls passed callback', () => {
const callback = jest.fn();
- res = { id: 1 };
- mock.onAny().reply(200, res);
+ return actions.updateDraft(context, { ...params, callback }).then(() => {
+ expect(callback).toHaveBeenCalled();
+ });
+ });
- actions
- .updateDraft(context, { note: { id: 1 }, noteText: 'test', callback })
- .then(() => {
- expect(callback).toHaveBeenCalled();
- })
- .then(done)
- .catch(done.fail);
+ it('does not stringify empty position', () => {
+ return actions.updateDraft(context, { ...params, position: {}, callback() {} }).then(() => {
+ expect(service.update.mock.calls[0][1].position).toBeUndefined();
+ });
+ });
+
+ it('stringifies a non-empty position', () => {
+ const position = { test: true };
+ const expectation = JSON.stringify(position);
+ return actions.updateDraft(context, { ...params, position, callback() {} }).then(() => {
+ expect(service.update.mock.calls[0][1].position).toBe(expectation);
+ });
});
});