2021-04-26 05:09:53 -04:00
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2020-05-04 08:09:46 -04:00
|
|
|
import AssigneesRealtime from '~/sidebar/components/assignees/assignees_realtime.vue';
|
2021-04-26 05:09:53 -04:00
|
|
|
import issuableAssigneesSubscription from '~/sidebar/queries/issuable_assignees.subscription.graphql';
|
2020-05-04 08:09:46 -04:00
|
|
|
import SidebarMediator from '~/sidebar/sidebar_mediator';
|
2021-04-30 08:12:30 -04:00
|
|
|
import getIssueAssigneesQuery from '~/vue_shared/components/sidebar/queries/get_issue_assignees.query.graphql';
|
2021-04-26 05:09:53 -04:00
|
|
|
import Mock, { issuableQueryResponse, subscriptionNullResponse } from './mock_data';
|
2020-05-04 08:09:46 -04:00
|
|
|
|
2021-04-26 05:09:53 -04:00
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(VueApollo);
|
2020-05-04 08:09:46 -04:00
|
|
|
|
|
|
|
describe('Assignees Realtime', () => {
|
|
|
|
let wrapper;
|
|
|
|
let mediator;
|
2021-04-26 05:09:53 -04:00
|
|
|
let fakeApollo;
|
|
|
|
|
|
|
|
const issuableQueryHandler = jest.fn().mockResolvedValue(issuableQueryResponse);
|
|
|
|
const subscriptionInitialHandler = jest.fn().mockResolvedValue(subscriptionNullResponse);
|
2020-05-04 08:09:46 -04:00
|
|
|
|
2021-04-26 05:09:53 -04:00
|
|
|
const createComponent = ({
|
|
|
|
issuableType = 'issue',
|
|
|
|
issuableId = 1,
|
|
|
|
subscriptionHandler = subscriptionInitialHandler,
|
|
|
|
} = {}) => {
|
|
|
|
fakeApollo = createMockApollo([
|
2021-04-30 08:12:30 -04:00
|
|
|
[getIssueAssigneesQuery, issuableQueryHandler],
|
2021-04-26 05:09:53 -04:00
|
|
|
[issuableAssigneesSubscription, subscriptionHandler],
|
|
|
|
]);
|
2020-05-04 08:09:46 -04:00
|
|
|
wrapper = shallowMount(AssigneesRealtime, {
|
|
|
|
propsData: {
|
2021-04-13 05:11:10 -04:00
|
|
|
issuableType,
|
2021-04-26 05:09:53 -04:00
|
|
|
issuableId,
|
|
|
|
queryVariables: {
|
|
|
|
issuableIid: '1',
|
|
|
|
projectPath: 'path/to/project',
|
2020-05-04 08:09:46 -04:00
|
|
|
},
|
2021-04-26 05:09:53 -04:00
|
|
|
mediator,
|
2020-05-04 08:09:46 -04:00
|
|
|
},
|
2021-04-26 05:09:53 -04:00
|
|
|
apolloProvider: fakeApollo,
|
|
|
|
localVue,
|
2020-05-04 08:09:46 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mediator = new SidebarMediator(Mock.mediator);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
2021-04-26 05:09:53 -04:00
|
|
|
fakeApollo = null;
|
2020-05-04 08:09:46 -04:00
|
|
|
SidebarMediator.singleton = null;
|
|
|
|
});
|
|
|
|
|
2021-04-26 05:09:53 -04:00
|
|
|
it('calls the query with correct variables', () => {
|
|
|
|
createComponent();
|
2020-05-04 08:09:46 -04:00
|
|
|
|
2021-04-26 05:09:53 -04:00
|
|
|
expect(issuableQueryHandler).toHaveBeenCalledWith({
|
|
|
|
issuableIid: '1',
|
|
|
|
projectPath: 'path/to/project',
|
2020-05-04 08:09:46 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-26 05:09:53 -04:00
|
|
|
it('calls the subscription with correct variable for issue', () => {
|
|
|
|
createComponent();
|
2020-05-04 08:09:46 -04:00
|
|
|
|
2021-04-26 05:09:53 -04:00
|
|
|
expect(subscriptionInitialHandler).toHaveBeenCalledWith({
|
|
|
|
issuableId: 'gid://gitlab/Issue/1',
|
2020-05-04 08:09:46 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|