diff options
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/integrations/edit/store/actions_spec.js | 30 | ||||
-rw-r--r-- | spec/frontend/integrations/edit/store/mutations_spec.js | 16 | ||||
-rw-r--r-- | spec/frontend/pipelines/unwrapping_utils_spec.js | 127 |
3 files changed, 173 insertions, 0 deletions
diff --git a/spec/frontend/integrations/edit/store/actions_spec.js b/spec/frontend/integrations/edit/store/actions_spec.js index 5b5c8d6f76e..1ff881c265d 100644 --- a/spec/frontend/integrations/edit/store/actions_spec.js +++ b/spec/frontend/integrations/edit/store/actions_spec.js @@ -1,13 +1,19 @@ import testAction from 'helpers/vuex_action_helper'; +import { refreshCurrentPage } from '~/lib/utils/url_utility'; import createState from '~/integrations/edit/store/state'; import { setOverride, setIsSaving, setIsTesting, setIsResetting, + requestResetIntegration, + receiveResetIntegrationSuccess, + receiveResetIntegrationError, } from '~/integrations/edit/store/actions'; import * as types from '~/integrations/edit/store/mutation_types'; +jest.mock('~/lib/utils/url_utility'); + describe('Integration form store actions', () => { let state; @@ -40,4 +46,28 @@ describe('Integration form store actions', () => { ]); }); }); + + describe('requestResetIntegration', () => { + it('should commit REQUEST_RESET_INTEGRATION mutation', () => { + return testAction(requestResetIntegration, null, state, [ + { type: types.REQUEST_RESET_INTEGRATION }, + ]); + }); + }); + + describe('receiveResetIntegrationSuccess', () => { + it('should call refreshCurrentPage()', () => { + return testAction(receiveResetIntegrationSuccess, null, state, [], [], () => { + expect(refreshCurrentPage).toHaveBeenCalled(); + }); + }); + }); + + describe('receiveResetIntegrationError', () => { + it('should commit RECEIVE_RESET_INTEGRATION_ERROR mutation', () => { + return testAction(receiveResetIntegrationError, null, state, [ + { type: types.RECEIVE_RESET_INTEGRATION_ERROR }, + ]); + }); + }); }); diff --git a/spec/frontend/integrations/edit/store/mutations_spec.js b/spec/frontend/integrations/edit/store/mutations_spec.js index 4707b4b3714..81f39adb87f 100644 --- a/spec/frontend/integrations/edit/store/mutations_spec.js +++ b/spec/frontend/integrations/edit/store/mutations_spec.js @@ -40,4 +40,20 @@ describe('Integration form store mutations', () => { expect(state.isResetting).toBe(true); }); }); + + describe(`${types.REQUEST_RESET_INTEGRATION}`, () => { + it('sets isResetting', () => { + mutations[types.REQUEST_RESET_INTEGRATION](state); + + expect(state.isResetting).toBe(true); + }); + }); + + describe(`${types.RECEIVE_RESET_INTEGRATION_ERROR}`, () => { + it('sets isResetting', () => { + mutations[types.RECEIVE_RESET_INTEGRATION_ERROR](state); + + expect(state.isResetting).toBe(false); + }); + }); }); diff --git a/spec/frontend/pipelines/unwrapping_utils_spec.js b/spec/frontend/pipelines/unwrapping_utils_spec.js new file mode 100644 index 00000000000..34413ad3ef3 --- /dev/null +++ b/spec/frontend/pipelines/unwrapping_utils_spec.js @@ -0,0 +1,127 @@ +import { + unwrapGroups, + unwrapNodesWithName, + unwrapStagesWithNeeds, +} from '~/pipelines/components/unwrapping_utils'; + +const groupsArray = [ + { + name: 'build_a', + size: 1, + status: { + label: 'passed', + group: 'success', + icon: 'status_success', + }, + }, + { + name: 'bob_the_build', + size: 1, + status: { + label: 'passed', + group: 'success', + icon: 'status_success', + }, + }, +]; + +const basicStageInfo = { + name: 'center_stage', + status: { + action: null, + }, +}; + +const stagesAndGroups = [ + { + ...basicStageInfo, + groups: { + nodes: groupsArray, + }, + }, +]; + +const needArray = [ + { + name: 'build_b', + }, +]; + +const elephantArray = [ + { + name: 'build_b', + elephant: 'gray', + }, +]; + +const baseJobs = { + name: 'test_d', + status: { + icon: 'status_success', + tooltip: null, + hasDetails: true, + detailsPath: '/root/abcd-dag/-/pipelines/162', + group: 'success', + action: null, + }, +}; + +const jobArrayWithNeeds = [ + { + ...baseJobs, + needs: { + nodes: needArray, + }, + }, +]; + +const jobArrayWithElephant = [ + { + ...baseJobs, + needs: { + nodes: elephantArray, + }, + }, +]; + +const completeMock = [ + { + ...basicStageInfo, + groups: { + nodes: groupsArray.map(group => ({ ...group, jobs: { nodes: jobArrayWithNeeds } })), + }, + }, +]; + +describe('Shared pipeline unwrapping utils', () => { + describe('unwrapGroups', () => { + it('takes stages without nodes and returns the unwrapped groups', () => { + expect(unwrapGroups(stagesAndGroups)[0].groups).toEqual(groupsArray); + }); + + it('keeps other stage properties intact', () => { + expect(unwrapGroups(stagesAndGroups)[0]).toMatchObject(basicStageInfo); + }); + }); + + describe('unwrapNodesWithName', () => { + it('works with no field argument', () => { + expect(unwrapNodesWithName(jobArrayWithNeeds, 'needs')[0].needs).toEqual([needArray[0].name]); + }); + + it('works with custom field argument', () => { + expect(unwrapNodesWithName(jobArrayWithElephant, 'needs', 'elephant')[0].needs).toEqual([ + elephantArray[0].elephant, + ]); + }); + }); + + describe('unwrapStagesWithNeeds', () => { + it('removes nodes from groups, jobs, and needs', () => { + const firstProcessedGroup = unwrapStagesWithNeeds(completeMock)[0].groups[0]; + expect(firstProcessedGroup).toMatchObject(groupsArray[0]); + expect(firstProcessedGroup.jobs[0]).toMatchObject(baseJobs); + expect(firstProcessedGroup.jobs[0].needs[0]).toBe(needArray[0].name); + }); + }); +}); |