debian-mirror-gitlab/spec/frontend/work_items/router_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
3.1 KiB
JavaScript
Raw Normal View History

2021-12-11 22:18:48 +05:30
import { mount } from '@vue/test-utils';
2022-10-11 01:57:18 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import workItemWeightSubscription from 'ee_component/work_items/graphql/work_item_weight.subscription.graphql';
import createMockApollo from 'helpers/mock_apollo_helper';
import {
2022-11-25 23:54:43 +05:30
workItemAssigneesSubscriptionResponse,
2022-10-11 01:57:18 +05:30
workItemDatesSubscriptionResponse,
workItemResponseFactory,
workItemTitleSubscriptionResponse,
workItemWeightSubscriptionResponse,
2022-11-25 23:54:43 +05:30
workItemLabelsSubscriptionResponse,
2022-10-11 01:57:18 +05:30
} from 'jest/work_items/mock_data';
2021-12-11 22:18:48 +05:30
import App from '~/work_items/components/app.vue';
2022-10-11 01:57:18 +05:30
import workItemQuery from '~/work_items/graphql/work_item.query.graphql';
import workItemDatesSubscription from '~/work_items/graphql/work_item_dates.subscription.graphql';
import workItemTitleSubscription from '~/work_items/graphql/work_item_title.subscription.graphql';
2022-11-25 23:54:43 +05:30
import workItemAssigneesSubscription from '~/work_items/graphql/work_item_assignees.subscription.graphql';
import workItemLabelsSubscription from 'ee_else_ce/work_items/graphql/work_item_labels.subscription.graphql';
2022-01-26 12:08:38 +05:30
import CreateWorkItem from '~/work_items/pages/create_work_item.vue';
2021-12-11 22:18:48 +05:30
import WorkItemsRoot from '~/work_items/pages/work_item_root.vue';
import { createRouter } from '~/work_items/router';
describe('Work items router', () => {
let wrapper;
2022-10-11 01:57:18 +05:30
Vue.use(VueApollo);
const workItemQueryHandler = jest.fn().mockResolvedValue(workItemResponseFactory());
const datesSubscriptionHandler = jest.fn().mockResolvedValue(workItemDatesSubscriptionResponse);
const titleSubscriptionHandler = jest.fn().mockResolvedValue(workItemTitleSubscriptionResponse);
const weightSubscriptionHandler = jest.fn().mockResolvedValue(workItemWeightSubscriptionResponse);
2022-11-25 23:54:43 +05:30
const assigneesSubscriptionHandler = jest
.fn()
.mockResolvedValue(workItemAssigneesSubscriptionResponse);
const labelsSubscriptionHandler = jest.fn().mockResolvedValue(workItemLabelsSubscriptionResponse);
2022-10-11 01:57:18 +05:30
2021-12-11 22:18:48 +05:30
const createComponent = async (routeArg) => {
const router = createRouter('/work_item');
if (routeArg !== undefined) {
await router.push(routeArg);
}
2022-10-11 01:57:18 +05:30
const handlers = [
[workItemQuery, workItemQueryHandler],
[workItemDatesSubscription, datesSubscriptionHandler],
[workItemTitleSubscription, titleSubscriptionHandler],
2022-11-25 23:54:43 +05:30
[workItemAssigneesSubscription, assigneesSubscriptionHandler],
[workItemLabelsSubscription, labelsSubscriptionHandler],
2022-10-11 01:57:18 +05:30
];
if (IS_EE) {
handlers.push([workItemWeightSubscription, weightSubscriptionHandler]);
}
2021-12-11 22:18:48 +05:30
wrapper = mount(App, {
2022-10-11 01:57:18 +05:30
apolloProvider: createMockApollo(handlers),
2021-12-11 22:18:48 +05:30
router,
2022-04-04 11:22:00 +05:30
provide: {
fullPath: 'full-path',
2022-07-16 23:28:13 +05:30
issuesListPath: 'full-path/-/issues',
2022-04-04 11:22:00 +05:30
},
2021-12-11 22:18:48 +05:30
});
};
afterEach(() => {
wrapper.destroy();
window.location.hash = '';
});
it('renders work item on `/1` route', async () => {
await createComponent('/1');
2022-06-21 17:19:12 +05:30
expect(wrapper.findComponent(WorkItemsRoot).exists()).toBe(true);
2021-12-11 22:18:48 +05:30
});
2022-01-26 12:08:38 +05:30
it('renders create work item page on `/new` route', async () => {
await createComponent('/new');
expect(wrapper.findComponent(CreateWorkItem).exists()).toBe(true);
});
2021-12-11 22:18:48 +05:30
});