diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-17 15:10:53 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-17 15:10:53 +0300 |
commit | 2724004cd7b8fa9d179c926c62f2fd7be63c2d81 (patch) | |
tree | 9915474bdea07e9748e3b940de07e899fb5f641c /spec/frontend/commons | |
parent | f665874e9ee6c28d5098248852f07ae7469d8b2b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/commons')
-rw-r--r-- | spec/frontend/commons/nav/user_merge_requests_spec.js | 154 |
1 files changed, 0 insertions, 154 deletions
diff --git a/spec/frontend/commons/nav/user_merge_requests_spec.js b/spec/frontend/commons/nav/user_merge_requests_spec.js deleted file mode 100644 index 114cbbf812c..00000000000 --- a/spec/frontend/commons/nav/user_merge_requests_spec.js +++ /dev/null @@ -1,154 +0,0 @@ -import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; -import * as UserApi from '~/api/user_api'; -import { - openUserCountsBroadcast, - closeUserCountsBroadcast, - refreshUserMergeRequestCounts, -} from '~/commons/nav/user_merge_requests'; - -jest.mock('~/api'); - -const TEST_COUNT = 1000; -const MR_COUNT_CLASS = 'js-merge-requests-count'; - -describe('User Merge Requests', () => { - let channelMock; - let newBroadcastChannelMock; - - beforeEach(() => { - jest.spyOn(document, 'dispatchEvent').mockReturnValue(false); - - global.gon.current_user_id = 123; - global.gon.use_new_navigation = false; - - channelMock = { - postMessage: jest.fn(), - close: jest.fn(), - }; - newBroadcastChannelMock = jest.fn().mockImplementation(() => channelMock); - - global.BroadcastChannel = newBroadcastChannelMock; - setHTMLFixture( - `<div><div class="${MR_COUNT_CLASS}">0</div><div class="js-assigned-mr-count"></div><div class="js-reviewer-mr-count"></div></div>`, - ); - }); - - afterEach(() => { - resetHTMLFixture(); - }); - - const findMRCountText = () => document.body.querySelector(`.${MR_COUNT_CLASS}`).textContent; - - describe('refreshUserMergeRequestCounts', () => { - beforeEach(() => { - jest.spyOn(UserApi, 'getUserCounts').mockResolvedValue({ - data: { - assigned_merge_requests: TEST_COUNT, - review_requested_merge_requests: TEST_COUNT, - }, - }); - }); - - describe('with open broadcast channel', () => { - beforeEach(() => { - openUserCountsBroadcast(); - - return refreshUserMergeRequestCounts(); - }); - - it('updates the top count of merge requests', () => { - expect(findMRCountText()).toEqual(Number(TEST_COUNT + TEST_COUNT).toLocaleString()); - }); - - it('calls the API', () => { - expect(UserApi.getUserCounts).toHaveBeenCalled(); - }); - - it('posts count to BroadcastChannel', () => { - expect(channelMock.postMessage).toHaveBeenCalledWith(TEST_COUNT + TEST_COUNT); - }); - }); - - describe('without open broadcast channel', () => { - beforeEach(() => refreshUserMergeRequestCounts()); - - it('does not post anything', () => { - expect(channelMock.postMessage).not.toHaveBeenCalled(); - }); - }); - - it('does not emit event to refetch counts', () => { - expect(document.dispatchEvent).not.toHaveBeenCalled(); - }); - }); - - describe('openUserCountsBroadcast', () => { - beforeEach(() => { - openUserCountsBroadcast(); - }); - - it('creates BroadcastChannel that updates DOM on message received', () => { - expect(findMRCountText()).toEqual('0'); - - channelMock.onmessage({ data: TEST_COUNT }); - - expect(newBroadcastChannelMock).toHaveBeenCalled(); - expect(findMRCountText()).toEqual(TEST_COUNT.toLocaleString()); - }); - - it('closes if called while already open', () => { - expect(channelMock.close).not.toHaveBeenCalled(); - - openUserCountsBroadcast(); - - expect(newBroadcastChannelMock).toHaveBeenCalled(); - expect(channelMock.close).toHaveBeenCalled(); - }); - }); - - describe('closeUserCountsBroadcast', () => { - describe('when not opened', () => { - it('does nothing', () => { - expect(channelMock.close).not.toHaveBeenCalled(); - }); - }); - - describe('when opened', () => { - beforeEach(() => { - openUserCountsBroadcast(); - }); - - it('closes', () => { - expect(channelMock.close).not.toHaveBeenCalled(); - - closeUserCountsBroadcast(); - - expect(channelMock.close).toHaveBeenCalled(); - }); - }); - }); - - describe('if new navigation is enabled', () => { - beforeEach(() => { - global.gon.use_new_navigation = true; - jest.spyOn(UserApi, 'getUserCounts'); - }); - - it('openUserCountsBroadcast is a noop', () => { - openUserCountsBroadcast(); - expect(newBroadcastChannelMock).not.toHaveBeenCalled(); - }); - - describe('refreshUserMergeRequestCounts', () => { - it('does not call api', async () => { - await refreshUserMergeRequestCounts(); - expect(UserApi.getUserCounts).not.toHaveBeenCalled(); - }); - - it('emits event to refetch counts', async () => { - await refreshUserMergeRequestCounts(); - expect(document.dispatchEvent).toHaveBeenCalledWith(new CustomEvent('todo:toggle')); - }); - }); - }); -}); |