diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/frontend/sidebar/sidebar_mediator_spec.js | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/frontend/sidebar/sidebar_mediator_spec.js')
-rw-r--r-- | spec/frontend/sidebar/sidebar_mediator_spec.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/frontend/sidebar/sidebar_mediator_spec.js b/spec/frontend/sidebar/sidebar_mediator_spec.js index cb84c142d55..3d7baaff10a 100644 --- a/spec/frontend/sidebar/sidebar_mediator_spec.js +++ b/spec/frontend/sidebar/sidebar_mediator_spec.js @@ -4,8 +4,11 @@ import * as urlUtility from '~/lib/utils/url_utility'; import SidebarService, { gqClient } from '~/sidebar/services/sidebar_service'; import SidebarMediator from '~/sidebar/sidebar_mediator'; import SidebarStore from '~/sidebar/stores/sidebar_store'; +import toast from '~/vue_shared/plugins/global_toast'; import Mock from './mock_data'; +jest.mock('~/vue_shared/plugins/global_toast'); + describe('Sidebar mediator', () => { const { mediator: mediatorMockData } = Mock; let mock; @@ -115,4 +118,56 @@ describe('Sidebar mediator', () => { urlSpy.mockRestore(); }); }); + + describe('toggleAttentionRequested', () => { + let attentionRequiredService; + + beforeEach(() => { + attentionRequiredService = jest + .spyOn(mediator.service, 'toggleAttentionRequested') + .mockResolvedValue(); + }); + + it('calls attentionRequired service method', async () => { + mediator.store.reviewers = [{ id: 1, attention_requested: false, username: 'root' }]; + + await mediator.toggleAttentionRequested('reviewer', { + user: { id: 1, username: 'root' }, + callback: jest.fn(), + }); + + expect(attentionRequiredService).toHaveBeenCalledWith(1); + }); + + it.each` + type | method + ${'reviewer'} | ${'findReviewer'} + `('finds $type', ({ type, method }) => { + const methodSpy = jest.spyOn(mediator.store, method); + + mediator.toggleAttentionRequested(type, { user: { id: 1 }, callback: jest.fn() }); + + expect(methodSpy).toHaveBeenCalledWith({ id: 1 }); + }); + + it.each` + attentionRequested | toastMessage + ${true} | ${'Removed attention request from @root'} + ${false} | ${'Requested attention from @root'} + `( + 'it creates toast $toastMessage when attention_requested is $attentionRequested', + async ({ attentionRequested, toastMessage }) => { + mediator.store.reviewers = [ + { id: 1, attention_requested: attentionRequested, username: 'root' }, + ]; + + await mediator.toggleAttentionRequested('reviewer', { + user: { id: 1, username: 'root' }, + callback: jest.fn(), + }); + + expect(toast).toHaveBeenCalledWith(toastMessage); + }, + ); + }); }); |