Commit 65b0ce17 authored by Mark Florian's avatar Mark Florian Committed by David O'Regan

Recover test lost due to rebase

This recovers the test added in 139e730a
that was lost due a bad rebase of this branch.
parent 0011a0e9
...@@ -15,6 +15,8 @@ jest.mock('~/lib/utils/url_utility'); ...@@ -15,6 +15,8 @@ jest.mock('~/lib/utils/url_utility');
Vue.use(VueApollo); Vue.use(VueApollo);
const projectPath = 'namespace/project';
describe('ManageViaMr component', () => { describe('ManageViaMr component', () => {
let wrapper; let wrapper;
...@@ -37,7 +39,7 @@ describe('ManageViaMr component', () => { ...@@ -37,7 +39,7 @@ describe('ManageViaMr component', () => {
wrapper = extendedWrapper( wrapper = extendedWrapper(
mount(ManageViaMr, { mount(ManageViaMr, {
provide: { provide: {
projectPath: 'testProjectPath', projectPath,
}, },
propsData: { propsData: {
feature: { feature: {
...@@ -62,98 +64,110 @@ describe('ManageViaMr component', () => { ...@@ -62,98 +64,110 @@ describe('ManageViaMr component', () => {
// the ones available in the current test context. // the ones available in the current test context.
const supportedReportTypes = Object.entries(featureToMutationMap).map( const supportedReportTypes = Object.entries(featureToMutationMap).map(
([featureType, { getMutationPayload, mutationId }]) => { ([featureType, { getMutationPayload, mutationId }]) => {
const { mutation } = getMutationPayload(); const { mutation, variables: mutationVariables } = getMutationPayload(projectPath);
return [humanize(featureType), featureType, mutation, mutationId]; return [humanize(featureType), featureType, mutation, mutationId, mutationVariables];
}, },
); );
describe.each(supportedReportTypes)('%s', (featureName, featureType, mutation, mutationId) => { describe.each(supportedReportTypes)(
const buildConfigureSecurityFeatureMock = buildConfigureSecurityFeatureMockFactory(mutationId); '%s',
const successHandler = async () => buildConfigureSecurityFeatureMock(); (featureName, featureType, mutation, mutationId, mutationVariables) => {
const noSuccessPathHandler = async () => const buildConfigureSecurityFeatureMock = buildConfigureSecurityFeatureMockFactory(
buildConfigureSecurityFeatureMock({ mutationId,
successPath: '', );
}); const successHandler = jest.fn(async () => buildConfigureSecurityFeatureMock());
const errorHandler = async () => const noSuccessPathHandler = async () =>
buildConfigureSecurityFeatureMock({ buildConfigureSecurityFeatureMock({
errors: ['foo'], successPath: '',
});
const errorHandler = async () =>
buildConfigureSecurityFeatureMock({
errors: ['foo'],
});
const pendingHandler = () => new Promise(() => {});
describe('when feature is configured', () => {
beforeEach(() => {
const apolloProvider = createMockApolloProvider(mutation, successHandler);
createComponent({ apolloProvider, featureName, featureType, isFeatureConfigured: true });
});
it('it does not render a button', () => {
expect(findButton().exists()).toBe(false);
});
}); });
const pendingHandler = () => new Promise(() => {});
describe('when feature is configured', () => { describe('when feature is not configured', () => {
beforeEach(() => { beforeEach(() => {
const apolloProvider = createMockApolloProvider(mutation, successHandler); const apolloProvider = createMockApolloProvider(mutation, successHandler);
createComponent({ apolloProvider, featureName, featureType, isFeatureConfigured: true }); createComponent({ apolloProvider, featureName, featureType, isFeatureConfigured: false });
}); });
it('it does not render a button', () => {
expect(findButton().exists()).toBe(false);
});
});
describe('when feature is not configured', () => { it('it does render a button', () => {
beforeEach(() => { expect(findButton().exists()).toBe(true);
const apolloProvider = createMockApolloProvider(mutation, successHandler); });
createComponent({ apolloProvider, featureName, featureType, isFeatureConfigured: false });
});
it('it does render a button', () => { it('clicking on the button triggers the configure mutation', () => {
expect(findButton().exists()).toBe(true); findButton().trigger('click');
});
});
describe('given a pending response', () => { expect(successHandler).toHaveBeenCalledTimes(1);
beforeEach(() => { expect(successHandler).toHaveBeenCalledWith(mutationVariables);
const apolloProvider = createMockApolloProvider(mutation, pendingHandler); });
createComponent({ apolloProvider, featureName, featureType });
}); });
it('renders spinner correctly', async () => { describe('given a pending response', () => {
const button = findButton(); beforeEach(() => {
expect(button.props('loading')).toBe(false); const apolloProvider = createMockApolloProvider(mutation, pendingHandler);
await button.trigger('click'); createComponent({ apolloProvider, featureName, featureType });
expect(button.props('loading')).toBe(true); });
it('renders spinner correctly', async () => {
const button = findButton();
expect(button.props('loading')).toBe(false);
await button.trigger('click');
expect(button.props('loading')).toBe(true);
});
}); });
});
describe('given a successful response', () => { describe('given a successful response', () => {
beforeEach(() => { beforeEach(() => {
const apolloProvider = createMockApolloProvider(mutation, successHandler); const apolloProvider = createMockApolloProvider(mutation, successHandler);
createComponent({ apolloProvider, featureName, featureType }); createComponent({ apolloProvider, featureName, featureType });
});
it('should call redirect helper with correct value', async () => {
await wrapper.trigger('click');
await waitForPromises();
expect(redirectTo).toHaveBeenCalledTimes(1);
expect(redirectTo).toHaveBeenCalledWith('testSuccessPath');
// This is done for UX reasons. If the loading prop is set to false
// on success, then there's a period where the button is clickable
// again. Instead, we want the button to display a loading indicator
// for the remainder of the lifetime of the page (i.e., until the
// browser can start painting the new page it's been redirected to).
expect(findButton().props().loading).toBe(true);
});
}); });
it('should call redirect helper with correct value', async () => { describe.each`
await wrapper.trigger('click'); handler | message
await waitForPromises(); ${noSuccessPathHandler} | ${`${featureName} merge request creation mutation failed`}
expect(redirectTo).toHaveBeenCalledTimes(1); ${errorHandler} | ${'foo'}
expect(redirectTo).toHaveBeenCalledWith('testSuccessPath'); `('given an error response', ({ handler, message }) => {
// This is done for UX reasons. If the loading prop is set to false beforeEach(() => {
// on success, then there's a period where the button is clickable const apolloProvider = createMockApolloProvider(mutation, handler);
// again. Instead, we want the button to display a loading indicator createComponent({ apolloProvider, featureName, featureType });
// for the remainder of the lifetime of the page (i.e., until the });
// browser can start painting the new page it's been redirected to).
expect(findButton().props().loading).toBe(true); it('should catch and emit error', async () => {
await wrapper.trigger('click');
await waitForPromises();
expect(wrapper.emitted('error')).toEqual([[message]]);
expect(findButton().props('loading')).toBe(false);
});
}); });
}); },
);
describe.each`
handler | message
${noSuccessPathHandler} | ${`${featureName} merge request creation mutation failed`}
${errorHandler} | ${'foo'}
`('given an error response', ({ handler, message }) => {
beforeEach(() => {
const apolloProvider = createMockApolloProvider(mutation, handler);
createComponent({ apolloProvider, featureName, featureType });
});
it('should catch and emit error', async () => {
await wrapper.trigger('click');
await waitForPromises();
expect(wrapper.emitted('error')).toEqual([[message]]);
expect(findButton().props('loading')).toBe(false);
});
});
});
describe('button props', () => { describe('button props', () => {
it('passes the variant and category props to the GlButton', () => { it('passes the variant and category props to the GlButton', () => {
......
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