Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/vuex_shared')
-rw-r--r--spec/frontend/vuex_shared/modules/members/actions_spec.js110
-rw-r--r--spec/frontend/vuex_shared/modules/members/mutations_spec.js90
-rw-r--r--spec/frontend/vuex_shared/modules/members/utils_spec.js14
3 files changed, 214 insertions, 0 deletions
diff --git a/spec/frontend/vuex_shared/modules/members/actions_spec.js b/spec/frontend/vuex_shared/modules/members/actions_spec.js
new file mode 100644
index 00000000000..833bd4cc175
--- /dev/null
+++ b/spec/frontend/vuex_shared/modules/members/actions_spec.js
@@ -0,0 +1,110 @@
+import { noop } from 'lodash';
+import axios from 'axios';
+import MockAdapter from 'axios-mock-adapter';
+import { members, group } from 'jest/vue_shared/components/members/mock_data';
+import testAction from 'helpers/vuex_action_helper';
+import httpStatusCodes from '~/lib/utils/http_status';
+import * as types from '~/vuex_shared/modules/members/mutation_types';
+import {
+ updateMemberRole,
+ showRemoveGroupLinkModal,
+ hideRemoveGroupLinkModal,
+} from '~/vuex_shared/modules/members/actions';
+
+describe('Vuex members actions', () => {
+ let mock;
+
+ beforeEach(() => {
+ mock = new MockAdapter(axios);
+ });
+
+ afterEach(() => {
+ mock.restore();
+ });
+
+ describe('updateMemberRole', () => {
+ const memberId = members[0].id;
+ const accessLevel = { integerValue: 30, stringValue: 'Developer' };
+
+ const payload = {
+ memberId,
+ accessLevel,
+ };
+ const state = {
+ members,
+ memberPath: '/groups/foo-bar/-/group_members/:id',
+ requestFormatter: noop,
+ removeGroupLinkModalVisible: false,
+ groupLinkToRemove: null,
+ };
+
+ describe('successful request', () => {
+ it(`commits ${types.RECEIVE_MEMBER_ROLE_SUCCESS} mutation`, async () => {
+ let requestPath;
+ mock.onPut().replyOnce(config => {
+ requestPath = config.url;
+ return [httpStatusCodes.OK, {}];
+ });
+
+ await testAction(updateMemberRole, payload, state, [
+ {
+ type: types.RECEIVE_MEMBER_ROLE_SUCCESS,
+ payload,
+ },
+ ]);
+
+ expect(requestPath).toBe('/groups/foo-bar/-/group_members/238');
+ });
+ });
+
+ describe('unsuccessful request', () => {
+ beforeEach(() => {
+ mock.onPut().replyOnce(httpStatusCodes.BAD_REQUEST, { message: 'Bad request' });
+ });
+
+ it(`commits ${types.RECEIVE_MEMBER_ROLE_ERROR} mutation`, async () => {
+ try {
+ await testAction(updateMemberRole, payload, state, [
+ {
+ type: types.RECEIVE_MEMBER_ROLE_SUCCESS,
+ },
+ ]);
+ } catch {
+ // Do nothing
+ }
+ });
+
+ it('throws error', async () => {
+ await expect(testAction(updateMemberRole, payload, state)).rejects.toThrowError();
+ });
+ });
+ });
+
+ describe('Group Link Modal', () => {
+ const state = {
+ removeGroupLinkModalVisible: false,
+ groupLinkToRemove: null,
+ };
+
+ describe('showRemoveGroupLinkModal', () => {
+ it(`commits ${types.SHOW_REMOVE_GROUP_LINK_MODAL} mutation`, () => {
+ testAction(showRemoveGroupLinkModal, group, state, [
+ {
+ type: types.SHOW_REMOVE_GROUP_LINK_MODAL,
+ payload: group,
+ },
+ ]);
+ });
+ });
+
+ describe('hideRemoveGroupLinkModal', () => {
+ it(`commits ${types.HIDE_REMOVE_GROUP_LINK_MODAL} mutation`, () => {
+ testAction(hideRemoveGroupLinkModal, group, state, [
+ {
+ type: types.HIDE_REMOVE_GROUP_LINK_MODAL,
+ },
+ ]);
+ });
+ });
+ });
+});
diff --git a/spec/frontend/vuex_shared/modules/members/mutations_spec.js b/spec/frontend/vuex_shared/modules/members/mutations_spec.js
new file mode 100644
index 00000000000..7338b19cfc9
--- /dev/null
+++ b/spec/frontend/vuex_shared/modules/members/mutations_spec.js
@@ -0,0 +1,90 @@
+import { members, group } from 'jest/vue_shared/components/members/mock_data';
+import mutations from '~/vuex_shared/modules/members/mutations';
+import * as types from '~/vuex_shared/modules/members/mutation_types';
+
+describe('Vuex members mutations', () => {
+ describe(types.RECEIVE_MEMBER_ROLE_SUCCESS, () => {
+ it('updates member', () => {
+ const state = {
+ members,
+ };
+
+ const accessLevel = { integerValue: 30, stringValue: 'Developer' };
+
+ mutations[types.RECEIVE_MEMBER_ROLE_SUCCESS](state, {
+ memberId: members[0].id,
+ accessLevel,
+ });
+
+ expect(state.members[0].accessLevel).toEqual(accessLevel);
+ });
+ });
+
+ describe(types.RECEIVE_MEMBER_ROLE_ERROR, () => {
+ it('shows error message', () => {
+ const state = {
+ showError: false,
+ errorMessage: '',
+ };
+
+ mutations[types.RECEIVE_MEMBER_ROLE_ERROR](state);
+
+ expect(state.showError).toBe(true);
+ expect(state.errorMessage).toBe(
+ "An error occurred while updating the member's role, please try again.",
+ );
+ });
+ });
+
+ describe(types.HIDE_ERROR, () => {
+ it('sets `showError` to `false`', () => {
+ const state = {
+ showError: true,
+ errorMessage: 'foo bar',
+ };
+
+ mutations[types.HIDE_ERROR](state);
+
+ expect(state.showError).toBe(false);
+ });
+
+ it('sets `errorMessage` to an empty string', () => {
+ const state = {
+ showError: true,
+ errorMessage: 'foo bar',
+ };
+
+ mutations[types.HIDE_ERROR](state);
+
+ expect(state.errorMessage).toBe('');
+ });
+ });
+
+ describe(types.SHOW_REMOVE_GROUP_LINK_MODAL, () => {
+ it('sets `removeGroupLinkModalVisible` and `groupLinkToRemove`', () => {
+ const state = {
+ removeGroupLinkModalVisible: false,
+ groupLinkToRemove: null,
+ };
+
+ mutations[types.SHOW_REMOVE_GROUP_LINK_MODAL](state, group);
+
+ expect(state).toEqual({
+ removeGroupLinkModalVisible: true,
+ groupLinkToRemove: group,
+ });
+ });
+ });
+
+ describe(types.HIDE_REMOVE_GROUP_LINK_MODAL, () => {
+ it('sets `removeGroupLinkModalVisible` to `false`', () => {
+ const state = {
+ removeGroupLinkModalVisible: false,
+ };
+
+ mutations[types.HIDE_REMOVE_GROUP_LINK_MODAL](state);
+
+ expect(state.removeGroupLinkModalVisible).toBe(false);
+ });
+ });
+});
diff --git a/spec/frontend/vuex_shared/modules/members/utils_spec.js b/spec/frontend/vuex_shared/modules/members/utils_spec.js
new file mode 100644
index 00000000000..4fc3445dac0
--- /dev/null
+++ b/spec/frontend/vuex_shared/modules/members/utils_spec.js
@@ -0,0 +1,14 @@
+import { members } from 'jest/vue_shared/components/members/mock_data';
+import { findMember } from '~/vuex_shared/modules/members/utils';
+
+describe('Members Vuex utils', () => {
+ describe('findMember', () => {
+ it('finds member by ID', () => {
+ const state = {
+ members,
+ };
+
+ expect(findMember(state, members[0].id)).toEqual(members[0]);
+ });
+ });
+});