debian-mirror-gitlab/spec/frontend/sidebar/assignees_realtime_spec.js

86 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
2021-06-08 01:23:25 +05:30
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
2022-06-21 17:19:12 +05:30
import waitForPromises from 'helpers/wait_for_promises';
2020-05-24 23:13:21 +05:30
import AssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue';
2021-06-08 01:23:25 +05:30
import issuableAssigneesSubscription from '~/sidebar/queries/issuable_assignees.subscription.graphql';
2020-05-24 23:13:21 +05:30
import SidebarMediator from '~/sidebar/sidebar_mediator';
2021-06-08 01:23:25 +05:30
import getIssueAssigneesQuery from '~/vue_shared/components/sidebar/queries/get_issue_assignees.query.graphql';
2022-06-21 17:19:12 +05:30
import Mock, {
issuableQueryResponse,
subscriptionNullResponse,
subscriptionResponse,
} from './mock_data';
2020-05-24 23:13:21 +05:30
2022-04-04 11:22:00 +05:30
Vue.use(VueApollo);
2020-05-24 23:13:21 +05:30
describe('Assignees Realtime', () => {
let wrapper;
let mediator;
2021-06-08 01:23:25 +05:30
let fakeApollo;
const issuableQueryHandler = jest.fn().mockResolvedValue(issuableQueryResponse);
const subscriptionInitialHandler = jest.fn().mockResolvedValue(subscriptionNullResponse);
2020-05-24 23:13:21 +05:30
2021-06-08 01:23:25 +05:30
const createComponent = ({
issuableType = 'issue',
subscriptionHandler = subscriptionInitialHandler,
} = {}) => {
fakeApollo = createMockApollo([
[getIssueAssigneesQuery, issuableQueryHandler],
[issuableAssigneesSubscription, subscriptionHandler],
]);
2020-05-24 23:13:21 +05:30
wrapper = shallowMount(AssigneesRealtime, {
propsData: {
2021-04-29 21:17:54 +05:30
issuableType,
2021-06-08 01:23:25 +05:30
queryVariables: {
issuableIid: '1',
projectPath: 'path/to/project',
2020-05-24 23:13:21 +05:30
},
2021-06-08 01:23:25 +05:30
mediator,
2020-05-24 23:13:21 +05:30
},
2021-06-08 01:23:25 +05:30
apolloProvider: fakeApollo,
2020-05-24 23:13:21 +05:30
});
};
beforeEach(() => {
mediator = new SidebarMediator(Mock.mediator);
});
afterEach(() => {
wrapper.destroy();
2021-06-08 01:23:25 +05:30
fakeApollo = null;
2020-05-24 23:13:21 +05:30
SidebarMediator.singleton = null;
});
2021-06-08 01:23:25 +05:30
it('calls the query with correct variables', () => {
createComponent();
2020-05-24 23:13:21 +05:30
2021-06-08 01:23:25 +05:30
expect(issuableQueryHandler).toHaveBeenCalledWith({
issuableIid: '1',
projectPath: 'path/to/project',
2020-05-24 23:13:21 +05:30
});
});
2022-06-21 17:19:12 +05:30
it('calls the subscription with correct variable for issue', async () => {
2021-06-08 01:23:25 +05:30
createComponent();
2022-06-21 17:19:12 +05:30
await waitForPromises();
2020-05-24 23:13:21 +05:30
2021-06-08 01:23:25 +05:30
expect(subscriptionInitialHandler).toHaveBeenCalledWith({
issuableId: 'gid://gitlab/Issue/1',
2020-05-24 23:13:21 +05:30
});
});
2022-06-21 17:19:12 +05:30
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 }],
]);
});
2020-05-24 23:13:21 +05:30
});