summaryrefslogtreecommitdiff
path: root/spec/frontend/releases/stores/modules
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-14 21:09:08 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-14 21:09:08 +0000
commit866ca4e49ff74ffadf8e6f6ff663a168489c2aba (patch)
treecc3135b1bae11dbd1cb3a30cb547473ad89a5551 /spec/frontend/releases/stores/modules
parent26a50872e9da9509c52c70f74dc21698fec906db (diff)
downloadgitlab-ce-866ca4e49ff74ffadf8e6f6ff663a168489c2aba.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/releases/stores/modules')
-rw-r--r--spec/frontend/releases/stores/modules/detail/actions_spec.js217
-rw-r--r--spec/frontend/releases/stores/modules/detail/mutations_spec.js119
2 files changed, 336 insertions, 0 deletions
diff --git a/spec/frontend/releases/stores/modules/detail/actions_spec.js b/spec/frontend/releases/stores/modules/detail/actions_spec.js
new file mode 100644
index 00000000000..0c2763822c9
--- /dev/null
+++ b/spec/frontend/releases/stores/modules/detail/actions_spec.js
@@ -0,0 +1,217 @@
+import axios from 'axios';
+import MockAdapter from 'axios-mock-adapter';
+import testAction from 'helpers/vuex_action_helper';
+import * as actions from '~/releases/stores/modules/detail/actions';
+import * as types from '~/releases/stores/modules/detail/mutation_types';
+import { release } from '../../../mock_data';
+import state from '~/releases/stores/modules/detail/state';
+import createFlash from '~/flash';
+import { redirectTo } from '~/lib/utils/url_utility';
+import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
+
+jest.mock('~/flash', () => jest.fn());
+
+jest.mock('~/lib/utils/url_utility', () => ({
+ redirectTo: jest.fn(),
+ joinPaths: jest.requireActual('~/lib/utils/url_utility').joinPaths,
+}));
+
+describe('Release detail actions', () => {
+ let stateClone;
+ let releaseClone;
+ let mock;
+ let error;
+
+ beforeEach(() => {
+ stateClone = state();
+ releaseClone = JSON.parse(JSON.stringify(release));
+ mock = new MockAdapter(axios);
+ gon.api_version = 'v4';
+ error = { message: 'An error occurred' };
+ createFlash.mockClear();
+ });
+
+ afterEach(() => {
+ mock.restore();
+ });
+
+ describe('setInitialState', () => {
+ it(`commits ${types.SET_INITIAL_STATE} with the provided object`, () => {
+ const initialState = {};
+
+ return testAction(actions.setInitialState, initialState, stateClone, [
+ { type: types.SET_INITIAL_STATE, payload: initialState },
+ ]);
+ });
+ });
+
+ describe('requestRelease', () => {
+ it(`commits ${types.REQUEST_RELEASE}`, () =>
+ testAction(actions.requestRelease, undefined, stateClone, [{ type: types.REQUEST_RELEASE }]));
+ });
+
+ describe('receiveReleaseSuccess', () => {
+ it(`commits ${types.RECEIVE_RELEASE_SUCCESS}`, () =>
+ testAction(actions.receiveReleaseSuccess, releaseClone, stateClone, [
+ { type: types.RECEIVE_RELEASE_SUCCESS, payload: releaseClone },
+ ]));
+ });
+
+ describe('receiveReleaseError', () => {
+ it(`commits ${types.RECEIVE_RELEASE_ERROR}`, () =>
+ testAction(actions.receiveReleaseError, error, stateClone, [
+ { type: types.RECEIVE_RELEASE_ERROR, payload: error },
+ ]));
+
+ it('shows a flash with an error message', () => {
+ actions.receiveReleaseError({ commit: jest.fn() }, error);
+
+ expect(createFlash).toHaveBeenCalledTimes(1);
+ expect(createFlash).toHaveBeenCalledWith(
+ 'Something went wrong while getting the release details',
+ );
+ });
+ });
+
+ describe('fetchRelease', () => {
+ let getReleaseUrl;
+
+ beforeEach(() => {
+ stateClone.projectId = '18';
+ stateClone.tagName = 'v1.3';
+ getReleaseUrl = `/api/v4/projects/${stateClone.projectId}/releases/${stateClone.tagName}`;
+ });
+
+ it(`dispatches requestRelease and receiveReleaseSuccess with the camel-case'd release object`, () => {
+ mock.onGet(getReleaseUrl).replyOnce(200, releaseClone);
+
+ return testAction(
+ actions.fetchRelease,
+ undefined,
+ stateClone,
+ [],
+ [
+ { type: 'requestRelease' },
+ {
+ type: 'receiveReleaseSuccess',
+ payload: convertObjectPropsToCamelCase(releaseClone, { deep: true }),
+ },
+ ],
+ );
+ });
+
+ it(`dispatches requestRelease and receiveReleaseError with an error object`, () => {
+ mock.onGet(getReleaseUrl).replyOnce(500);
+
+ return testAction(
+ actions.fetchRelease,
+ undefined,
+ stateClone,
+ [],
+ [{ type: 'requestRelease' }, { type: 'receiveReleaseError', payload: expect.anything() }],
+ );
+ });
+ });
+
+ describe('updateReleaseTitle', () => {
+ it(`commits ${types.UPDATE_RELEASE_TITLE} with the updated release title`, () => {
+ const newTitle = 'The new release title';
+ return testAction(actions.updateReleaseTitle, newTitle, stateClone, [
+ { type: types.UPDATE_RELEASE_TITLE, payload: newTitle },
+ ]);
+ });
+ });
+
+ describe('updateReleaseNotes', () => {
+ it(`commits ${types.UPDATE_RELEASE_NOTES} with the updated release notes`, () => {
+ const newReleaseNotes = 'The new release notes';
+ return testAction(actions.updateReleaseNotes, newReleaseNotes, stateClone, [
+ { type: types.UPDATE_RELEASE_NOTES, payload: newReleaseNotes },
+ ]);
+ });
+ });
+
+ describe('requestUpdateRelease', () => {
+ it(`commits ${types.REQUEST_UPDATE_RELEASE}`, () =>
+ testAction(actions.requestUpdateRelease, undefined, stateClone, [
+ { type: types.REQUEST_UPDATE_RELEASE },
+ ]));
+ });
+
+ describe('receiveUpdateReleaseSuccess', () => {
+ it(`commits ${types.RECEIVE_UPDATE_RELEASE_SUCCESS}`, () =>
+ testAction(
+ actions.receiveUpdateReleaseSuccess,
+ undefined,
+ stateClone,
+ [{ type: types.RECEIVE_UPDATE_RELEASE_SUCCESS }],
+ [{ type: 'navigateToReleasesPage' }],
+ ));
+ });
+
+ describe('receiveUpdateReleaseError', () => {
+ it(`commits ${types.RECEIVE_UPDATE_RELEASE_ERROR}`, () =>
+ testAction(actions.receiveUpdateReleaseError, error, stateClone, [
+ { type: types.RECEIVE_UPDATE_RELEASE_ERROR, payload: error },
+ ]));
+
+ it('shows a flash with an error message', () => {
+ actions.receiveUpdateReleaseError({ commit: jest.fn() }, error);
+
+ expect(createFlash).toHaveBeenCalledTimes(1);
+ expect(createFlash).toHaveBeenCalledWith(
+ 'Something went wrong while saving the release details',
+ );
+ });
+ });
+
+ describe('updateRelease', () => {
+ let getReleaseUrl;
+
+ beforeEach(() => {
+ stateClone.release = releaseClone;
+ stateClone.projectId = '18';
+ stateClone.tagName = 'v1.3';
+ getReleaseUrl = `/api/v4/projects/${stateClone.projectId}/releases/${stateClone.tagName}`;
+ });
+
+ it(`dispatches requestUpdateRelease and receiveUpdateReleaseSuccess`, () => {
+ mock.onPut(getReleaseUrl).replyOnce(200);
+
+ return testAction(
+ actions.updateRelease,
+ undefined,
+ stateClone,
+ [],
+ [{ type: 'requestUpdateRelease' }, { type: 'receiveUpdateReleaseSuccess' }],
+ );
+ });
+
+ it(`dispatches requestUpdateRelease and receiveUpdateReleaseError with an error object`, () => {
+ mock.onPut(getReleaseUrl).replyOnce(500);
+
+ return testAction(
+ actions.updateRelease,
+ undefined,
+ stateClone,
+ [],
+ [
+ { type: 'requestUpdateRelease' },
+ { type: 'receiveUpdateReleaseError', payload: expect.anything() },
+ ],
+ );
+ });
+ });
+
+ describe('navigateToReleasesPage', () => {
+ it(`calls redirectTo() with the URL to the releases page`, () => {
+ const releasesPagePath = 'path/to/releases/page';
+ stateClone.releasesPagePath = releasesPagePath;
+
+ actions.navigateToReleasesPage({ state: stateClone });
+
+ expect(redirectTo).toHaveBeenCalledTimes(1);
+ expect(redirectTo).toHaveBeenCalledWith(releasesPagePath);
+ });
+ });
+});
diff --git a/spec/frontend/releases/stores/modules/detail/mutations_spec.js b/spec/frontend/releases/stores/modules/detail/mutations_spec.js
new file mode 100644
index 00000000000..81b2dde75ab
--- /dev/null
+++ b/spec/frontend/releases/stores/modules/detail/mutations_spec.js
@@ -0,0 +1,119 @@
+/* eslint-disable jest/valid-describe */
+/*
+ * ESLint disable directive ↑ can be removed once
+ * https://github.com/jest-community/eslint-plugin-jest/issues/203
+ * is resolved
+ */
+
+import state from '~/releases/stores/modules/detail/state';
+import mutations from '~/releases/stores/modules/detail/mutations';
+import * as types from '~/releases/stores/modules/detail/mutation_types';
+import { release } from '../../../mock_data';
+
+describe('Release detail mutations', () => {
+ let stateClone;
+ let releaseClone;
+
+ beforeEach(() => {
+ stateClone = state();
+ releaseClone = JSON.parse(JSON.stringify(release));
+ });
+
+ describe(types.SET_INITIAL_STATE, () => {
+ it('populates the state with initial values', () => {
+ const initialState = {
+ projectId: '18',
+ tagName: 'v1.3',
+ releasesPagePath: 'path/to/releases/page',
+ markdownDocsPath: 'path/to/markdown/docs',
+ markdownPreviewPath: 'path/to/markdown/preview',
+ };
+
+ mutations[types.SET_INITIAL_STATE](stateClone, initialState);
+
+ expect(stateClone).toEqual(expect.objectContaining(initialState));
+ });
+ });
+
+ describe(types.REQUEST_RELEASE, () => {
+ it('set state.isFetchingRelease to true', () => {
+ mutations[types.REQUEST_RELEASE](stateClone);
+
+ expect(stateClone.isFetchingRelease).toEqual(true);
+ });
+ });
+
+ describe(types.RECEIVE_RELEASE_SUCCESS, () => {
+ it('handles a successful response from the server', () => {
+ mutations[types.RECEIVE_RELEASE_SUCCESS](stateClone, releaseClone);
+
+ expect(stateClone.fetchError).toEqual(undefined);
+
+ expect(stateClone.isFetchingRelease).toEqual(false);
+
+ expect(stateClone.release).toEqual(releaseClone);
+ });
+ });
+
+ describe(types.RECEIVE_RELEASE_ERROR, () => {
+ it('handles an unsuccessful response from the server', () => {
+ const error = { message: 'An error occurred!' };
+ mutations[types.RECEIVE_RELEASE_ERROR](stateClone, error);
+
+ expect(stateClone.isFetchingRelease).toEqual(false);
+
+ expect(stateClone.release).toBeUndefined();
+
+ expect(stateClone.fetchError).toEqual(error);
+ });
+ });
+
+ describe(types.UPDATE_RELEASE_TITLE, () => {
+ it("updates the release's title", () => {
+ stateClone.release = releaseClone;
+ const newTitle = 'The new release title';
+ mutations[types.UPDATE_RELEASE_TITLE](stateClone, newTitle);
+
+ expect(stateClone.release.name).toEqual(newTitle);
+ });
+ });
+
+ describe(types.UPDATE_RELEASE_NOTES, () => {
+ it("updates the release's notes", () => {
+ stateClone.release = releaseClone;
+ const newNotes = 'The new release notes';
+ mutations[types.UPDATE_RELEASE_NOTES](stateClone, newNotes);
+
+ expect(stateClone.release.description).toEqual(newNotes);
+ });
+ });
+
+ describe(types.REQUEST_UPDATE_RELEASE, () => {
+ it('set state.isUpdatingRelease to true', () => {
+ mutations[types.REQUEST_UPDATE_RELEASE](stateClone);
+
+ expect(stateClone.isUpdatingRelease).toEqual(true);
+ });
+ });
+
+ describe(types.RECEIVE_UPDATE_RELEASE_SUCCESS, () => {
+ it('handles a successful response from the server', () => {
+ mutations[types.RECEIVE_UPDATE_RELEASE_SUCCESS](stateClone, releaseClone);
+
+ expect(stateClone.updateError).toEqual(undefined);
+
+ expect(stateClone.isUpdatingRelease).toEqual(false);
+ });
+ });
+
+ describe(types.RECEIVE_UPDATE_RELEASE_ERROR, () => {
+ it('handles an unsuccessful response from the server', () => {
+ const error = { message: 'An error occurred!' };
+ mutations[types.RECEIVE_UPDATE_RELEASE_ERROR](stateClone, error);
+
+ expect(stateClone.isUpdatingRelease).toEqual(false);
+
+ expect(stateClone.updateError).toEqual(error);
+ });
+ });
+});