diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-12 18:10:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-12 18:10:26 +0300 |
commit | c0b17cee8be646588b14db49ad6d91b8cc818f97 (patch) | |
tree | 97287971303bccd649da1718c1a3a1ba8f345df6 /spec/frontend/vue_merge_request_widget | |
parent | 8ef107c43390ea9c9932afb55d1318e4716fbf3b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_merge_request_widget')
-rw-r--r-- | spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js | 48 | ||||
-rw-r--r-- | spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js | 48 |
2 files changed, 42 insertions, 54 deletions
diff --git a/spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js b/spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js index a07a60438fb..724f9ea0346 100644 --- a/spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js +++ b/spec/frontend/vue_merge_request_widget/components/approvals/approvals_spec.js @@ -57,13 +57,10 @@ describe('MRWidget approvals', () => { const apolloProvider = createMockApollo(requestHandlers); const provide = { ...options.provide, - glFeatures: { - realtimeApprovals: options.provide?.glFeatures?.realtimeApprovals || false, - }, }; - subscriptionHandlers.forEach(([document, stream]) => { - apolloProvider.defaultClient.setRequestHandler(document, stream); + subscriptionHandlers.forEach(([query, stream]) => { + apolloProvider.defaultClient.setRequestHandler(query, stream); }); wrapper = shallowMount(Approvals, { @@ -386,42 +383,21 @@ describe('MRWidget approvals', () => { }); describe('realtime approvals update', () => { - describe('realtime_approvals feature disabled', () => { - beforeEach(() => { - jest.spyOn(console, 'warn').mockImplementation(); - createComponent(); - }); + const subscriptionApproval = { approved: true }; + const subscriptionResponse = { + data: { mergeRequestApprovalStateUpdated: subscriptionApproval }, + }; - it('does not subscribe to the approvals update socket', () => { - expect(mr.setApprovals).not.toHaveBeenCalled(); - mockedSubscription.next({}); - // eslint-disable-next-line no-console - expect(console.warn).toHaveBeenCalledWith( - expect.stringMatching('Mock subscription has no observer, this will have no effect'), - ); - expect(mr.setApprovals).not.toHaveBeenCalled(); - }); + beforeEach(() => { + createComponent(); }); - describe('realtime_approvals feature enabled', () => { - const subscriptionApproval = { approved: true }; - const subscriptionResponse = { - data: { mergeRequestApprovalStateUpdated: subscriptionApproval }, - }; + it('updates approvals when the subscription data is streamed to the Apollo client', () => { + expect(mr.setApprovals).not.toHaveBeenCalled(); - beforeEach(() => { - createComponent({ - provide: { glFeatures: { realtimeApprovals: true } }, - }); - }); + mockedSubscription.next(subscriptionResponse); - it('updates approvals when the subscription data is streamed to the Apollo client', () => { - expect(mr.setApprovals).not.toHaveBeenCalled(); - - mockedSubscription.next(subscriptionResponse); - - expect(mr.setApprovals).toHaveBeenCalledWith(subscriptionApproval); - }); + expect(mr.setApprovals).toHaveBeenCalledWith(subscriptionApproval); }); }); }); diff --git a/spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js b/spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js index 266f69c8f2e..656203b1d25 100644 --- a/spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js +++ b/spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js @@ -4,6 +4,7 @@ import MockAdapter from 'axios-mock-adapter'; import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import * as Sentry from '@sentry/browser'; +import { createMockSubscription as createMockApolloSubscription } from 'mock-apollo-client'; import approvedByCurrentUser from 'test_fixtures/graphql/merge_requests/approvals/approvals.query.graphql.json'; import getStateQueryResponse from 'test_fixtures/graphql/merge_requests/get_state.query.graphql.json'; import readyToMergeResponse from 'test_fixtures/graphql/merge_requests/states/ready_to_merge.query.graphql.json'; @@ -31,6 +32,7 @@ import securityReportMergeRequestDownloadPathsQuery from '~/vue_shared/security_ import getStateQuery from '~/vue_merge_request_widget/queries/get_state.query.graphql'; import readyToMergeQuery from 'ee_else_ce/vue_merge_request_widget/queries/states/ready_to_merge.query.graphql'; import approvalsQuery from 'ee_else_ce/vue_merge_request_widget/components/approvals/queries/approvals.query.graphql'; +import approvedBySubscription from 'ee_else_ce/vue_merge_request_widget/components/approvals/queries/approvals.subscription.graphql'; import userPermissionsQuery from '~/vue_merge_request_widget/queries/permissions.query.graphql'; import conflictsStateQuery from '~/vue_merge_request_widget/queries/states/conflicts.query.graphql'; import { faviconDataUrl, overlayDataUrl } from '../lib/utils/mock_data'; @@ -63,6 +65,7 @@ jest.mock('@sentry/browser', () => ({ Vue.use(VueApollo); describe('MrWidgetOptions', () => { + let mockedApprovalsSubscription; let stateQueryHandler; let queryResponse; let wrapper; @@ -94,8 +97,7 @@ describe('MrWidgetOptions', () => { }); const createComponent = (mrData = mockData, options = {}, data = {}, fullMount = true) => { - const mounting = fullMount ? mount : shallowMount; - + mockedApprovalsSubscription = createMockApolloSubscription(); queryResponse = { data: { project: { @@ -108,6 +110,31 @@ describe('MrWidgetOptions', () => { }, }; stateQueryHandler = jest.fn().mockResolvedValue(queryResponse); + + const mounting = fullMount ? mount : shallowMount; + const queryHandlers = [ + [approvalsQuery, jest.fn().mockResolvedValue(approvedByCurrentUser)], + [getStateQuery, stateQueryHandler], + [readyToMergeQuery, jest.fn().mockResolvedValue(readyToMergeResponse)], + [ + userPermissionsQuery, + jest.fn().mockResolvedValue({ + data: { project: { mergeRequest: { userPermissions: {} } } }, + }), + ], + [ + conflictsStateQuery, + jest.fn().mockResolvedValue({ data: { project: { mergeRequest: {} } } }), + ], + ...(options.apolloMock || []), + ]; + const subscriptionHandlers = [[approvedBySubscription, () => mockedApprovalsSubscription]]; + const apolloProvider = createMockApollo(queryHandlers); + + subscriptionHandlers.forEach(([query, stream]) => { + apolloProvider.defaultClient.setRequestHandler(query, stream); + }); + wrapper = mounting(MrWidgetOptions, { propsData: { mrData: { ...mrData }, @@ -120,22 +147,7 @@ describe('MrWidgetOptions', () => { }, ...options, - apolloProvider: createMockApollo([ - [approvalsQuery, jest.fn().mockResolvedValue(approvedByCurrentUser)], - [getStateQuery, stateQueryHandler], - [readyToMergeQuery, jest.fn().mockResolvedValue(readyToMergeResponse)], - [ - userPermissionsQuery, - jest.fn().mockResolvedValue({ - data: { project: { mergeRequest: { userPermissions: {} } } }, - }), - ], - [ - conflictsStateQuery, - jest.fn().mockResolvedValue({ data: { project: { mergeRequest: {} } } }), - ], - ...(options.apolloMock || []), - ]), + apolloProvider, }); return axios.waitForAll(); |