2022-01-25 07:14:14 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Vue from 'vue';
|
2021-04-26 05:09:53 -04:00
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2022-04-01 14:08:46 -04:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
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';
|
2022-04-01 14:08:46 -04:00
|
|
|
import Mock, {
|
|
|
|
issuableQueryResponse,
|
|
|
|
subscriptionNullResponse,
|
|
|
|
subscriptionResponse,
|
|
|
|
} from './mock_data';
|
2020-05-04 08:09:46 -04:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
Vue.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',
|
|
|
|
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
|
|
|
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,
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-01 14:08:46 -04:00
|
|
|
it('calls the subscription with correct variable for issue', async () => {
|
2021-04-26 05:09:53 -04:00
|
|
|
createComponent();
|
2022-04-01 14:08:46 -04:00
|
|
|
await waitForPromises();
|
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
|
|
|
});
|
|
|
|
});
|
2022-04-01 14:08:46 -04:00
|
|
|
|
|
|
|
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-04 08:09:46 -04:00
|
|
|
});
|