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.

116 lines
4.2 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 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,
2022-11-25 23:54:43 +05:30
workItemLabelsSubscriptionResponse,
2023-01-13 00:05:48 +05:30
workItemMilestoneSubscriptionResponse,
workItemDescriptionSubscriptionResponse,
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';
2023-06-20 00:43:36 +05:30
import workItemDatesSubscription from '~/graphql_shared/subscriptions/work_item_dates.subscription.graphql';
2022-10-11 01:57:18 +05:30
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';
2023-01-13 00:05:48 +05:30
import workItemMilestoneSubscription from '~/work_items/graphql/work_item_milestone.subscription.graphql';
import workItemDescriptionSubscription from '~/work_items/graphql/work_item_description.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';
2023-03-04 22:38:38 +05:30
jest.mock('~/behaviors/markdown/render_gfm');
2021-12-11 22:18:48 +05:30
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);
2022-11-25 23:54:43 +05:30
const assigneesSubscriptionHandler = jest
.fn()
.mockResolvedValue(workItemAssigneesSubscriptionResponse);
const labelsSubscriptionHandler = jest.fn().mockResolvedValue(workItemLabelsSubscriptionResponse);
2023-01-13 00:05:48 +05:30
const milestoneSubscriptionHandler = jest
.fn()
.mockResolvedValue(workItemMilestoneSubscriptionResponse);
const descriptionSubscriptionHandler = jest
.fn()
.mockResolvedValue(workItemDescriptionSubscriptionResponse);
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],
2023-01-13 00:05:48 +05:30
[workItemMilestoneSubscription, milestoneSubscriptionHandler],
[workItemDescriptionSubscription, descriptionSubscriptionHandler],
2022-10-11 01:57:18 +05:30
];
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',
2023-01-13 00:05:48 +05:30
hasIssueWeightsFeature: false,
2023-03-04 22:38:38 +05:30
hasIterationsFeature: false,
hasOkrsFeature: false,
hasIssuableHealthStatusFeature: false,
},
stubs: {
WorkItemWeight: true,
WorkItemIteration: true,
2023-03-17 16:20:25 +05:30
WorkItemHealthStatus: true,
2023-05-27 22:25:52 +05:30
WorkItemNotes: true,
2022-04-04 11:22:00 +05:30
},
2021-12-11 22:18:48 +05:30
});
};
2023-01-13 00:05:48 +05:30
beforeEach(() => {
window.gon = {
features: {
workItemsMvc2: false,
},
};
});
2021-12-11 22:18:48 +05:30
afterEach(() => {
2023-05-27 22:25:52 +05:30
// eslint-disable-next-line @gitlab/vtu-no-explicit-wrapper-destroy
2021-12-11 22:18:48 +05:30
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
2023-01-13 00:05:48 +05:30
it('does not render create work item page on `/new` route if `workItemsMvc2` feature flag is off', async () => {
await createComponent('/new');
expect(wrapper.findComponent(CreateWorkItem).exists()).toBe(false);
});
2022-01-26 12:08:38 +05:30
it('renders create work item page on `/new` route', async () => {
2023-01-13 00:05:48 +05:30
window.gon.features.workItemsMvc2 = true;
2022-01-26 12:08:38 +05:30
await createComponent('/new');
expect(wrapper.findComponent(CreateWorkItem).exists()).toBe(true);
});
2021-12-11 22:18:48 +05:30
});