summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/stores
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts/ide/stores')
-rw-r--r--spec/javascripts/ide/stores/actions/file_spec.js74
-rw-r--r--spec/javascripts/ide/stores/modules/commit/actions_spec.js2
-rw-r--r--spec/javascripts/ide/stores/modules/commit/getters_spec.js8
-rw-r--r--spec/javascripts/ide/stores/modules/commit/mutations_spec.js42
-rw-r--r--spec/javascripts/ide/stores/modules/file_templates/getters_spec.js59
-rw-r--r--spec/javascripts/ide/stores/modules/file_templates/mutations_spec.js69
-rw-r--r--spec/javascripts/ide/stores/modules/pane/getters_spec.js55
-rw-r--r--spec/javascripts/ide/stores/modules/pane/mutations_spec.js42
-rw-r--r--spec/javascripts/ide/stores/modules/pipelines/getters_spec.js40
-rw-r--r--spec/javascripts/ide/stores/mutations/branch_spec.js40
-rw-r--r--spec/javascripts/ide/stores/mutations/merge_request_spec.js67
11 files changed, 32 insertions, 466 deletions
diff --git a/spec/javascripts/ide/stores/actions/file_spec.js b/spec/javascripts/ide/stores/actions/file_spec.js
index 7ddc734ff56..1e5b55af4ba 100644
--- a/spec/javascripts/ide/stores/actions/file_spec.js
+++ b/spec/javascripts/ide/stores/actions/file_spec.js
@@ -121,68 +121,48 @@ describe('IDE store file actions', () => {
store._actions.scrollToTab = oldScrollToTab; // eslint-disable-line
});
- it('calls scrollToTab', done => {
- store
- .dispatch('setFileActive', localFile.path)
- .then(() => {
- expect(scrollToTabSpy).toHaveBeenCalled();
-
- done();
- })
- .catch(done.fail);
- });
+ it('calls scrollToTab', () => {
+ const dispatch = jasmine.createSpy();
- it('sets the file active', done => {
- store
- .dispatch('setFileActive', localFile.path)
- .then(() => {
- expect(localFile.active).toBeTruthy();
+ actions.setFileActive(
+ { commit() {}, state: store.state, getters: store.getters, dispatch },
+ localFile.path,
+ );
- done();
- })
- .catch(done.fail);
+ expect(dispatch).toHaveBeenCalledWith('scrollToTab');
});
- it('returns early if file is already active', done => {
- localFile.active = true;
+ it('commits SET_FILE_ACTIVE', () => {
+ const commit = jasmine.createSpy();
- store
- .dispatch('setFileActive', localFile.path)
- .then(() => {
- expect(scrollToTabSpy).not.toHaveBeenCalled();
+ actions.setFileActive(
+ { commit, state: store.state, getters: store.getters, dispatch() {} },
+ localFile.path,
+ );
- done();
- })
- .catch(done.fail);
+ expect(commit).toHaveBeenCalledWith('SET_FILE_ACTIVE', {
+ path: localFile.path,
+ active: true,
+ });
});
- it('sets current active file to not active', done => {
+ it('sets current active file to not active', () => {
const f = file('newActive');
store.state.entries[f.path] = f;
localFile.active = true;
store.state.openFiles.push(localFile);
- store
- .dispatch('setFileActive', f.path)
- .then(() => {
- expect(localFile.active).toBeFalsy();
+ const commit = jasmine.createSpy();
- done();
- })
- .catch(done.fail);
- });
-
- it('resets location.hash for line highlighting', done => {
- window.location.hash = 'test';
-
- store
- .dispatch('setFileActive', localFile.path)
- .then(() => {
- expect(window.location.hash).not.toBe('test');
+ actions.setFileActive(
+ { commit, state: store.state, getters: store.getters, dispatch() {} },
+ f.path,
+ );
- done();
- })
- .catch(done.fail);
+ expect(commit).toHaveBeenCalledWith('SET_FILE_ACTIVE', {
+ path: localFile.path,
+ active: false,
+ });
});
});
diff --git a/spec/javascripts/ide/stores/modules/commit/actions_spec.js b/spec/javascripts/ide/stores/modules/commit/actions_spec.js
index 06b8b452319..34d97347438 100644
--- a/spec/javascripts/ide/stores/modules/commit/actions_spec.js
+++ b/spec/javascripts/ide/stores/modules/commit/actions_spec.js
@@ -396,7 +396,7 @@ describe('IDE commit module actions', () => {
.then(() => {
expect(visitUrl).toHaveBeenCalledWith(
`webUrl/merge_requests/new?merge_request[source_branch]=${
- store.getters['commit/newBranchName']
+ store.getters['commit/placeholderBranchName']
}&merge_request[target_branch]=master`,
);
diff --git a/spec/javascripts/ide/stores/modules/commit/getters_spec.js b/spec/javascripts/ide/stores/modules/commit/getters_spec.js
index 3f4bf407a1f..702e78ef773 100644
--- a/spec/javascripts/ide/stores/modules/commit/getters_spec.js
+++ b/spec/javascripts/ide/stores/modules/commit/getters_spec.js
@@ -29,11 +29,11 @@ describe('IDE commit module getters', () => {
});
});
- describe('newBranchName', () => {
+ describe('placeholderBranchName', () => {
it('includes username, currentBranchId, patch & random number', () => {
gon.current_username = 'username';
- const branch = getters.newBranchName(state, null, {
+ const branch = getters.placeholderBranchName(state, null, {
currentBranchId: 'testing',
});
@@ -46,7 +46,7 @@ describe('IDE commit module getters', () => {
currentBranchId: 'master',
};
const localGetters = {
- newBranchName: 'newBranchName',
+ placeholderBranchName: 'newBranchName',
};
beforeEach(() => {
@@ -71,7 +71,7 @@ describe('IDE commit module getters', () => {
expect(getters.branchName(state, localGetters, rootState)).toBe('state-newBranchName');
});
- it('uses getters newBranchName when state newBranchName is empty', () => {
+ it('uses placeholderBranchName when state newBranchName is empty', () => {
Object.assign(state, {
newBranchName: '',
});
diff --git a/spec/javascripts/ide/stores/modules/commit/mutations_spec.js b/spec/javascripts/ide/stores/modules/commit/mutations_spec.js
deleted file mode 100644
index 5de7a281d34..00000000000
--- a/spec/javascripts/ide/stores/modules/commit/mutations_spec.js
+++ /dev/null
@@ -1,42 +0,0 @@
-import commitState from '~/ide/stores/modules/commit/state';
-import mutations from '~/ide/stores/modules/commit/mutations';
-
-describe('IDE commit module mutations', () => {
- let state;
-
- beforeEach(() => {
- state = commitState();
- });
-
- describe('UPDATE_COMMIT_MESSAGE', () => {
- it('updates commitMessage', () => {
- mutations.UPDATE_COMMIT_MESSAGE(state, 'testing');
-
- expect(state.commitMessage).toBe('testing');
- });
- });
-
- describe('UPDATE_COMMIT_ACTION', () => {
- it('updates commitAction', () => {
- mutations.UPDATE_COMMIT_ACTION(state, 'testing');
-
- expect(state.commitAction).toBe('testing');
- });
- });
-
- describe('UPDATE_NEW_BRANCH_NAME', () => {
- it('updates newBranchName', () => {
- mutations.UPDATE_NEW_BRANCH_NAME(state, 'testing');
-
- expect(state.newBranchName).toBe('testing');
- });
- });
-
- describe('UPDATE_LOADING', () => {
- it('updates submitCommitLoading', () => {
- mutations.UPDATE_LOADING(state, true);
-
- expect(state.submitCommitLoading).toBeTruthy();
- });
- });
-});
diff --git a/spec/javascripts/ide/stores/modules/file_templates/getters_spec.js b/spec/javascripts/ide/stores/modules/file_templates/getters_spec.js
deleted file mode 100644
index 17cb457881f..00000000000
--- a/spec/javascripts/ide/stores/modules/file_templates/getters_spec.js
+++ /dev/null
@@ -1,59 +0,0 @@
-import createState from '~/ide/stores/state';
-import { activityBarViews } from '~/ide/constants';
-import * as getters from '~/ide/stores/modules/file_templates/getters';
-
-describe('IDE file templates getters', () => {
- describe('templateTypes', () => {
- it('returns list of template types', () => {
- expect(getters.templateTypes().length).toBe(4);
- });
- });
-
- describe('showFileTemplatesBar', () => {
- let rootState;
-
- beforeEach(() => {
- rootState = createState();
- });
-
- it('returns true if template is found and currentActivityView is edit', () => {
- rootState.currentActivityView = activityBarViews.edit;
-
- expect(
- getters.showFileTemplatesBar(
- null,
- {
- templateTypes: getters.templateTypes(),
- },
- rootState,
- )('LICENSE'),
- ).toBe(true);
- });
-
- it('returns false if template is found and currentActivityView is not edit', () => {
- rootState.currentActivityView = activityBarViews.commit;
-
- expect(
- getters.showFileTemplatesBar(
- null,
- {
- templateTypes: getters.templateTypes(),
- },
- rootState,
- )('LICENSE'),
- ).toBe(false);
- });
-
- it('returns undefined if not found', () => {
- expect(
- getters.showFileTemplatesBar(
- null,
- {
- templateTypes: getters.templateTypes(),
- },
- rootState,
- )('test'),
- ).toBe(undefined);
- });
- });
-});
diff --git a/spec/javascripts/ide/stores/modules/file_templates/mutations_spec.js b/spec/javascripts/ide/stores/modules/file_templates/mutations_spec.js
deleted file mode 100644
index 8e0e3ae99a1..00000000000
--- a/spec/javascripts/ide/stores/modules/file_templates/mutations_spec.js
+++ /dev/null
@@ -1,69 +0,0 @@
-import createState from '~/ide/stores/modules/file_templates/state';
-import * as types from '~/ide/stores/modules/file_templates/mutation_types';
-import mutations from '~/ide/stores/modules/file_templates/mutations';
-
-describe('IDE file templates mutations', () => {
- let state;
-
- beforeEach(() => {
- state = createState();
- });
-
- describe(types.REQUEST_TEMPLATE_TYPES, () => {
- it('sets isLoading', () => {
- mutations[types.REQUEST_TEMPLATE_TYPES](state);
-
- expect(state.isLoading).toBe(true);
- });
- });
-
- describe(types.RECEIVE_TEMPLATE_TYPES_ERROR, () => {
- it('sets isLoading', () => {
- state.isLoading = true;
-
- mutations[types.RECEIVE_TEMPLATE_TYPES_ERROR](state);
-
- expect(state.isLoading).toBe(false);
- });
- });
-
- describe(types.RECEIVE_TEMPLATE_TYPES_SUCCESS, () => {
- it('sets isLoading to false', () => {
- state.isLoading = true;
-
- mutations[types.RECEIVE_TEMPLATE_TYPES_SUCCESS](state, []);
-
- expect(state.isLoading).toBe(false);
- });
-
- it('sets templates', () => {
- mutations[types.RECEIVE_TEMPLATE_TYPES_SUCCESS](state, ['test']);
-
- expect(state.templates).toEqual(['test']);
- });
- });
-
- describe(types.SET_SELECTED_TEMPLATE_TYPE, () => {
- it('sets selectedTemplateType', () => {
- mutations[types.SET_SELECTED_TEMPLATE_TYPE](state, 'type');
-
- expect(state.selectedTemplateType).toBe('type');
- });
-
- it('clears templates', () => {
- state.templates = ['test'];
-
- mutations[types.SET_SELECTED_TEMPLATE_TYPE](state, 'type');
-
- expect(state.templates).toEqual([]);
- });
- });
-
- describe(types.SET_UPDATE_SUCCESS, () => {
- it('sets updateSuccess', () => {
- mutations[types.SET_UPDATE_SUCCESS](state, true);
-
- expect(state.updateSuccess).toBe(true);
- });
- });
-});
diff --git a/spec/javascripts/ide/stores/modules/pane/getters_spec.js b/spec/javascripts/ide/stores/modules/pane/getters_spec.js
deleted file mode 100644
index 8a213323de0..00000000000
--- a/spec/javascripts/ide/stores/modules/pane/getters_spec.js
+++ /dev/null
@@ -1,55 +0,0 @@
-import * as getters from '~/ide/stores/modules/pane/getters';
-import state from '~/ide/stores/modules/pane/state';
-
-describe('IDE pane module getters', () => {
- const TEST_VIEW = 'test-view';
- const TEST_KEEP_ALIVE_VIEWS = {
- [TEST_VIEW]: true,
- };
-
- describe('isActiveView', () => {
- it('returns true if given view matches currentView', () => {
- const result = getters.isActiveView({ currentView: 'A' })('A');
-
- expect(result).toBe(true);
- });
-
- it('returns false if given view does not match currentView', () => {
- const result = getters.isActiveView({ currentView: 'A' })('B');
-
- expect(result).toBe(false);
- });
- });
-
- describe('isAliveView', () => {
- it('returns true if given view is in keepAliveViews', () => {
- const result = getters.isAliveView({ keepAliveViews: TEST_KEEP_ALIVE_VIEWS }, {})(TEST_VIEW);
-
- expect(result).toBe(true);
- });
-
- it('returns true if given view is active view and open', () => {
- const result = getters.isAliveView(
- { ...state(), isOpen: true },
- { isActiveView: () => true },
- )(TEST_VIEW);
-
- expect(result).toBe(true);
- });
-
- it('returns false if given view is active view and closed', () => {
- const result = getters.isAliveView(state(), { isActiveView: () => true })(TEST_VIEW);
-
- expect(result).toBe(false);
- });
-
- it('returns false if given view is not activeView', () => {
- const result = getters.isAliveView(
- { ...state(), isOpen: true },
- { isActiveView: () => false },
- )(TEST_VIEW);
-
- expect(result).toBe(false);
- });
- });
-});
diff --git a/spec/javascripts/ide/stores/modules/pane/mutations_spec.js b/spec/javascripts/ide/stores/modules/pane/mutations_spec.js
deleted file mode 100644
index b5fcd35912e..00000000000
--- a/spec/javascripts/ide/stores/modules/pane/mutations_spec.js
+++ /dev/null
@@ -1,42 +0,0 @@
-import state from '~/ide/stores/modules/pane/state';
-import mutations from '~/ide/stores/modules/pane/mutations';
-import * as types from '~/ide/stores/modules/pane/mutation_types';
-
-describe('IDE pane module mutations', () => {
- const TEST_VIEW = 'test-view';
- let mockedState;
-
- beforeEach(() => {
- mockedState = state();
- });
-
- describe('SET_OPEN', () => {
- it('sets isOpen', () => {
- mockedState.isOpen = false;
-
- mutations[types.SET_OPEN](mockedState, true);
-
- expect(mockedState.isOpen).toBe(true);
- });
- });
-
- describe('SET_CURRENT_VIEW', () => {
- it('sets currentView', () => {
- mockedState.currentView = null;
-
- mutations[types.SET_CURRENT_VIEW](mockedState, TEST_VIEW);
-
- expect(mockedState.currentView).toEqual(TEST_VIEW);
- });
- });
-
- describe('KEEP_ALIVE_VIEW', () => {
- it('adds entry to keepAliveViews', () => {
- mutations[types.KEEP_ALIVE_VIEW](mockedState, TEST_VIEW);
-
- expect(mockedState.keepAliveViews).toEqual({
- [TEST_VIEW]: true,
- });
- });
- });
-});
diff --git a/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js b/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js
deleted file mode 100644
index 4514896b5ea..00000000000
--- a/spec/javascripts/ide/stores/modules/pipelines/getters_spec.js
+++ /dev/null
@@ -1,40 +0,0 @@
-import * as getters from '~/ide/stores/modules/pipelines/getters';
-import state from '~/ide/stores/modules/pipelines/state';
-
-describe('IDE pipeline getters', () => {
- let mockedState;
-
- beforeEach(() => {
- mockedState = state();
- });
-
- describe('hasLatestPipeline', () => {
- it('returns false when loading is true', () => {
- mockedState.isLoadingPipeline = true;
-
- expect(getters.hasLatestPipeline(mockedState)).toBe(false);
- });
-
- it('returns false when pipelines is null', () => {
- mockedState.latestPipeline = null;
-
- expect(getters.hasLatestPipeline(mockedState)).toBe(false);
- });
-
- it('returns false when loading is true & pipelines is null', () => {
- mockedState.latestPipeline = null;
- mockedState.isLoadingPipeline = true;
-
- expect(getters.hasLatestPipeline(mockedState)).toBe(false);
- });
-
- it('returns true when loading is false & pipelines is an object', () => {
- mockedState.latestPipeline = {
- id: 1,
- };
- mockedState.isLoadingPipeline = false;
-
- expect(getters.hasLatestPipeline(mockedState)).toBe(true);
- });
- });
-});
diff --git a/spec/javascripts/ide/stores/mutations/branch_spec.js b/spec/javascripts/ide/stores/mutations/branch_spec.js
deleted file mode 100644
index 29eb859ddaf..00000000000
--- a/spec/javascripts/ide/stores/mutations/branch_spec.js
+++ /dev/null
@@ -1,40 +0,0 @@
-import mutations from '~/ide/stores/mutations/branch';
-import state from '~/ide/stores/state';
-
-describe('Multi-file store branch mutations', () => {
- let localState;
-
- beforeEach(() => {
- localState = state();
- });
-
- describe('SET_CURRENT_BRANCH', () => {
- it('sets currentBranch', () => {
- mutations.SET_CURRENT_BRANCH(localState, 'master');
-
- expect(localState.currentBranchId).toBe('master');
- });
- });
-
- describe('SET_BRANCH_COMMIT', () => {
- it('sets the last commit on current project', () => {
- localState.projects = {
- Example: {
- branches: {
- master: {},
- },
- },
- };
-
- mutations.SET_BRANCH_COMMIT(localState, {
- projectId: 'Example',
- branchId: 'master',
- commit: {
- title: 'Example commit',
- },
- });
-
- expect(localState.projects.Example.branches.master.commit.title).toBe('Example commit');
- });
- });
-});
diff --git a/spec/javascripts/ide/stores/mutations/merge_request_spec.js b/spec/javascripts/ide/stores/mutations/merge_request_spec.js
deleted file mode 100644
index e30ca22022f..00000000000
--- a/spec/javascripts/ide/stores/mutations/merge_request_spec.js
+++ /dev/null
@@ -1,67 +0,0 @@
-import mutations from '~/ide/stores/mutations/merge_request';
-import state from '~/ide/stores/state';
-
-describe('IDE store merge request mutations', () => {
- let localState;
-
- beforeEach(() => {
- localState = state();
- localState.projects = { abcproject: { mergeRequests: {} } };
-
- mutations.SET_MERGE_REQUEST(localState, {
- projectPath: 'abcproject',
- mergeRequestId: 1,
- mergeRequest: {
- title: 'mr',
- },
- });
- });
-
- describe('SET_CURRENT_MERGE_REQUEST', () => {
- it('sets current merge request', () => {
- mutations.SET_CURRENT_MERGE_REQUEST(localState, 2);
-
- expect(localState.currentMergeRequestId).toBe(2);
- });
- });
-
- describe('SET_MERGE_REQUEST', () => {
- it('setsmerge request data', () => {
- const newMr = localState.projects.abcproject.mergeRequests[1];
-
- expect(newMr.title).toBe('mr');
- expect(newMr.active).toBeTruthy();
- });
- });
-
- describe('SET_MERGE_REQUEST_CHANGES', () => {
- it('sets merge request changes', () => {
- mutations.SET_MERGE_REQUEST_CHANGES(localState, {
- projectPath: 'abcproject',
- mergeRequestId: 1,
- changes: {
- diff: 'abc',
- },
- });
-
- const newMr = localState.projects.abcproject.mergeRequests[1];
-
- expect(newMr.changes.diff).toBe('abc');
- });
- });
-
- describe('SET_MERGE_REQUEST_VERSIONS', () => {
- it('sets merge request versions', () => {
- mutations.SET_MERGE_REQUEST_VERSIONS(localState, {
- projectPath: 'abcproject',
- mergeRequestId: 1,
- versions: [{ id: 123 }],
- });
-
- const newMr = localState.projects.abcproject.mergeRequests[1];
-
- expect(newMr.versions.length).toBe(1);
- expect(newMr.versions[0].id).toBe(123);
- });
- });
-});