Commit 27464ebd authored by Eulyeon Ko's avatar Eulyeon Ko Committed by Eulyeon Ko

Apply maintainer suggestions

- Use extendedWrapper for future maintainability
- Extract initial parameters into the wrapper creator.
parent 6a03f079
...@@ -21,6 +21,7 @@ import createMockApollo from 'helpers/mock_apollo_helper'; ...@@ -21,6 +21,7 @@ import createMockApollo from 'helpers/mock_apollo_helper';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import { mockTracking, unmockTracking } from 'helpers/tracking_helper'; import { mockTracking, unmockTracking } from 'helpers/tracking_helper';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import createFlash from '~/flash'; import createFlash from '~/flash';
import FilteredSearchBarRoot from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue'; import FilteredSearchBarRoot from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue';
...@@ -69,36 +70,42 @@ const defaultProps = { ...@@ -69,36 +70,42 @@ const defaultProps = {
}; };
const createComponent = ({ props = {}, loading = false } = {}) => const createComponent = ({ props = {}, loading = false } = {}) =>
shallowMount(RequirementsRoot, { extendedWrapper(
propsData: { shallowMount(RequirementsRoot, {
...defaultProps, propsData: {
...props, ...defaultProps,
}, ...props,
mocks: { },
$apollo: { mocks: {
queries: { $apollo: {
requirements: { queries: {
loading, requirements: {
list: [], loading,
pageInfo: {}, list: [],
refetch: jest.fn(), pageInfo: {},
}, refetch: jest.fn(),
requirementsCount: { },
...defaultProps.initialRequirementsCount, requirementsCount: {
refetch: jest.fn(), ...defaultProps.initialRequirementsCount,
refetch: jest.fn(),
},
}, },
mutate: jest.fn(),
}, },
mutate: jest.fn(), $toast,
}, },
$toast, }),
}, );
});
const createComponentWithApollo = ({ props = {}, requestHandlers } = {}) => { const createComponentWithApollo = ({ props = {}, requestHandlers = [] } = {}) => {
localVue.use(VueApollo); localVue.use(VueApollo);
const mockApollo = createMockApollo( const mockApollo = createMockApollo(
requestHandlers, [
[projectRequirements, jest.fn().mockResolvedValue(mockProjectRequirements)],
[projectRequirementsCount, jest.fn().mockResolvedValue(mockProjectRequirementCounts)],
...requestHandlers,
],
{}, {},
{ {
dataIdFromObject: (object) => dataIdFromObject: (object) =>
...@@ -107,30 +114,33 @@ const createComponentWithApollo = ({ props = {}, requestHandlers } = {}) => { ...@@ -107,30 +114,33 @@ const createComponentWithApollo = ({ props = {}, requestHandlers } = {}) => {
}, },
); );
return shallowMount(RequirementsRoot, { return extendedWrapper(
localVue, shallowMount(RequirementsRoot, {
apolloProvider: mockApollo, localVue,
propsData: { apolloProvider: mockApollo,
...defaultProps, propsData: {
...props, ...defaultProps,
}, initialRequirementsCount: mockInitialRequirementCounts,
mocks: { ...props,
$toast, },
}, mocks: {
stubs: { $toast,
RequirementItem, },
RequirementStatusBadge, stubs: {
GlIcon, RequirementItem,
}, RequirementStatusBadge,
}); GlIcon,
},
}),
);
}; };
describe('RequirementsRoot', () => { describe('RequirementsRoot', () => {
let wrapper; let wrapper;
let trackingSpy; let trackingSpy;
const findRequirementEditForm = () => wrapper.find("[data-testid='edit-form']"); const findRequirementEditForm = () => wrapper.findByTestId('edit-form');
const findFailedStatusIcon = () => wrapper.find("[data-testid='status_failed-icon']"); const findFailedStatusIcon = () => wrapper.findByTestId('status_failed-icon');
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); wrapper = createComponent();
...@@ -1044,15 +1054,8 @@ describe('RequirementsRoot', () => { ...@@ -1044,15 +1054,8 @@ describe('RequirementsRoot', () => {
beforeEach(() => { beforeEach(() => {
updateRequirementSpy = jest.fn().mockResolvedValue(mockUpdateRequirementToFailed); updateRequirementSpy = jest.fn().mockResolvedValue(mockUpdateRequirementToFailed);
const requestHandlers = [
[projectRequirements, jest.fn().mockResolvedValue(mockProjectRequirements)],
[projectRequirementsCount, jest.fn().mockResolvedValue(mockProjectRequirementCounts)],
[updateRequirement, updateRequirementSpy],
];
wrapper = createComponentWithApollo({ wrapper = createComponentWithApollo({
props: { initialRequirementsCount: mockInitialRequirementCounts }, requestHandlers: [[updateRequirement, updateRequirementSpy]],
requestHandlers,
}); });
}); });
...@@ -1092,15 +1095,8 @@ describe('RequirementsRoot', () => { ...@@ -1092,15 +1095,8 @@ describe('RequirementsRoot', () => {
beforeEach(async () => { beforeEach(async () => {
updateRequirementSpy = jest.fn().mockResolvedValue(mockUpdateRequirementTitle); updateRequirementSpy = jest.fn().mockResolvedValue(mockUpdateRequirementTitle);
const requestHandlers = [
[projectRequirements, jest.fn().mockResolvedValueOnce(mockProjectRequirements)],
[projectRequirementsCount, jest.fn().mockResolvedValue(mockProjectRequirementCounts)],
[updateRequirement, updateRequirementSpy],
];
wrapper = createComponentWithApollo({ wrapper = createComponentWithApollo({
props: { initialRequirementsCount: mockInitialRequirementCounts }, requestHandlers: [[updateRequirement, updateRequirementSpy]],
requestHandlers,
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment