summaryrefslogtreecommitdiff
path: root/spec/frontend/feature_flags/store/gitlab_user_lists
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/feature_flags/store/gitlab_user_lists')
-rw-r--r--spec/frontend/feature_flags/store/gitlab_user_lists/actions_spec.js60
-rw-r--r--spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js69
-rw-r--r--spec/frontend/feature_flags/store/gitlab_user_lists/mutations_spec.js50
3 files changed, 179 insertions, 0 deletions
diff --git a/spec/frontend/feature_flags/store/gitlab_user_lists/actions_spec.js b/spec/frontend/feature_flags/store/gitlab_user_lists/actions_spec.js
new file mode 100644
index 00000000000..aba578cca59
--- /dev/null
+++ b/spec/frontend/feature_flags/store/gitlab_user_lists/actions_spec.js
@@ -0,0 +1,60 @@
+import testAction from 'helpers/vuex_action_helper';
+import Api from '~/api';
+import createState from '~/feature_flags/store/gitlab_user_list/state';
+import { fetchUserLists, setFilter } from '~/feature_flags/store/gitlab_user_list/actions';
+import * as types from '~/feature_flags/store/gitlab_user_list/mutation_types';
+import { userList } from '../../mock_data';
+
+jest.mock('~/api');
+
+describe('~/feature_flags/store/gitlab_user_list/actions', () => {
+ let mockedState;
+
+ beforeEach(() => {
+ mockedState = createState({ projectId: '1' });
+ mockedState.filter = 'test';
+ });
+
+ describe('fetchUserLists', () => {
+ it('should commit FETCH_USER_LISTS and RECEIEVE_USER_LISTS_SUCCESS on success', () => {
+ Api.searchFeatureFlagUserLists.mockResolvedValue({ data: [userList] });
+ return testAction(
+ fetchUserLists,
+ undefined,
+ mockedState,
+ [
+ { type: types.FETCH_USER_LISTS },
+ { type: types.RECEIVE_USER_LISTS_SUCCESS, payload: [userList] },
+ ],
+ [],
+ () => expect(Api.searchFeatureFlagUserLists).toHaveBeenCalledWith('1', 'test'),
+ );
+ });
+
+ it('should commit FETCH_USER_LISTS and RECEIEVE_USER_LISTS_ERROR on success', () => {
+ Api.searchFeatureFlagUserLists.mockRejectedValue({ message: 'error' });
+ return testAction(
+ fetchUserLists,
+ undefined,
+ mockedState,
+ [
+ { type: types.FETCH_USER_LISTS },
+ { type: types.RECEIVE_USER_LISTS_ERROR, payload: ['error'] },
+ ],
+ [],
+ () => expect(Api.searchFeatureFlagUserLists).toHaveBeenCalledWith('1', 'test'),
+ );
+ });
+ });
+
+ describe('setFilter', () => {
+ it('commits SET_FILTER and fetches new user lists', () =>
+ testAction(
+ setFilter,
+ 'filter',
+ mockedState,
+ [{ type: types.SET_FILTER, payload: 'filter' }],
+ [{ type: 'fetchUserLists' }],
+ ));
+ });
+});
diff --git a/spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js b/spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js
new file mode 100644
index 00000000000..e267cd59f50
--- /dev/null
+++ b/spec/frontend/feature_flags/store/gitlab_user_lists/getters_spec.js
@@ -0,0 +1,69 @@
+import {
+ userListOptions,
+ hasUserLists,
+ isLoading,
+ hasError,
+} from '~/feature_flags/store/gitlab_user_list/getters';
+import statuses from '~/feature_flags/store/gitlab_user_list/status';
+import createState from '~/feature_flags/store/gitlab_user_list/state';
+import { userList } from '../../mock_data';
+
+describe('~/feature_flags/store/gitlab_user_list/getters', () => {
+ let mockedState;
+
+ beforeEach(() => {
+ mockedState = createState({ projectId: '8' });
+ mockedState.userLists = [userList];
+ });
+
+ describe('userListOption', () => {
+ it('should return user lists in a way usable by a dropdown', () => {
+ expect(userListOptions(mockedState)).toEqual([{ value: userList.id, text: userList.name }]);
+ });
+
+ it('should return an empty array if there are no lists', () => {
+ mockedState.userLists = [];
+ expect(userListOptions(mockedState)).toEqual([]);
+ });
+ });
+
+ describe('hasUserLists', () => {
+ it.each`
+ userLists | status | result
+ ${[userList]} | ${statuses.IDLE} | ${true}
+ ${[]} | ${statuses.IDLE} | ${false}
+ ${[]} | ${statuses.START} | ${true}
+ `(
+ 'should return $result if there are $userLists.length user lists and the status is $status',
+ ({ userLists, status, result }) => {
+ mockedState.userLists = userLists;
+ mockedState.status = status;
+ expect(hasUserLists(mockedState)).toBe(result);
+ },
+ );
+ });
+
+ describe('isLoading', () => {
+ it.each`
+ status | result
+ ${statuses.LOADING} | ${true}
+ ${statuses.ERROR} | ${false}
+ ${statuses.IDLE} | ${false}
+ `('should return $result if the status is "$status"', ({ status, result }) => {
+ mockedState.status = status;
+ expect(isLoading(mockedState)).toBe(result);
+ });
+ });
+
+ describe('hasError', () => {
+ it.each`
+ status | result
+ ${statuses.LOADING} | ${false}
+ ${statuses.ERROR} | ${true}
+ ${statuses.IDLE} | ${false}
+ `('should return $result if the status is "$status"', ({ status, result }) => {
+ mockedState.status = status;
+ expect(hasError(mockedState)).toBe(result);
+ });
+ });
+});
diff --git a/spec/frontend/feature_flags/store/gitlab_user_lists/mutations_spec.js b/spec/frontend/feature_flags/store/gitlab_user_lists/mutations_spec.js
new file mode 100644
index 00000000000..88d4554a227
--- /dev/null
+++ b/spec/frontend/feature_flags/store/gitlab_user_lists/mutations_spec.js
@@ -0,0 +1,50 @@
+import statuses from '~/feature_flags/store/gitlab_user_list/status';
+import createState from '~/feature_flags/store/gitlab_user_list/state';
+import * as types from '~/feature_flags/store/gitlab_user_list/mutation_types';
+import mutations from '~/feature_flags/store/gitlab_user_list/mutations';
+import { userList } from '../../mock_data';
+
+describe('~/feature_flags/store/gitlab_user_list/mutations', () => {
+ let state;
+
+ beforeEach(() => {
+ state = createState({ projectId: '8' });
+ });
+
+ describe(types.SET_FILTER, () => {
+ it('sets the filter in the state', () => {
+ mutations[types.SET_FILTER](state, 'test');
+ expect(state.filter).toBe('test');
+ });
+ });
+
+ describe(types.FETCH_USER_LISTS, () => {
+ it('sets the status to loading', () => {
+ mutations[types.FETCH_USER_LISTS](state);
+ expect(state.status).toBe(statuses.LOADING);
+ });
+ });
+
+ describe(types.RECEIVE_USER_LISTS_SUCCESS, () => {
+ it('sets the user lists to the ones received', () => {
+ mutations[types.RECEIVE_USER_LISTS_SUCCESS](state, [userList]);
+ expect(state.userLists).toEqual([userList]);
+ });
+
+ it('sets the status to idle', () => {
+ mutations[types.RECEIVE_USER_LISTS_SUCCESS](state, [userList]);
+ expect(state.status).toBe(statuses.IDLE);
+ });
+ });
+ describe(types.RECEIVE_USER_LISTS_ERROR, () => {
+ it('sets the status to error', () => {
+ mutations[types.RECEIVE_USER_LISTS_ERROR](state, 'failure');
+ expect(state.status).toBe(statuses.ERROR);
+ });
+
+ it('sets the error message', () => {
+ mutations[types.RECEIVE_USER_LISTS_ERROR](state, 'failure');
+ expect(state.error).toBe('failure');
+ });
+ });
+});