1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
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(() => {
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 }],
]);
});
});
|