diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 18:25:58 +0000 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/frontend/feature_flags/store/index | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) | |
download | gitlab-ce-a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4.tar.gz |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/frontend/feature_flags/store/index')
-rw-r--r-- | spec/frontend/feature_flags/store/index/actions_spec.js | 165 | ||||
-rw-r--r-- | spec/frontend/feature_flags/store/index/mutations_spec.js | 94 |
2 files changed, 5 insertions, 254 deletions
diff --git a/spec/frontend/feature_flags/store/index/actions_spec.js b/spec/frontend/feature_flags/store/index/actions_spec.js index a7ab2e92cb2..ec311ef92a3 100644 --- a/spec/frontend/feature_flags/store/index/actions_spec.js +++ b/spec/frontend/feature_flags/store/index/actions_spec.js @@ -1,7 +1,6 @@ import MockAdapter from 'axios-mock-adapter'; import testAction from 'helpers/vuex_action_helper'; import { TEST_HOST } from 'spec/test_constants'; -import Api from '~/api'; import { mapToScopesViewModel } from '~/feature_flags/store/helpers'; import { requestFeatureFlags, @@ -17,18 +16,12 @@ import { updateFeatureFlag, receiveUpdateFeatureFlagSuccess, receiveUpdateFeatureFlagError, - requestUserLists, - receiveUserListsSuccess, - receiveUserListsError, - fetchUserLists, - deleteUserList, - receiveDeleteUserListError, clearAlert, } from '~/feature_flags/store/index/actions'; import * as types from '~/feature_flags/store/index/mutation_types'; import state from '~/feature_flags/store/index/state'; import axios from '~/lib/utils/axios_utils'; -import { getRequestData, rotateData, featureFlag, userList } from '../../mock_data'; +import { getRequestData, rotateData, featureFlag } from '../../mock_data'; jest.mock('~/api.js'); @@ -154,99 +147,6 @@ describe('Feature flags actions', () => { }); }); - describe('fetchUserLists', () => { - beforeEach(() => { - Api.fetchFeatureFlagUserLists.mockResolvedValue({ data: [userList], headers: {} }); - }); - - describe('success', () => { - it('dispatches requestUserLists and receiveUserListsSuccess ', (done) => { - testAction( - fetchUserLists, - null, - mockedState, - [], - [ - { - type: 'requestUserLists', - }, - { - payload: { data: [userList], headers: {} }, - type: 'receiveUserListsSuccess', - }, - ], - done, - ); - }); - }); - - describe('error', () => { - it('dispatches requestUserLists and receiveUserListsError ', (done) => { - Api.fetchFeatureFlagUserLists.mockRejectedValue(); - - testAction( - fetchUserLists, - null, - mockedState, - [], - [ - { - type: 'requestUserLists', - }, - { - type: 'receiveUserListsError', - }, - ], - done, - ); - }); - }); - }); - - describe('requestUserLists', () => { - it('should commit RECEIVE_USER_LISTS_SUCCESS mutation', (done) => { - testAction( - requestUserLists, - null, - mockedState, - [{ type: types.REQUEST_USER_LISTS }], - [], - done, - ); - }); - }); - - describe('receiveUserListsSuccess', () => { - it('should commit RECEIVE_USER_LISTS_SUCCESS mutation', (done) => { - testAction( - receiveUserListsSuccess, - { data: [userList], headers: {} }, - mockedState, - [ - { - type: types.RECEIVE_USER_LISTS_SUCCESS, - payload: { data: [userList], headers: {} }, - }, - ], - [], - done, - ); - }); - }); - - describe('receiveUserListsError', () => { - it('should commit RECEIVE_USER_LISTS_ERROR mutation', (done) => { - testAction( - receiveUserListsError, - null, - mockedState, - [{ type: types.RECEIVE_USER_LISTS_ERROR }], - [], - done, - ); - }); - }); - describe('rotateInstanceId', () => { let mock; @@ -482,69 +382,6 @@ describe('Feature flags actions', () => { ); }); }); - describe('deleteUserList', () => { - beforeEach(() => { - mockedState.userLists = [userList]; - }); - - describe('success', () => { - beforeEach(() => { - Api.deleteFeatureFlagUserList.mockResolvedValue(); - }); - - it('should refresh the user lists', (done) => { - testAction( - deleteUserList, - userList, - mockedState, - [], - [{ type: 'requestDeleteUserList', payload: userList }, { type: 'fetchUserLists' }], - done, - ); - }); - }); - - describe('error', () => { - beforeEach(() => { - Api.deleteFeatureFlagUserList.mockRejectedValue({ response: { data: 'some error' } }); - }); - - it('should dispatch receiveDeleteUserListError', (done) => { - testAction( - deleteUserList, - userList, - mockedState, - [], - [ - { type: 'requestDeleteUserList', payload: userList }, - { - type: 'receiveDeleteUserListError', - payload: { list: userList, error: 'some error' }, - }, - ], - done, - ); - }); - }); - }); - - describe('receiveDeleteUserListError', () => { - it('should commit RECEIVE_DELETE_USER_LIST_ERROR with the given list', (done) => { - testAction( - receiveDeleteUserListError, - { list: userList, error: 'mock error' }, - mockedState, - [ - { - type: 'RECEIVE_DELETE_USER_LIST_ERROR', - payload: { list: userList, error: 'mock error' }, - }, - ], - [], - done, - ); - }); - }); describe('clearAlert', () => { it('should commit RECEIVE_CLEAR_ALERT', (done) => { diff --git a/spec/frontend/feature_flags/store/index/mutations_spec.js b/spec/frontend/feature_flags/store/index/mutations_spec.js index 08b5868d1b4..b9354196c68 100644 --- a/spec/frontend/feature_flags/store/index/mutations_spec.js +++ b/spec/frontend/feature_flags/store/index/mutations_spec.js @@ -3,7 +3,7 @@ import * as types from '~/feature_flags/store/index/mutation_types'; import mutations from '~/feature_flags/store/index/mutations'; import state from '~/feature_flags/store/index/state'; import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils'; -import { getRequestData, rotateData, featureFlag, userList } from '../../mock_data'; +import { getRequestData, rotateData, featureFlag } from '../../mock_data'; describe('Feature flags store Mutations', () => { let stateCopy; @@ -59,13 +59,11 @@ describe('Feature flags store Mutations', () => { }); it('should set count with the given data', () => { - expect(stateCopy.count.featureFlags).toEqual(37); + expect(stateCopy.count).toEqual(37); }); it('should set pagination', () => { - expect(stateCopy.pageInfo.featureFlags).toEqual( - parseIntPagination(normalizeHeaders(headers)), - ); + expect(stateCopy.pageInfo).toEqual(parseIntPagination(normalizeHeaders(headers))); }); }); @@ -83,58 +81,6 @@ describe('Feature flags store Mutations', () => { }); }); - describe('REQUEST_USER_LISTS', () => { - it('sets isLoading to true', () => { - mutations[types.REQUEST_USER_LISTS](stateCopy); - expect(stateCopy.isLoading).toBe(true); - }); - }); - - describe('RECEIVE_USER_LISTS_SUCCESS', () => { - const headers = { - 'x-next-page': '2', - 'x-page': '1', - 'X-Per-Page': '2', - 'X-Prev-Page': '', - 'X-TOTAL': '37', - 'X-Total-Pages': '5', - }; - - beforeEach(() => { - mutations[types.RECEIVE_USER_LISTS_SUCCESS](stateCopy, { data: [userList], headers }); - }); - - it('sets isLoading to false', () => { - expect(stateCopy.isLoading).toBe(false); - }); - - it('sets userLists to the received userLists', () => { - expect(stateCopy.userLists).toEqual([userList]); - }); - - it('sets pagination info for user lits', () => { - expect(stateCopy.pageInfo.userLists).toEqual(parseIntPagination(normalizeHeaders(headers))); - }); - - it('sets the count for user lists', () => { - expect(stateCopy.count.userLists).toBe(parseInt(headers['X-TOTAL'], 10)); - }); - }); - - describe('RECEIVE_USER_LISTS_ERROR', () => { - beforeEach(() => { - mutations[types.RECEIVE_USER_LISTS_ERROR](stateCopy); - }); - - it('should set isLoading to false', () => { - expect(stateCopy.isLoading).toEqual(false); - }); - - it('should set hasError to true', () => { - expect(stateCopy.hasError).toEqual(true); - }); - }); - describe('REQUEST_ROTATE_INSTANCE_ID', () => { beforeEach(() => { mutations[types.REQUEST_ROTATE_INSTANCE_ID](stateCopy); @@ -214,7 +160,7 @@ describe('Feature flags store Mutations', () => { ...flagState, scopes: mapToScopesViewModel(flag.scopes || []), })); - stateCopy.count.featureFlags = stateCount; + stateCopy.count = stateCount; mutations[types.RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS](stateCopy, { ...featureFlag, @@ -241,8 +187,6 @@ describe('Feature flags store Mutations', () => { ...flag, scopes: mapToScopesViewModel(flag.scopes || []), })); - stateCopy.count = { enabled: 1, disabled: 0 }; - mutations[types.RECEIVE_UPDATE_FEATURE_FLAG_ERROR](stateCopy, featureFlag.id); }); @@ -257,36 +201,6 @@ describe('Feature flags store Mutations', () => { }); }); - describe('REQUEST_DELETE_USER_LIST', () => { - beforeEach(() => { - stateCopy.userLists = [userList]; - mutations[types.REQUEST_DELETE_USER_LIST](stateCopy, userList); - }); - - it('should remove the deleted list', () => { - expect(stateCopy.userLists).not.toContain(userList); - }); - }); - - describe('RECEIVE_DELETE_USER_LIST_ERROR', () => { - beforeEach(() => { - stateCopy.userLists = []; - mutations[types.RECEIVE_DELETE_USER_LIST_ERROR](stateCopy, { - list: userList, - error: 'some error', - }); - }); - - it('should set isLoading to false and hasError to false', () => { - expect(stateCopy.isLoading).toBe(false); - expect(stateCopy.hasError).toBe(false); - }); - - it('should add the user list back to the list of user lists', () => { - expect(stateCopy.userLists).toContain(userList); - }); - }); - describe('RECEIVE_CLEAR_ALERT', () => { it('clears the alert', () => { stateCopy.alerts = ['a server error']; |