diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/frontend/sidebar/components/assignees/assignees_realtime_spec.js | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/frontend/sidebar/components/assignees/assignees_realtime_spec.js')
-rw-r--r-- | spec/frontend/sidebar/components/assignees/assignees_realtime_spec.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/spec/frontend/sidebar/components/assignees/assignees_realtime_spec.js b/spec/frontend/sidebar/components/assignees/assignees_realtime_spec.js new file mode 100644 index 00000000000..080171fb2ea --- /dev/null +++ b/spec/frontend/sidebar/components/assignees/assignees_realtime_spec.js @@ -0,0 +1,85 @@ +import { shallowMount } from '@vue/test-utils'; +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; +import AssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue'; +import issuableAssigneesSubscription from '~/sidebar/queries/issuable_assignees.subscription.graphql'; +import SidebarMediator from '~/sidebar/sidebar_mediator'; +import getIssueAssigneesQuery from '~/sidebar/queries/get_issue_assignees.query.graphql'; +import Mock, { + issuableQueryResponse, + subscriptionNullResponse, + subscriptionResponse, +} from '../../mock_data'; + +Vue.use(VueApollo); + +describe('Assignees Realtime', () => { + let wrapper; + let mediator; + let fakeApollo; + + const issuableQueryHandler = jest.fn().mockResolvedValue(issuableQueryResponse); + const subscriptionInitialHandler = jest.fn().mockResolvedValue(subscriptionNullResponse); + + const createComponent = ({ + issuableType = 'issue', + subscriptionHandler = subscriptionInitialHandler, + } = {}) => { + fakeApollo = createMockApollo([ + [getIssueAssigneesQuery, issuableQueryHandler], + [issuableAssigneesSubscription, subscriptionHandler], + ]); + wrapper = shallowMount(AssigneesRealtime, { + propsData: { + issuableType, + queryVariables: { + issuableIid: '1', + projectPath: 'path/to/project', + }, + mediator, + }, + apolloProvider: fakeApollo, + }); + }; + + beforeEach(() => { + mediator = new SidebarMediator(Mock.mediator); + }); + + afterEach(() => { + wrapper.destroy(); + fakeApollo = null; + SidebarMediator.singleton = null; + }); + + it('calls the query with correct variables', () => { + createComponent(); + + expect(issuableQueryHandler).toHaveBeenCalledWith({ + issuableIid: '1', + projectPath: 'path/to/project', + }); + }); + + it('calls the subscription with correct variable for issue', async () => { + createComponent(); + await waitForPromises(); + + expect(subscriptionInitialHandler).toHaveBeenCalledWith({ + issuableId: 'gid://gitlab/Issue/1', + }); + }); + + it('emits an `assigneesUpdated` event on subscription response', async () => { + createComponent({ + subscriptionHandler: jest.fn().mockResolvedValue(subscriptionResponse), + }); + await waitForPromises(); + + expect(wrapper.emitted('assigneesUpdated')).toEqual([ + [{ id: '1', assignees: subscriptionResponse.data.issuableAssigneesUpdated.assignees.nodes }], + ]); + }); +}); |