diff options
Diffstat (limited to 'spec/frontend/sidebar')
10 files changed, 91 insertions, 28 deletions
diff --git a/spec/frontend/sidebar/components/assignees/uncollapsed_assignee_list_spec.js b/spec/frontend/sidebar/components/assignees/uncollapsed_assignee_list_spec.js index 90aae85e1ca..f7437386814 100644 --- a/spec/frontend/sidebar/components/assignees/uncollapsed_assignee_list_spec.js +++ b/spec/frontend/sidebar/components/assignees/uncollapsed_assignee_list_spec.js @@ -47,12 +47,10 @@ describe('UncollapsedAssigneeList component', () => { it('calls the AssigneeAvatarLink with the proper props', () => { expect(wrapper.find(AssigneeAvatarLink).exists()).toBe(true); - expect(wrapper.find(AssigneeAvatarLink).props().tooltipPlacement).toEqual('left'); }); it('Shows one user with avatar, username and author name', () => { expect(wrapper.text()).toContain(user.name); - expect(wrapper.text()).toContain(`@${user.username}`); }); }); diff --git a/spec/frontend/sidebar/components/attention_requested_toggle_spec.js b/spec/frontend/sidebar/components/attention_requested_toggle_spec.js index a9ae23c1624..959fa799eb7 100644 --- a/spec/frontend/sidebar/components/attention_requested_toggle_spec.js +++ b/spec/frontend/sidebar/components/attention_requested_toggle_spec.js @@ -68,6 +68,7 @@ describe('Attention require toggle', () => { { user: { attention_requested: true, can_update_merge_request: true }, callback: expect.anything(), + direction: 'remove', }, ]); }); @@ -96,9 +97,9 @@ describe('Attention require toggle', () => { it.each` type | attentionRequested | tooltip | canUpdateMergeRequest - ${'reviewer'} | ${true} | ${AttentionRequestedToggle.i18n.removeAttentionRequested} | ${true} - ${'reviewer'} | ${false} | ${AttentionRequestedToggle.i18n.attentionRequestedReviewer} | ${true} - ${'assignee'} | ${false} | ${AttentionRequestedToggle.i18n.attentionRequestedAssignee} | ${true} + ${'reviewer'} | ${true} | ${AttentionRequestedToggle.i18n.removeAttentionRequest} | ${true} + ${'reviewer'} | ${false} | ${AttentionRequestedToggle.i18n.addAttentionRequest} | ${true} + ${'assignee'} | ${false} | ${AttentionRequestedToggle.i18n.addAttentionRequest} | ${true} ${'reviewer'} | ${true} | ${AttentionRequestedToggle.i18n.attentionRequestedNoPermission} | ${false} ${'reviewer'} | ${false} | ${AttentionRequestedToggle.i18n.noAttentionRequestedNoPermission} | ${false} ${'assignee'} | ${true} | ${AttentionRequestedToggle.i18n.attentionRequestedNoPermission} | ${false} diff --git a/spec/frontend/sidebar/components/confidential/sidebar_confidentiality_content_spec.js b/spec/frontend/sidebar/components/confidential/sidebar_confidentiality_content_spec.js index 8844e1626cd..ab45fdf03bc 100644 --- a/spec/frontend/sidebar/components/confidential/sidebar_confidentiality_content_spec.js +++ b/spec/frontend/sidebar/components/confidential/sidebar_confidentiality_content_spec.js @@ -1,4 +1,4 @@ -import { GlIcon } from '@gitlab/ui'; +import { GlIcon, GlAlert } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import SidebarConfidentialityContent from '~/sidebar/components/confidential/sidebar_confidentiality_content.vue'; @@ -60,12 +60,24 @@ describe('Sidebar Confidentiality Content', () => { it('displays a correct confidential text for issue', () => { createComponent({ confidential: true }); - expect(findText().text()).toBe('This issue is confidential'); + + const alertEl = findText().findComponent(GlAlert); + + expect(alertEl.props()).toMatchObject({ + showIcon: false, + dismissible: false, + variant: 'warning', + }); + expect(alertEl.text()).toBe( + 'Only project members with at least Reporter role can view or be notified about this issue.', + ); }); it('displays a correct confidential text for epic', () => { createComponent({ confidential: true, issuableType: 'epic' }); - expect(findText().text()).toBe('This epic is confidential'); + expect(findText().findComponent(GlAlert).text()).toBe( + 'Only group members with at least Reporter role can view or be notified about this epic.', + ); }); }); }); diff --git a/spec/frontend/sidebar/components/confidential/sidebar_confidentiality_form_spec.js b/spec/frontend/sidebar/components/confidential/sidebar_confidentiality_form_spec.js index 28a19fb9df6..85d6bc7b782 100644 --- a/spec/frontend/sidebar/components/confidential/sidebar_confidentiality_form_spec.js +++ b/spec/frontend/sidebar/components/confidential/sidebar_confidentiality_form_spec.js @@ -89,7 +89,7 @@ describe('Sidebar Confidentiality Form', () => { it('renders a message about making an issue confidential', () => { expect(findWarningMessage().text()).toBe( - 'You are going to turn on confidentiality. Only team members with at least Reporter access will be able to see and leave comments on the issue.', + 'You are going to turn on confidentiality. Only project members with at least Reporter role can view or be notified about this issue.', ); }); diff --git a/spec/frontend/sidebar/components/crm_contacts_spec.js b/spec/frontend/sidebar/components/crm_contacts_spec.js index 758cff30e2d..6456829258f 100644 --- a/spec/frontend/sidebar/components/crm_contacts_spec.js +++ b/spec/frontend/sidebar/components/crm_contacts_spec.js @@ -33,7 +33,7 @@ describe('Issue crm contacts component', () => { [issueCrmContactsSubscription, subscriptionHandler], ]); wrapper = shallowMountExtended(CrmContacts, { - propsData: { issueId: '123' }, + propsData: { issueId: '123', groupIssuesPath: '/groups/flightjs/-/issues' }, apolloProvider: fakeApollo, }); }; @@ -71,8 +71,14 @@ describe('Issue crm contacts component', () => { await waitForPromises(); expect(wrapper.find('#contact_0').text()).toContain('Someone Important'); + expect(wrapper.find('#contact_0').attributes('href')).toBe( + '/groups/flightjs/-/issues?crm_contact_id=1', + ); expect(wrapper.find('#contact_container_0').text()).toContain('si@gitlab.com'); expect(wrapper.find('#contact_1').text()).toContain('Marty McFly'); + expect(wrapper.find('#contact_1').attributes('href')).toBe( + '/groups/flightjs/-/issues?crm_contact_id=5', + ); }); it('renders correct results after subscription update', async () => { @@ -83,5 +89,8 @@ describe('Issue crm contacts component', () => { contact.forEach((property) => { expect(wrapper.find('#contact_container_0').text()).toContain(property); }); + expect(wrapper.find('#contact_0').attributes('href')).toBe( + '/groups/flightjs/-/issues?crm_contact_id=13', + ); }); }); diff --git a/spec/frontend/sidebar/components/reviewers/uncollapsed_reviewer_list_spec.js b/spec/frontend/sidebar/components/reviewers/uncollapsed_reviewer_list_spec.js index d0792fa7b73..8999f120a0f 100644 --- a/spec/frontend/sidebar/components/reviewers/uncollapsed_reviewer_list_spec.js +++ b/spec/frontend/sidebar/components/reviewers/uncollapsed_reviewer_list_spec.js @@ -42,9 +42,8 @@ describe('UncollapsedReviewerList component', () => { expect(wrapper.findAll(ReviewerAvatarLink).length).toBe(1); }); - it('shows one user with avatar, username and author name', () => { + it('shows one user with avatar, and author name', () => { expect(wrapper.text()).toContain(user.name); - expect(wrapper.text()).toContain(`@root`); }); it('renders re-request loading icon', async () => { @@ -84,11 +83,9 @@ describe('UncollapsedReviewerList component', () => { expect(wrapper.findAll(ReviewerAvatarLink).length).toBe(2); }); - it('shows both users with avatar, username and author name', () => { + it('shows both users with avatar, and author name', () => { expect(wrapper.text()).toContain(user.name); - expect(wrapper.text()).toContain(`@root`); expect(wrapper.text()).toContain(user2.name); - expect(wrapper.text()).toContain(`@hello-world`); }); it('renders approval icon', () => { diff --git a/spec/frontend/sidebar/components/time_tracking/mock_data.js b/spec/frontend/sidebar/components/time_tracking/mock_data.js index 3f1b3fa8ec1..ba2781118d9 100644 --- a/spec/frontend/sidebar/components/time_tracking/mock_data.js +++ b/spec/frontend/sidebar/components/time_tracking/mock_data.js @@ -9,6 +9,7 @@ export const getIssueTimelogsQueryResponse = { nodes: [ { __typename: 'Timelog', + id: 'gid://gitlab/Timelog/18', timeSpent: 14400, user: { id: 'user-1', @@ -25,6 +26,7 @@ export const getIssueTimelogsQueryResponse = { }, { __typename: 'Timelog', + id: 'gid://gitlab/Timelog/20', timeSpent: 1800, user: { id: 'user-2', @@ -37,6 +39,7 @@ export const getIssueTimelogsQueryResponse = { }, { __typename: 'Timelog', + id: 'gid://gitlab/Timelog/25', timeSpent: 14400, user: { id: 'user-2', @@ -68,6 +71,7 @@ export const getMrTimelogsQueryResponse = { nodes: [ { __typename: 'Timelog', + id: 'gid://gitlab/Timelog/13', timeSpent: 1800, user: { id: 'user-1', @@ -84,6 +88,7 @@ export const getMrTimelogsQueryResponse = { }, { __typename: 'Timelog', + id: 'gid://gitlab/Timelog/22', timeSpent: 3600, user: { id: 'user-1', @@ -96,6 +101,7 @@ export const getMrTimelogsQueryResponse = { }, { __typename: 'Timelog', + id: 'gid://gitlab/Timelog/64', timeSpent: 300, user: { id: 'user-1', diff --git a/spec/frontend/sidebar/lock/issuable_lock_form_spec.js b/spec/frontend/sidebar/lock/issuable_lock_form_spec.js index 7bf7e563a01..8478d3d674d 100644 --- a/spec/frontend/sidebar/lock/issuable_lock_form_spec.js +++ b/spec/frontend/sidebar/lock/issuable_lock_form_spec.js @@ -37,6 +37,9 @@ describe('IssuableLockForm', () => { const createComponent = ({ props = {} }) => { wrapper = shallowMount(IssuableLockForm, { store, + provide: { + fullPath: '', + }, propsData: { isEditable: true, ...props, diff --git a/spec/frontend/sidebar/reviewers_spec.js b/spec/frontend/sidebar/reviewers_spec.js index fc24b51287f..351dfc9a6ed 100644 --- a/spec/frontend/sidebar/reviewers_spec.js +++ b/spec/frontend/sidebar/reviewers_spec.js @@ -146,7 +146,6 @@ describe('Reviewer component', () => { const userItems = wrapper.findAll('[data-testid="reviewer"]'); expect(userItems.length).toBe(3); - expect(userItems.at(0).find('a').attributes('title')).toBe(users[2].name); }); it('passes the sorted reviewers to the collapsed-reviewer-list', () => { diff --git a/spec/frontend/sidebar/sidebar_mediator_spec.js b/spec/frontend/sidebar/sidebar_mediator_spec.js index c472a98bf0b..82fb10ab1d2 100644 --- a/spec/frontend/sidebar/sidebar_mediator_spec.js +++ b/spec/frontend/sidebar/sidebar_mediator_spec.js @@ -1,4 +1,5 @@ import MockAdapter from 'axios-mock-adapter'; +import createFlash from '~/flash'; import axios from '~/lib/utils/axios_utils'; import * as urlUtility from '~/lib/utils/url_utility'; import SidebarService, { gqClient } from '~/sidebar/services/sidebar_service'; @@ -8,6 +9,7 @@ import toast from '~/vue_shared/plugins/global_toast'; import { refreshUserMergeRequestCounts } from '~/commons/nav/user_merge_requests'; import Mock from './mock_data'; +jest.mock('~/flash'); jest.mock('~/vue_shared/plugins/global_toast'); jest.mock('~/commons/nav/user_merge_requests'); @@ -122,25 +124,39 @@ describe('Sidebar mediator', () => { }); describe('toggleAttentionRequested', () => { - let attentionRequiredService; + let requestAttentionMock; + let removeAttentionRequestMock; beforeEach(() => { - attentionRequiredService = jest - .spyOn(mediator.service, 'toggleAttentionRequested') + requestAttentionMock = jest.spyOn(mediator.service, 'requestAttention').mockResolvedValue(); + removeAttentionRequestMock = jest + .spyOn(mediator.service, 'removeAttentionRequest') .mockResolvedValue(); }); - it('calls attentionRequired service method', async () => { - mediator.store.reviewers = [{ id: 1, attention_requested: false, username: 'root' }]; + it.each` + attentionIsCurrentlyRequested | serviceMethod + ${true} | ${'remove'} + ${false} | ${'add'} + `( + "calls the $serviceMethod service method when the user's attention request is set to $attentionIsCurrentlyRequested", + async ({ serviceMethod }) => { + const methods = { + add: requestAttentionMock, + remove: removeAttentionRequestMock, + }; + mediator.store.reviewers = [{ id: 1, attention_requested: false, username: 'root' }]; - await mediator.toggleAttentionRequested('reviewer', { - user: { id: 1, username: 'root' }, - callback: jest.fn(), - }); + await mediator.toggleAttentionRequested('reviewer', { + user: { id: 1, username: 'root' }, + callback: jest.fn(), + direction: serviceMethod, + }); - expect(attentionRequiredService).toHaveBeenCalledWith(1); - expect(refreshUserMergeRequestCounts).toHaveBeenCalled(); - }); + expect(methods[serviceMethod]).toHaveBeenCalledWith(1); + expect(refreshUserMergeRequestCounts).toHaveBeenCalled(); + }, + ); it.each` type | method @@ -172,5 +188,27 @@ describe('Sidebar mediator', () => { expect(toast).toHaveBeenCalledWith(toastMessage); }, ); + + describe('errors', () => { + beforeEach(() => { + jest + .spyOn(mediator.service, 'removeAttentionRequest') + .mockRejectedValueOnce(new Error('Something went wrong')); + }); + + it('shows an error message', async () => { + await mediator.toggleAttentionRequested('reviewer', { + user: { id: 1, username: 'root' }, + callback: jest.fn(), + direction: 'remove', + }); + + expect(createFlash).toHaveBeenCalledWith( + expect.objectContaining({ + message: 'Updating the attention request for root failed.', + }), + ); + }); + }); }); }); |