diff options
Diffstat (limited to 'spec/frontend')
-rw-r--r-- | spec/frontend/api/api_utils_spec.js | 35 | ||||
-rw-r--r-- | spec/frontend/commons/nav/user_merge_requests_spec.js | 18 | ||||
-rw-r--r-- | spec/frontend/invite_members/components/members_token_select_spec.js | 11 | ||||
-rw-r--r-- | spec/frontend/lib/utils/users_cache_spec.js | 10 | ||||
-rw-r--r-- | spec/frontend/notes/stores/actions_spec.js | 5 | ||||
-rw-r--r-- | spec/frontend/performance_bar/index_spec.js | 11 | ||||
-rw-r--r-- | spec/frontend/set_status_modal/set_status_modal_wrapper_spec.js | 17 |
7 files changed, 69 insertions, 38 deletions
diff --git a/spec/frontend/api/api_utils_spec.js b/spec/frontend/api/api_utils_spec.js new file mode 100644 index 00000000000..3fec26f0149 --- /dev/null +++ b/spec/frontend/api/api_utils_spec.js @@ -0,0 +1,35 @@ +import * as apiUtils from '~/api/api_utils'; + +describe('~/api/api_utils.js', () => { + describe('buildApiUrl', () => { + beforeEach(() => { + window.gon = { + api_version: 'v7', + }; + }); + + it('returns a URL with the correct API version', () => { + expect(apiUtils.buildApiUrl('/api/:version/users/:id/status')).toEqual( + '/api/v7/users/:id/status', + ); + }); + + it('only replaces the first instance of :version in the URL', () => { + expect(apiUtils.buildApiUrl('/api/:version/projects/:id/packages/:version')).toEqual( + '/api/v7/projects/:id/packages/:version', + ); + }); + + describe('when gon includes a relative_url_root property', () => { + beforeEach(() => { + window.gon.relative_url_root = '/relative/root'; + }); + + it('returns a URL with the correct relative root URL and API version', () => { + expect(apiUtils.buildApiUrl('/api/:version/users/:id/status')).toEqual( + '/relative/root/api/v7/users/:id/status', + ); + }); + }); + }); +}); diff --git a/spec/frontend/commons/nav/user_merge_requests_spec.js b/spec/frontend/commons/nav/user_merge_requests_spec.js index 5f81067f84f..c441668f7c7 100644 --- a/spec/frontend/commons/nav/user_merge_requests_spec.js +++ b/spec/frontend/commons/nav/user_merge_requests_spec.js @@ -3,7 +3,7 @@ import { closeUserCountsBroadcast, refreshUserMergeRequestCounts, } from '~/commons/nav/user_merge_requests'; -import Api from '~/api'; +import * as UserApi from '~/api/user_api'; jest.mock('~/api'); @@ -33,14 +33,12 @@ describe('User Merge Requests', () => { describe('refreshUserMergeRequestCounts', () => { beforeEach(() => { - Api.userCounts.mockReturnValue( - Promise.resolve({ - data: { - assigned_merge_requests: TEST_COUNT, - review_requested_merge_requests: TEST_COUNT, - }, - }), - ); + jest.spyOn(UserApi, 'getUserCounts').mockResolvedValue({ + data: { + assigned_merge_requests: TEST_COUNT, + review_requested_merge_requests: TEST_COUNT, + }, + }); }); describe('with open broadcast channel', () => { @@ -55,7 +53,7 @@ describe('User Merge Requests', () => { }); it('calls the API', () => { - expect(Api.userCounts).toHaveBeenCalled(); + expect(UserApi.getUserCounts).toHaveBeenCalled(); }); it('posts count to BroadcastChannel', () => { diff --git a/spec/frontend/invite_members/components/members_token_select_spec.js b/spec/frontend/invite_members/components/members_token_select_spec.js index d66b715689f..ff123a13ce7 100644 --- a/spec/frontend/invite_members/components/members_token_select_spec.js +++ b/spec/frontend/invite_members/components/members_token_select_spec.js @@ -3,7 +3,7 @@ import { nextTick } from 'vue'; import { GlTokenSelector } from '@gitlab/ui'; import waitForPromises from 'helpers/wait_for_promises'; import { stubComponent } from 'helpers/stub_component'; -import Api from '~/api'; +import * as UserApi from '~/api/user_api'; import MembersTokenSelect from '~/invite_members/components/members_token_select.vue'; const label = 'testgroup'; @@ -28,7 +28,7 @@ describe('MembersTokenSelect', () => { let wrapper; beforeEach(() => { - jest.spyOn(Api, 'users').mockResolvedValue({ data: allUsers }); + jest.spyOn(UserApi, 'getUsers').mockResolvedValue({ data: allUsers }); wrapper = createComponent(); }); @@ -57,7 +57,7 @@ describe('MembersTokenSelect', () => { await waitForPromises(); - expect(Api.users).not.toHaveBeenCalled(); + expect(UserApi.getUsers).not.toHaveBeenCalled(); }); }); @@ -90,7 +90,10 @@ describe('MembersTokenSelect', () => { await waitForPromises(); - expect(Api.users).toHaveBeenCalledWith(searchParam, wrapper.vm.$options.queryOptions); + expect(UserApi.getUsers).toHaveBeenCalledWith( + searchParam, + wrapper.vm.$options.queryOptions, + ); expect(tokenSelector.props('hideDropdownWithNoItems')).toBe(false); }); diff --git a/spec/frontend/lib/utils/users_cache_spec.js b/spec/frontend/lib/utils/users_cache_spec.js index bc00a5d5409..4034f39ee9c 100644 --- a/spec/frontend/lib/utils/users_cache_spec.js +++ b/spec/frontend/lib/utils/users_cache_spec.js @@ -1,4 +1,4 @@ -import Api from '~/api'; +import * as UserApi from '~/api/user_api'; import UsersCache from '~/lib/utils/users_cache'; describe('UsersCache', () => { @@ -88,7 +88,9 @@ describe('UsersCache', () => { let apiSpy; beforeEach(() => { - jest.spyOn(Api, 'users').mockImplementation((query, options) => apiSpy(query, options)); + jest + .spyOn(UserApi, 'getUsers') + .mockImplementation((query, options) => apiSpy(query, options)); }); it('stores and returns data from API call if cache is empty', (done) => { @@ -151,7 +153,7 @@ describe('UsersCache', () => { let apiSpy; beforeEach(() => { - jest.spyOn(Api, 'user').mockImplementation((id) => apiSpy(id)); + jest.spyOn(UserApi, 'getUser').mockImplementation((id) => apiSpy(id)); }); it('stores and returns data from API call if cache is empty', (done) => { @@ -208,7 +210,7 @@ describe('UsersCache', () => { let apiSpy; beforeEach(() => { - jest.spyOn(Api, 'userStatus').mockImplementation((id) => apiSpy(id)); + jest.spyOn(UserApi, 'getUserStatus').mockImplementation((id) => apiSpy(id)); }); it('stores and returns data from API call if cache is empty', (done) => { diff --git a/spec/frontend/notes/stores/actions_spec.js b/spec/frontend/notes/stores/actions_spec.js index 912778a1546..1bc74609b6f 100644 --- a/spec/frontend/notes/stores/actions_spec.js +++ b/spec/frontend/notes/stores/actions_spec.js @@ -918,7 +918,6 @@ describe('Actions Notes Store', () => { testSubmitSuggestion(done, () => { expect(commit.mock.calls).toEqual([ [mutationTypes.SET_RESOLVING_DISCUSSION, true], - [mutationTypes.APPLY_SUGGESTION, { discussionId, noteId, suggestionId }], [mutationTypes.SET_RESOLVING_DISCUSSION, false], ]); @@ -1001,8 +1000,6 @@ describe('Actions Notes Store', () => { expect(commit.mock.calls).toEqual([ [mutationTypes.SET_APPLYING_BATCH_STATE, true], [mutationTypes.SET_RESOLVING_DISCUSSION, true], - [mutationTypes.APPLY_SUGGESTION, batchSuggestionsInfo[0]], - [mutationTypes.APPLY_SUGGESTION, batchSuggestionsInfo[1]], [mutationTypes.CLEAR_SUGGESTION_BATCH], [mutationTypes.SET_APPLYING_BATCH_STATE, false], [mutationTypes.SET_RESOLVING_DISCUSSION, false], @@ -1066,8 +1063,6 @@ describe('Actions Notes Store', () => { expect(commit.mock.calls).toEqual([ [mutationTypes.SET_APPLYING_BATCH_STATE, true], [mutationTypes.SET_RESOLVING_DISCUSSION, true], - [mutationTypes.APPLY_SUGGESTION, batchSuggestionsInfo[0]], - [mutationTypes.APPLY_SUGGESTION, batchSuggestionsInfo[1]], [mutationTypes.CLEAR_SUGGESTION_BATCH], [mutationTypes.SET_APPLYING_BATCH_STATE, false], [mutationTypes.SET_RESOLVING_DISCUSSION, false], diff --git a/spec/frontend/performance_bar/index_spec.js b/spec/frontend/performance_bar/index_spec.js index bcd2cbbd530..8d9c32b7f12 100644 --- a/spec/frontend/performance_bar/index_spec.js +++ b/spec/frontend/performance_bar/index_spec.js @@ -4,25 +4,23 @@ import '~/performance_bar/components/performance_bar_app.vue'; import performanceBar from '~/performance_bar'; import PerformanceBarService from '~/performance_bar/services/performance_bar_service'; +jest.mock('~/performance_bar/performance_bar_log'); + describe('performance bar wrapper', () => { let mock; let vm; beforeEach(() => { + setFixtures('<div id="js-peek"></div>'); + const peekWrapper = document.getElementById('js-peek'); performance.getEntriesByType = jest.fn().mockReturnValue([]); - // clear html so that elements from previous tests don't mess with this test - document.body.innerHTML = ''; - const peekWrapper = document.createElement('div'); - peekWrapper.setAttribute('id', 'js-peek'); peekWrapper.setAttribute('data-env', 'development'); peekWrapper.setAttribute('data-request-id', '123'); peekWrapper.setAttribute('data-peek-url', '/-/peek/results'); peekWrapper.setAttribute('data-profile-url', '?lineprofiler=true'); - document.body.appendChild(peekWrapper); - mock = new MockAdapter(axios); mock.onGet('/-/peek/results').reply( @@ -48,6 +46,7 @@ describe('performance bar wrapper', () => { afterEach(() => { vm.$destroy(); + document.getElementById('js-peek').remove(); mock.restore(); }); diff --git a/spec/frontend/set_status_modal/set_status_modal_wrapper_spec.js b/spec/frontend/set_status_modal/set_status_modal_wrapper_spec.js index 273dfeeb6f3..f3085fb7ffb 100644 --- a/spec/frontend/set_status_modal/set_status_modal_wrapper_spec.js +++ b/spec/frontend/set_status_modal/set_status_modal_wrapper_spec.js @@ -1,13 +1,12 @@ import { shallowMount } from '@vue/test-utils'; import { GlModal, GlFormCheckbox } from '@gitlab/ui'; import { initEmojiMock } from 'helpers/emoji'; -import Api from '~/api'; +import * as UserApi from '~/api/user_api'; import { deprecatedCreateFlash as createFlash } from '~/flash'; import SetStatusModalWrapper, { AVAILABILITY_STATUS, } from '~/set_status_modal/set_status_modal_wrapper.vue'; -jest.mock('~/api'); jest.mock('~/flash'); describe('SetStatusModalWrapper', () => { @@ -150,7 +149,7 @@ describe('SetStatusModalWrapper', () => { describe('update status', () => { describe('succeeds', () => { beforeEach(() => { - jest.spyOn(Api, 'postUserStatus').mockResolvedValue(); + jest.spyOn(UserApi, 'updateUserStatus').mockResolvedValue(); }); it('clicking "removeStatus" clears the emoji and message fields', async () => { @@ -173,12 +172,12 @@ describe('SetStatusModalWrapper', () => { const commonParams = { emoji: defaultEmoji, message: defaultMessage }; - expect(Api.postUserStatus).toHaveBeenCalledTimes(2); - expect(Api.postUserStatus).toHaveBeenNthCalledWith(1, { + expect(UserApi.updateUserStatus).toHaveBeenCalledTimes(2); + expect(UserApi.updateUserStatus).toHaveBeenNthCalledWith(1, { availability: AVAILABILITY_STATUS.NOT_SET, ...commonParams, }); - expect(Api.postUserStatus).toHaveBeenNthCalledWith(2, { + expect(UserApi.updateUserStatus).toHaveBeenNthCalledWith(2, { availability: AVAILABILITY_STATUS.BUSY, ...commonParams, }); @@ -196,7 +195,7 @@ describe('SetStatusModalWrapper', () => { beforeEach(async () => { mockEmoji = await initEmojiMock(); wrapper = createComponent({ currentEmoji: '', currentMessage: '' }); - jest.spyOn(Api, 'postUserStatus').mockResolvedValue(); + jest.spyOn(UserApi, 'updateUserStatus').mockResolvedValue(); return initModal({ mockOnUpdateSuccess: false }); }); @@ -210,7 +209,7 @@ describe('SetStatusModalWrapper', () => { describe('with errors', () => { beforeEach(() => { - jest.spyOn(Api, 'postUserStatus').mockRejectedValue(); + jest.spyOn(UserApi, 'updateUserStatus').mockRejectedValue(); }); it('calls the "onUpdateFail" handler', async () => { @@ -225,7 +224,7 @@ describe('SetStatusModalWrapper', () => { beforeEach(async () => { mockEmoji = await initEmojiMock(); wrapper = createComponent({ currentEmoji: '', currentMessage: '' }); - jest.spyOn(Api, 'postUserStatus').mockRejectedValue(); + jest.spyOn(UserApi, 'updateUserStatus').mockRejectedValue(); return initModal({ mockOnUpdateFailure: false }); }); |