summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/stores/modules/commit/actions_spec.js
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
committerRobert Speicher <rspeicher@gmail.com>2021-01-20 13:34:23 -0600
commit6438df3a1e0fb944485cebf07976160184697d72 (patch)
tree00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/frontend/ide/stores/modules/commit/actions_spec.js
parent42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff)
downloadgitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/frontend/ide/stores/modules/commit/actions_spec.js')
-rw-r--r--spec/frontend/ide/stores/modules/commit/actions_spec.js95
1 files changed, 41 insertions, 54 deletions
diff --git a/spec/frontend/ide/stores/modules/commit/actions_spec.js b/spec/frontend/ide/stores/modules/commit/actions_spec.js
index cfe2bddf76c..5be0e22a9fc 100644
--- a/spec/frontend/ide/stores/modules/commit/actions_spec.js
+++ b/spec/frontend/ide/stores/modules/commit/actions_spec.js
@@ -1,6 +1,7 @@
import { file } from 'jest/ide/helpers';
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
+import testAction from 'helpers/vuex_action_helper';
import { visitUrl } from '~/lib/utils/url_utility';
import { createStore } from '~/ide/stores';
import service from '~/ide/services';
@@ -11,7 +12,6 @@ import * as mutationTypes from '~/ide/stores/modules/commit/mutation_types';
import * as actions from '~/ide/stores/modules/commit/actions';
import { createUnexpectedCommitError } from '~/ide/lib/errors';
import { commitActionTypes, PERMISSION_CREATE_MR } from '~/ide/constants';
-import testAction from '../../../../helpers/vuex_action_helper';
jest.mock('~/lib/utils/url_utility', () => ({
...jest.requireActual('~/lib/utils/url_utility'),
@@ -19,6 +19,17 @@ jest.mock('~/lib/utils/url_utility', () => ({
}));
const TEST_COMMIT_SHA = '123456789';
+const COMMIT_RESPONSE = {
+ id: '123456',
+ short_id: '123',
+ message: 'test message',
+ committed_date: 'date',
+ parent_ids: [],
+ stats: {
+ additions: '1',
+ deletions: '2',
+ },
+};
describe('IDE commit module actions', () => {
let mock;
@@ -32,7 +43,9 @@ describe('IDE commit module actions', () => {
mock = new MockAdapter(axios);
jest.spyOn(router, 'push').mockImplementation();
- mock.onGet('/api/v1/projects/abcproject/repository/branches/master').reply(200);
+ mock
+ .onGet('/api/v1/projects/abcproject/repository/branches/master')
+ .reply(200, { commit: COMMIT_RESPONSE });
});
afterEach(() => {
@@ -41,7 +54,7 @@ describe('IDE commit module actions', () => {
});
describe('updateCommitMessage', () => {
- it('updates store with new commit message', done => {
+ it('updates store with new commit message', (done) => {
store
.dispatch('commit/updateCommitMessage', 'testing')
.then(() => {
@@ -53,7 +66,7 @@ describe('IDE commit module actions', () => {
});
describe('discardDraft', () => {
- it('resets commit message to blank', done => {
+ it('resets commit message to blank', (done) => {
store.state.commit.commitMessage = 'testing';
store
@@ -67,7 +80,7 @@ describe('IDE commit module actions', () => {
});
describe('updateCommitAction', () => {
- it('updates store with new commit action', done => {
+ it('updates store with new commit action', (done) => {
store
.dispatch('commit/updateCommitAction', '1')
.then(() => {
@@ -123,7 +136,7 @@ describe('IDE commit module actions', () => {
});
});
- it('updates commit message with short_id', done => {
+ it('updates commit message with short_id', (done) => {
store
.dispatch('commit/setLastCommitMessage', { short_id: '123' })
.then(() => {
@@ -135,7 +148,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('updates commit message with stats', done => {
+ it('updates commit message with stats', (done) => {
store
.dispatch('commit/setLastCommitMessage', {
short_id: '123',
@@ -200,12 +213,12 @@ describe('IDE commit module actions', () => {
});
store.state.openFiles = store.state.stagedFiles;
- store.state.stagedFiles.forEach(stagedFile => {
+ store.state.stagedFiles.forEach((stagedFile) => {
store.state.entries[stagedFile.path] = stagedFile;
});
});
- it('updates stores working reference', done => {
+ it('updates stores working reference', (done) => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
@@ -218,14 +231,14 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('resets all files changed status', done => {
+ it('resets all files changed status', (done) => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
.then(() => {
- store.state.openFiles.forEach(entry => {
+ store.state.openFiles.forEach((entry) => {
expect(entry.changed).toBeFalsy();
});
})
@@ -233,7 +246,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('sets files commit data', done => {
+ it('sets files commit data', (done) => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
@@ -246,7 +259,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('updates raw content for changed file', done => {
+ it('updates raw content for changed file', (done) => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
@@ -259,7 +272,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('emits changed event for file', done => {
+ it('emits changed event for file', (done) => {
store
.dispatch('commit/updateFilesAfterCommit', {
data,
@@ -319,7 +332,7 @@ describe('IDE commit module actions', () => {
store.state.commit.commitAction = '2';
store.state.commit.commitMessage = 'testing 123';
- store.state.openFiles.forEach(localF => {
+ store.state.openFiles.forEach((localF) => {
store.state.entries[localF.path] = localF;
});
});
@@ -329,23 +342,11 @@ describe('IDE commit module actions', () => {
});
describe('success', () => {
- const COMMIT_RESPONSE = {
- id: '123456',
- short_id: '123',
- message: 'test message',
- committed_date: 'date',
- parent_ids: '321',
- stats: {
- additions: '1',
- deletions: '2',
- },
- };
-
beforeEach(() => {
jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE });
});
- it('calls service', done => {
+ it('calls service', (done) => {
store
.dispatch('commit/commitChanges')
.then(() => {
@@ -370,7 +371,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('sends lastCommit ID when not creating new branch', done => {
+ it('sends lastCommit ID when not creating new branch', (done) => {
store.state.commit.commitAction = '1';
store
@@ -397,7 +398,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('sets last Commit Msg', done => {
+ it('sets last Commit Msg', (done) => {
store
.dispatch('commit/commitChanges')
.then(() => {
@@ -410,7 +411,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('adds commit data to files', done => {
+ it('adds commit data to files', (done) => {
store
.dispatch('commit/commitChanges')
.then(() => {
@@ -423,7 +424,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('resets stores commit actions', done => {
+ it('resets stores commit actions', (done) => {
store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH;
store
@@ -435,7 +436,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('removes all staged files', done => {
+ it('removes all staged files', (done) => {
store
.dispatch('commit/commitChanges')
.then(() => {
@@ -446,7 +447,7 @@ describe('IDE commit module actions', () => {
});
describe('merge request', () => {
- it('redirects to new merge request page', done => {
+ it('redirects to new merge request page', (done) => {
jest.spyOn(eventHub, '$on').mockImplementation();
store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH;
@@ -456,9 +457,7 @@ describe('IDE commit module actions', () => {
.dispatch('commit/commitChanges')
.then(() => {
expect(visitUrl).toHaveBeenCalledWith(
- `webUrl/-/merge_requests/new?merge_request[source_branch]=${
- store.getters['commit/placeholderBranchName']
- }&merge_request[target_branch]=master&nav_source=webide`,
+ `webUrl/-/merge_requests/new?merge_request[source_branch]=${store.getters['commit/placeholderBranchName']}&merge_request[target_branch]=master&nav_source=webide`,
);
done();
@@ -466,7 +465,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('does not redirect to new merge request page when shouldCreateMR is not checked', done => {
+ it('does not redirect to new merge request page when shouldCreateMR is not checked', (done) => {
jest.spyOn(eventHub, '$on').mockImplementation();
store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH;
@@ -512,7 +511,7 @@ describe('IDE commit module actions', () => {
});
});
- it('shows failed message', done => {
+ it('shows failed message', (done) => {
store
.dispatch('commit/commitChanges')
.then(() => {
@@ -546,19 +545,7 @@ describe('IDE commit module actions', () => {
});
describe('first commit of a branch', () => {
- const COMMIT_RESPONSE = {
- id: '123456',
- short_id: '123',
- message: 'test message',
- committed_date: 'date',
- parent_ids: [],
- stats: {
- additions: '1',
- deletions: '2',
- },
- };
-
- it('commits TOGGLE_EMPTY_STATE mutation on empty repo', done => {
+ it('commits TOGGLE_EMPTY_STATE mutation on empty repo', (done) => {
jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE });
jest.spyOn(store, 'commit');
@@ -575,7 +562,7 @@ describe('IDE commit module actions', () => {
.catch(done.fail);
});
- it('does not commmit TOGGLE_EMPTY_STATE mutation on existing project', done => {
+ it('does not commmit TOGGLE_EMPTY_STATE mutation on existing project', (done) => {
COMMIT_RESPONSE.parent_ids.push('1234');
jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE });
jest.spyOn(store, 'commit');
@@ -596,7 +583,7 @@ describe('IDE commit module actions', () => {
});
describe('toggleShouldCreateMR', () => {
- it('commits both toggle and interacting with MR checkbox actions', done => {
+ it('commits both toggle and interacting with MR checkbox actions', (done) => {
testAction(
actions.toggleShouldCreateMR,
{},