Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/diffs/store/actions_spec.js')
-rw-r--r--spec/frontend/diffs/store/actions_spec.js62
1 files changed, 33 insertions, 29 deletions
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js
index f46a42fae7a..14f8e090be9 100644
--- a/spec/frontend/diffs/store/actions_spec.js
+++ b/spec/frontend/diffs/store/actions_spec.js
@@ -9,8 +9,6 @@ import {
INLINE_DIFF_VIEW_TYPE,
PARALLEL_DIFF_VIEW_TYPE,
DIFFS_PER_PAGE,
- DIFF_WHITESPACE_COOKIE_NAME,
- SHOW_WHITESPACE,
} from '~/diffs/constants';
import {
setBaseConfig,
@@ -54,7 +52,8 @@ import {
} from '~/diffs/store/actions';
import * as types from '~/diffs/store/mutation_types';
import * as utils from '~/diffs/store/utils';
-import { deprecatedCreateFlash as createFlash } from '~/flash';
+import * as workerUtils from '~/diffs/utils/workers';
+import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils';
import * as commonUtils from '~/lib/utils/common_utils';
import { mergeUrlParams } from '~/lib/utils/url_utility';
@@ -252,7 +251,10 @@ describe('DiffsStoreActions', () => {
{ type: types.SET_MERGE_REQUEST_DIFFS, payload: diffMetadata.merge_request_diffs },
{ type: types.SET_DIFF_METADATA, payload: noFilesData },
// Workers are synchronous in Jest environment (see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/58805)
- { type: types.SET_TREE_DATA, payload: utils.generateTreeList(diffMetadata.diff_files) },
+ {
+ type: types.SET_TREE_DATA,
+ payload: workerUtils.generateTreeList(diffMetadata.diff_files),
+ },
],
[],
() => {
@@ -293,7 +295,9 @@ describe('DiffsStoreActions', () => {
testAction(fetchCoverageFiles, {}, { endpointCoverage }, [], [], () => {
expect(createFlash).toHaveBeenCalledTimes(1);
- expect(createFlash).toHaveBeenCalledWith(expect.stringMatching('Something went wrong'));
+ expect(createFlash).toHaveBeenCalledWith({
+ message: expect.stringMatching('Something went wrong'),
+ });
done();
});
});
@@ -1013,14 +1017,26 @@ describe('DiffsStoreActions', () => {
});
describe('setShowWhitespace', () => {
+ const endpointUpdateUser = 'user/prefs';
+ let putSpy;
+ let mock;
+
beforeEach(() => {
+ mock = new MockAdapter(axios);
+ putSpy = jest.spyOn(axios, 'put');
+
+ mock.onPut(endpointUpdateUser).reply(200, {});
jest.spyOn(eventHub, '$emit').mockImplementation();
});
+ afterEach(() => {
+ mock.restore();
+ });
+
it('commits SET_SHOW_WHITESPACE', (done) => {
testAction(
setShowWhitespace,
- { showWhitespace: true },
+ { showWhitespace: true, updateDatabase: false },
{},
[{ type: types.SET_SHOW_WHITESPACE, payload: true }],
[],
@@ -1028,32 +1044,20 @@ describe('DiffsStoreActions', () => {
);
});
- it('sets cookie', () => {
- setShowWhitespace({ commit() {} }, { showWhitespace: true });
-
- expect(Cookies.get(DIFF_WHITESPACE_COOKIE_NAME)).toEqual(SHOW_WHITESPACE);
- });
-
- it('calls history pushState', () => {
- setShowWhitespace({ commit() {} }, { showWhitespace: true, pushState: true });
-
- expect(window.history.pushState).toHaveBeenCalled();
- });
-
- it('calls history pushState with merged params', () => {
- window.history.pushState({}, '', '?test=1');
-
- setShowWhitespace({ commit() {} }, { showWhitespace: true, pushState: true });
-
- expect(
- window.history.pushState.mock.calls[window.history.pushState.mock.calls.length - 1][2],
- ).toMatch(/(.*)\?test=1&w=0/);
+ it('saves to the database', async () => {
+ await setShowWhitespace(
+ { state: { endpointUpdateUser }, commit() {} },
+ { showWhitespace: true, updateDatabase: true },
+ );
- window.history.pushState({}, '', '?');
+ expect(putSpy).toHaveBeenCalledWith(endpointUpdateUser, { show_whitespace_in_diffs: true });
});
- it('emits eventHub event', () => {
- setShowWhitespace({ commit() {} }, { showWhitespace: true, pushState: true });
+ it('emits eventHub event', async () => {
+ await setShowWhitespace(
+ { state: {}, commit() {} },
+ { showWhitespace: true, updateDatabase: false },
+ );
expect(eventHub.$emit).toHaveBeenCalledWith('refetchDiffData');
});