diff options
Diffstat (limited to 'spec/frontend/releases/stores/modules')
5 files changed, 270 insertions, 12 deletions
diff --git a/spec/frontend/releases/stores/modules/detail/actions_spec.js b/spec/frontend/releases/stores/modules/detail/actions_spec.js index 854f06821be..345be2acc71 100644 --- a/spec/frontend/releases/stores/modules/detail/actions_spec.js +++ b/spec/frontend/releases/stores/modules/detail/actions_spec.js @@ -10,6 +10,7 @@ import createFlash from '~/flash'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { redirectTo } from '~/lib/utils/url_utility'; import api from '~/api'; +import { ASSET_LINK_TYPE } from '~/releases/constants'; jest.mock('~/flash', () => jest.fn()); @@ -130,6 +131,54 @@ describe('Release detail actions', () => { }); }); + describe('updateAssetLinkUrl', () => { + it(`commits ${types.UPDATE_ASSET_LINK_URL} with the updated link URL`, () => { + const params = { + linkIdToUpdate: 2, + newUrl: 'https://example.com/updated', + }; + + return testAction(actions.updateAssetLinkUrl, params, state, [ + { type: types.UPDATE_ASSET_LINK_URL, payload: params }, + ]); + }); + }); + + describe('updateAssetLinkName', () => { + it(`commits ${types.UPDATE_ASSET_LINK_NAME} with the updated link name`, () => { + const params = { + linkIdToUpdate: 2, + newName: 'Updated link name', + }; + + return testAction(actions.updateAssetLinkName, params, state, [ + { type: types.UPDATE_ASSET_LINK_NAME, payload: params }, + ]); + }); + }); + + describe('updateAssetLinkType', () => { + it(`commits ${types.UPDATE_ASSET_LINK_TYPE} with the updated link type`, () => { + const params = { + linkIdToUpdate: 2, + newType: ASSET_LINK_TYPE.RUNBOOK, + }; + + return testAction(actions.updateAssetLinkType, params, state, [ + { type: types.UPDATE_ASSET_LINK_TYPE, payload: params }, + ]); + }); + }); + + describe('removeAssetLink', () => { + it(`commits ${types.REMOVE_ASSET_LINK} with the ID of the asset link to remove`, () => { + const idToRemove = 2; + return testAction(actions.removeAssetLink, idToRemove, state, [ + { type: types.REMOVE_ASSET_LINK, payload: idToRemove }, + ]); + }); + }); + describe('updateReleaseMilestones', () => { it(`commits ${types.UPDATE_RELEASE_MILESTONES} with the updated release milestones`, () => { const newReleaseMilestones = ['v0.0', 'v0.1']; diff --git a/spec/frontend/releases/stores/modules/detail/mutations_spec.js b/spec/frontend/releases/stores/modules/detail/mutations_spec.js index f3f7ca797b4..a34c1be64d9 100644 --- a/spec/frontend/releases/stores/modules/detail/mutations_spec.js +++ b/spec/frontend/releases/stores/modules/detail/mutations_spec.js @@ -3,6 +3,7 @@ import mutations from '~/releases/stores/modules/detail/mutations'; import * as types from '~/releases/stores/modules/detail/mutation_types'; import { release as originalRelease } from '../../../mock_data'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; +import { ASSET_LINK_TYPE, DEFAULT_ASSET_LINK_TYPE } from '~/releases/constants'; describe('Release detail mutations', () => { let state; @@ -24,7 +25,7 @@ describe('Release detail mutations', () => { it('set state.isFetchingRelease to true', () => { mutations[types.REQUEST_RELEASE](state); - expect(state.isFetchingRelease).toEqual(true); + expect(state.isFetchingRelease).toBe(true); }); }); @@ -32,9 +33,9 @@ describe('Release detail mutations', () => { it('handles a successful response from the server', () => { mutations[types.RECEIVE_RELEASE_SUCCESS](state, release); - expect(state.fetchError).toEqual(undefined); + expect(state.fetchError).toBeUndefined(); - expect(state.isFetchingRelease).toEqual(false); + expect(state.isFetchingRelease).toBe(false); expect(state.release).toEqual(release); @@ -47,7 +48,7 @@ describe('Release detail mutations', () => { const error = { message: 'An error occurred!' }; mutations[types.RECEIVE_RELEASE_ERROR](state, error); - expect(state.isFetchingRelease).toEqual(false); + expect(state.isFetchingRelease).toBe(false); expect(state.release).toBeUndefined(); @@ -61,7 +62,7 @@ describe('Release detail mutations', () => { const newTitle = 'The new release title'; mutations[types.UPDATE_RELEASE_TITLE](state, newTitle); - expect(state.release.name).toEqual(newTitle); + expect(state.release.name).toBe(newTitle); }); }); @@ -71,7 +72,7 @@ describe('Release detail mutations', () => { const newNotes = 'The new release notes'; mutations[types.UPDATE_RELEASE_NOTES](state, newNotes); - expect(state.release.description).toEqual(newNotes); + expect(state.release.description).toBe(newNotes); }); }); @@ -79,7 +80,7 @@ describe('Release detail mutations', () => { it('set state.isUpdatingRelease to true', () => { mutations[types.REQUEST_UPDATE_RELEASE](state); - expect(state.isUpdatingRelease).toEqual(true); + expect(state.isUpdatingRelease).toBe(true); }); }); @@ -87,9 +88,9 @@ describe('Release detail mutations', () => { it('handles a successful response from the server', () => { mutations[types.RECEIVE_UPDATE_RELEASE_SUCCESS](state, release); - expect(state.updateError).toEqual(undefined); + expect(state.updateError).toBeUndefined(); - expect(state.isUpdatingRelease).toEqual(false); + expect(state.isUpdatingRelease).toBe(false); }); }); @@ -98,7 +99,7 @@ describe('Release detail mutations', () => { const error = { message: 'An error occurred!' }; mutations[types.RECEIVE_UPDATE_RELEASE_ERROR](state, error); - expect(state.isUpdatingRelease).toEqual(false); + expect(state.isUpdatingRelease).toBe(false); expect(state.updateError).toEqual(error); }); @@ -118,6 +119,7 @@ describe('Release detail mutations', () => { id: expect.stringMatching(/^new-link-/), url: '', name: '', + linkType: DEFAULT_ASSET_LINK_TYPE, }, ]); }); @@ -134,7 +136,7 @@ describe('Release detail mutations', () => { newUrl, }); - expect(state.release.assets.links[0].url).toEqual(newUrl); + expect(state.release.assets.links[0].url).toBe(newUrl); }); }); @@ -149,7 +151,22 @@ describe('Release detail mutations', () => { newName, }); - expect(state.release.assets.links[0].name).toEqual(newName); + expect(state.release.assets.links[0].name).toBe(newName); + }); + }); + + describe(`${types.UPDATE_ASSET_LINK_TYPE}`, () => { + it('updates an asset link with a new type', () => { + state.release = release; + + const newType = ASSET_LINK_TYPE.RUNBOOK; + + mutations[types.UPDATE_ASSET_LINK_TYPE](state, { + linkIdToUpdate: state.release.assets.links[0].id, + newType, + }); + + expect(state.release.assets.links[0].linkType).toBe(newType); }); }); diff --git a/spec/frontend/releases/stores/modules/list/actions_spec.js b/spec/frontend/releases/stores/modules/list/actions_spec.js new file mode 100644 index 00000000000..4c3af157684 --- /dev/null +++ b/spec/frontend/releases/stores/modules/list/actions_spec.js @@ -0,0 +1,131 @@ +import testAction from 'helpers/vuex_action_helper'; +import { + requestReleases, + fetchReleases, + receiveReleasesSuccess, + receiveReleasesError, +} from '~/releases/stores/modules/list/actions'; +import state from '~/releases/stores/modules/list/state'; +import * as types from '~/releases/stores/modules/list/mutation_types'; +import api from '~/api'; +import { parseIntPagination, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; +import { pageInfoHeadersWithoutPagination, releases as originalReleases } from '../../../mock_data'; + +describe('Releases State actions', () => { + let mockedState; + let pageInfo; + let releases; + + beforeEach(() => { + mockedState = state(); + pageInfo = parseIntPagination(pageInfoHeadersWithoutPagination); + releases = convertObjectPropsToCamelCase(originalReleases, { deep: true }); + }); + + describe('requestReleases', () => { + it('should commit REQUEST_RELEASES mutation', done => { + testAction(requestReleases, null, mockedState, [{ type: types.REQUEST_RELEASES }], [], done); + }); + }); + + describe('fetchReleases', () => { + describe('success', () => { + it('dispatches requestReleases and receiveReleasesSuccess', done => { + jest.spyOn(api, 'releases').mockImplementation((id, options) => { + expect(id).toEqual(1); + expect(options.page).toEqual('1'); + return Promise.resolve({ data: releases, headers: pageInfoHeadersWithoutPagination }); + }); + + testAction( + fetchReleases, + { projectId: 1 }, + mockedState, + [], + [ + { + type: 'requestReleases', + }, + { + payload: { data: releases, headers: pageInfoHeadersWithoutPagination }, + type: 'receiveReleasesSuccess', + }, + ], + done, + ); + }); + + it('dispatches requestReleases and receiveReleasesSuccess on page two', done => { + jest.spyOn(api, 'releases').mockImplementation((_, options) => { + expect(options.page).toEqual('2'); + return Promise.resolve({ data: releases, headers: pageInfoHeadersWithoutPagination }); + }); + + testAction( + fetchReleases, + { page: '2', projectId: 1 }, + mockedState, + [], + [ + { + type: 'requestReleases', + }, + { + payload: { data: releases, headers: pageInfoHeadersWithoutPagination }, + type: 'receiveReleasesSuccess', + }, + ], + done, + ); + }); + }); + + describe('error', () => { + it('dispatches requestReleases and receiveReleasesError', done => { + jest.spyOn(api, 'releases').mockReturnValue(Promise.reject()); + + testAction( + fetchReleases, + { projectId: null }, + mockedState, + [], + [ + { + type: 'requestReleases', + }, + { + type: 'receiveReleasesError', + }, + ], + done, + ); + }); + }); + }); + + describe('receiveReleasesSuccess', () => { + it('should commit RECEIVE_RELEASES_SUCCESS mutation', done => { + testAction( + receiveReleasesSuccess, + { data: releases, headers: pageInfoHeadersWithoutPagination }, + mockedState, + [{ type: types.RECEIVE_RELEASES_SUCCESS, payload: { pageInfo, data: releases } }], + [], + done, + ); + }); + }); + + describe('receiveReleasesError', () => { + it('should commit RECEIVE_RELEASES_ERROR mutation', done => { + testAction( + receiveReleasesError, + null, + mockedState, + [{ type: types.RECEIVE_RELEASES_ERROR }], + [], + done, + ); + }); + }); +}); diff --git a/spec/frontend/releases/stores/modules/list/helpers.js b/spec/frontend/releases/stores/modules/list/helpers.js new file mode 100644 index 00000000000..435ca36047e --- /dev/null +++ b/spec/frontend/releases/stores/modules/list/helpers.js @@ -0,0 +1,6 @@ +import state from '~/releases/stores/modules/list/state'; + +// eslint-disable-next-line import/prefer-default-export +export const resetStore = store => { + store.replaceState(state()); +}; diff --git a/spec/frontend/releases/stores/modules/list/mutations_spec.js b/spec/frontend/releases/stores/modules/list/mutations_spec.js new file mode 100644 index 00000000000..3035b916ff6 --- /dev/null +++ b/spec/frontend/releases/stores/modules/list/mutations_spec.js @@ -0,0 +1,55 @@ +import state from '~/releases/stores/modules/list/state'; +import mutations from '~/releases/stores/modules/list/mutations'; +import * as types from '~/releases/stores/modules/list/mutation_types'; +import { parseIntPagination } from '~/lib/utils/common_utils'; +import { pageInfoHeadersWithoutPagination, releases } from '../../../mock_data'; + +describe('Releases Store Mutations', () => { + let stateCopy; + let pageInfo; + + beforeEach(() => { + stateCopy = state(); + pageInfo = parseIntPagination(pageInfoHeadersWithoutPagination); + }); + + describe('REQUEST_RELEASES', () => { + it('sets isLoading to true', () => { + mutations[types.REQUEST_RELEASES](stateCopy); + + expect(stateCopy.isLoading).toEqual(true); + }); + }); + + describe('RECEIVE_RELEASES_SUCCESS', () => { + beforeEach(() => { + mutations[types.RECEIVE_RELEASES_SUCCESS](stateCopy, { pageInfo, data: releases }); + }); + + it('sets is loading to false', () => { + expect(stateCopy.isLoading).toEqual(false); + }); + + it('sets hasError to false', () => { + expect(stateCopy.hasError).toEqual(false); + }); + + it('sets data', () => { + expect(stateCopy.releases).toEqual(releases); + }); + + it('sets pageInfo', () => { + expect(stateCopy.pageInfo).toEqual(pageInfo); + }); + }); + + describe('RECEIVE_RELEASES_ERROR', () => { + it('resets data', () => { + mutations[types.RECEIVE_RELEASES_ERROR](stateCopy); + + expect(stateCopy.isLoading).toEqual(false); + expect(stateCopy.releases).toEqual([]); + expect(stateCopy.pageInfo).toEqual({}); + }); + }); +}); |