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,6 +70,7 @@ const defaultProps = { ...@@ -69,6 +70,7 @@ const defaultProps = {
}; };
const createComponent = ({ props = {}, loading = false } = {}) => const createComponent = ({ props = {}, loading = false } = {}) =>
extendedWrapper(
shallowMount(RequirementsRoot, { shallowMount(RequirementsRoot, {
propsData: { propsData: {
...defaultProps, ...defaultProps,
...@@ -92,13 +94,18 @@ const createComponent = ({ props = {}, loading = false } = {}) => ...@@ -92,13 +94,18 @@ const createComponent = ({ props = {}, loading = false } = {}) =>
}, },
$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,11 +114,13 @@ const createComponentWithApollo = ({ props = {}, requestHandlers } = {}) => { ...@@ -107,11 +114,13 @@ const createComponentWithApollo = ({ props = {}, requestHandlers } = {}) => {
}, },
); );
return shallowMount(RequirementsRoot, { return extendedWrapper(
shallowMount(RequirementsRoot, {
localVue, localVue,
apolloProvider: mockApollo, apolloProvider: mockApollo,
propsData: { propsData: {
...defaultProps, ...defaultProps,
initialRequirementsCount: mockInitialRequirementCounts,
...props, ...props,
}, },
mocks: { mocks: {
...@@ -122,15 +131,16 @@ const createComponentWithApollo = ({ props = {}, requestHandlers } = {}) => { ...@@ -122,15 +131,16 @@ const createComponentWithApollo = ({ props = {}, requestHandlers } = {}) => {
RequirementStatusBadge, RequirementStatusBadge,
GlIcon, 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