diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/frontend/projects/commit/store | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/frontend/projects/commit/store')
-rw-r--r-- | spec/frontend/projects/commit/store/actions_spec.js | 111 | ||||
-rw-r--r-- | spec/frontend/projects/commit/store/getters_spec.js | 21 | ||||
-rw-r--r-- | spec/frontend/projects/commit/store/mutations_spec.js | 57 |
3 files changed, 189 insertions, 0 deletions
diff --git a/spec/frontend/projects/commit/store/actions_spec.js b/spec/frontend/projects/commit/store/actions_spec.js new file mode 100644 index 00000000000..ec528d4ee88 --- /dev/null +++ b/spec/frontend/projects/commit/store/actions_spec.js @@ -0,0 +1,111 @@ +import MockAdapter from 'axios-mock-adapter'; +import testAction from 'helpers/vuex_action_helper'; +import axios from '~/lib/utils/axios_utils'; +import createFlash from '~/flash'; +import getInitialState from '~/projects/commit/store/state'; +import * as actions from '~/projects/commit/store/actions'; +import * as types from '~/projects/commit/store/mutation_types'; +import mockData from '../mock_data'; +import { PROJECT_BRANCHES_ERROR } from '~/projects/commit/constants'; + +jest.mock('~/flash.js'); + +describe('Commit form modal store actions', () => { + let axiosMock; + let state; + + beforeEach(() => { + axiosMock = new MockAdapter(axios); + state = getInitialState(); + }); + + afterEach(() => { + axiosMock.restore(); + }); + + describe('clearModal', () => { + it('commits CLEAR_MODAL mutation', () => { + testAction(actions.clearModal, {}, {}, [ + { + type: types.CLEAR_MODAL, + }, + ]); + }); + }); + + describe('requestBranches', () => { + it('commits REQUEST_BRANCHES mutation', () => { + testAction(actions.requestBranches, {}, {}, [ + { + type: types.REQUEST_BRANCHES, + }, + ]); + }); + }); + + describe('fetchBranches', () => { + it('dispatch correct actions on fetchBranches', (done) => { + jest + .spyOn(axios, 'get') + .mockImplementation(() => Promise.resolve({ data: mockData.mockBranches })); + + testAction( + actions.fetchBranches, + {}, + state, + [ + { + type: types.RECEIVE_BRANCHES_SUCCESS, + payload: mockData.mockBranches, + }, + ], + [{ type: 'requestBranches' }], + () => { + done(); + }, + ); + }); + + it('should show flash error and set error in state on fetchBranches failure', (done) => { + jest.spyOn(axios, 'get').mockRejectedValue(); + + testAction(actions.fetchBranches, {}, state, [], [{ type: 'requestBranches' }], () => { + expect(createFlash).toHaveBeenCalledWith({ message: PROJECT_BRANCHES_ERROR }); + done(); + }); + }); + }); + + describe('setBranch', () => { + it('commits SET_BRANCH mutation', () => { + testAction( + actions.setBranch, + {}, + {}, + [ + { + type: types.SET_BRANCH, + payload: {}, + }, + ], + [ + { + type: 'setSelectedBranch', + payload: {}, + }, + ], + ); + }); + }); + + describe('setSelectedBranch', () => { + it('commits SET_SELECTED_BRANCH mutation', () => { + testAction(actions.setSelectedBranch, {}, {}, [ + { + type: types.SET_SELECTED_BRANCH, + payload: {}, + }, + ]); + }); + }); +}); diff --git a/spec/frontend/projects/commit/store/getters_spec.js b/spec/frontend/projects/commit/store/getters_spec.js new file mode 100644 index 00000000000..bd0cb356854 --- /dev/null +++ b/spec/frontend/projects/commit/store/getters_spec.js @@ -0,0 +1,21 @@ +import * as getters from '~/projects/commit/store/getters'; +import mockData from '../mock_data'; + +describe('Commit form modal getters', () => { + describe('joinedBranches', () => { + it('should join fetched branches with variable branches', () => { + const state = { + branches: mockData.mockBranches, + }; + + expect(getters.joinedBranches(state)).toEqual(mockData.mockBranches.sort()); + }); + + it('should provide a uniq list of branches', () => { + const branches = ['_branch_', '_branch_', '_different_branch']; + const state = { branches }; + + expect(getters.joinedBranches(state)).toEqual(branches.slice(1)); + }); + }); +}); diff --git a/spec/frontend/projects/commit/store/mutations_spec.js b/spec/frontend/projects/commit/store/mutations_spec.js new file mode 100644 index 00000000000..59ab3d9a74a --- /dev/null +++ b/spec/frontend/projects/commit/store/mutations_spec.js @@ -0,0 +1,57 @@ +import mutations from '~/projects/commit/store/mutations'; +import * as types from '~/projects/commit/store/mutation_types'; + +describe('Commit form modal mutations', () => { + let stateCopy; + + describe('REQUEST_BRANCHES', () => { + it('should set isFetching to true', () => { + stateCopy = { isFetching: false }; + + mutations[types.REQUEST_BRANCHES](stateCopy); + + expect(stateCopy.isFetching).toBe(true); + }); + }); + + describe('RECEIVE_BRANCHES_SUCCESS', () => { + it('should set branches', () => { + stateCopy = { branch: '_existing_branch_', isFetching: true }; + + mutations[types.RECEIVE_BRANCHES_SUCCESS](stateCopy, ['_branch_1_', '_branch_2_']); + + expect(stateCopy.branches).toEqual(['_existing_branch_', '_branch_1_', '_branch_2_']); + expect(stateCopy.isFetching).toEqual(false); + }); + }); + + describe('CLEAR_MODAL', () => { + it('should clear modal state ', () => { + stateCopy = { branch: '_master_', defaultBranch: '_default_branch_' }; + + mutations[types.CLEAR_MODAL](stateCopy); + + expect(stateCopy.branch).toEqual('_default_branch_'); + }); + }); + + describe('SET_BRANCH', () => { + it('should set branch', () => { + stateCopy = { branch: '_master_' }; + + mutations[types.SET_BRANCH](stateCopy, '_changed_branch_'); + + expect(stateCopy.branch).toBe('_changed_branch_'); + }); + }); + + describe('SET_SELECTED_BRANCH', () => { + it('should set selectedBranch', () => { + stateCopy = { selectedBranch: '_master_' }; + + mutations[types.SET_SELECTED_BRANCH](stateCopy, '_changed_branch_'); + + expect(stateCopy.selectedBranch).toBe('_changed_branch_'); + }); + }); +}); |