diff options
Diffstat (limited to 'spec/frontend/commons/nav')
-rw-r--r-- | spec/frontend/commons/nav/user_merge_requests_spec.js | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/spec/frontend/commons/nav/user_merge_requests_spec.js b/spec/frontend/commons/nav/user_merge_requests_spec.js index 4da6d53557a..c441668f7c7 100644 --- a/spec/frontend/commons/nav/user_merge_requests_spec.js +++ b/spec/frontend/commons/nav/user_merge_requests_spec.js @@ -3,12 +3,12 @@ import { closeUserCountsBroadcast, refreshUserMergeRequestCounts, } from '~/commons/nav/user_merge_requests'; -import Api from '~/api'; +import * as UserApi from '~/api/user_api'; jest.mock('~/api'); const TEST_COUNT = 1000; -const MR_COUNT_CLASS = 'merge-requests-count'; +const MR_COUNT_CLASS = 'js-merge-requests-count'; describe('User Merge Requests', () => { let channelMock; @@ -24,18 +24,21 @@ describe('User Merge Requests', () => { newBroadcastChannelMock = jest.fn().mockImplementation(() => channelMock); global.BroadcastChannel = newBroadcastChannelMock; - setFixtures(`<div class="${MR_COUNT_CLASS}">0</div>`); + setFixtures( + `<div><div class="${MR_COUNT_CLASS}">0</div><div class="js-assigned-mr-count"></div><div class="js-reviewer-mr-count"></div></div>`, + ); }); const findMRCountText = () => document.body.querySelector(`.${MR_COUNT_CLASS}`).textContent; describe('refreshUserMergeRequestCounts', () => { beforeEach(() => { - Api.userCounts.mockReturnValue( - Promise.resolve({ - data: { 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', () => { @@ -46,15 +49,15 @@ describe('User Merge Requests', () => { }); it('updates the top count of merge requests', () => { - expect(findMRCountText()).toEqual(TEST_COUNT.toLocaleString()); + expect(findMRCountText()).toEqual(Number(TEST_COUNT + TEST_COUNT).toLocaleString()); }); it('calls the API', () => { - expect(Api.userCounts).toHaveBeenCalled(); + expect(UserApi.getUserCounts).toHaveBeenCalled(); }); it('posts count to BroadcastChannel', () => { - expect(channelMock.postMessage).toHaveBeenCalledWith(TEST_COUNT); + expect(channelMock.postMessage).toHaveBeenCalledWith(TEST_COUNT + TEST_COUNT); }); }); |