Commit 0011a0e9 authored by Mark Florian's avatar Mark Florian Committed by David O'Regan

Add variant and category props

These props are needed to support
https://gitlab.com/gitlab-org/gitlab/-/issues/328385,
part of https://gitlab.com/groups/gitlab-org/-/epics/5820.
parent 9e96a467
...@@ -16,6 +16,16 @@ export default { ...@@ -16,6 +16,16 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
variant: {
type: String,
required: false,
default: 'success',
},
category: {
type: String,
required: false,
default: 'secondary',
},
}, },
data() { data() {
return { return {
...@@ -65,8 +75,8 @@ export default { ...@@ -65,8 +75,8 @@ export default {
<gl-button <gl-button
v-if="!feature.configured" v-if="!feature.configured"
:loading="isLoading" :loading="isLoading"
variant="success" :variant="variant"
category="secondary" :category="category"
@click="mutate" @click="mutate"
>{{ $options.i18n.buttonLabel }}</gl-button >{{ $options.i18n.buttonLabel }}</gl-button
> >
......
...@@ -67,7 +67,7 @@ describe('ConfigurationTable component', () => { ...@@ -67,7 +67,7 @@ describe('ConfigurationTable component', () => {
gitlabCiHistoryPath: propsData.gitlabCiHistoryPath, gitlabCiHistoryPath: propsData.gitlabCiHistoryPath,
autoDevopsEnabled: propsData.autoDevopsEnabled, autoDevopsEnabled: propsData.autoDevopsEnabled,
}); });
expect(manage.find(ManageFeature).props()).toEqual({ feature }); expect(manage.find(ManageFeature).props()).toMatchObject({ feature });
expect(description.find(GlLink).attributes('href')).toBe(feature.helpPath); expect(description.find(GlLink).attributes('href')).toBe(feature.helpPath);
}); });
......
...@@ -73,7 +73,7 @@ describe('ManageFeature component', () => { ...@@ -73,7 +73,7 @@ describe('ManageFeature component', () => {
}); });
it('passes through props to expected component', () => { it('passes through props to expected component', () => {
expect(component.props()).toEqual({ feature }); expect(component.props()).toMatchObject({ feature });
}); });
}); });
......
...@@ -20,39 +20,22 @@ describe('ManageViaMr component', () => { ...@@ -20,39 +20,22 @@ describe('ManageViaMr component', () => {
const findButton = () => wrapper.findComponent(GlButton); const findButton = () => wrapper.findComponent(GlButton);
// This component supports different report types/mutations depending on function createMockApolloProvider(mutation, handler) {
// whether it's in a CE or EE context. This makes sure we are only testing
// the ones available in the current test context.
const supportedReportTypes = Object.entries(featureToMutationMap).map(
([featureType, { getMutationPayload, mutationId }]) => {
const { mutation } = getMutationPayload();
return [humanize(featureType), featureType, mutation, mutationId];
},
);
describe.each(supportedReportTypes)('%s', (featureName, featureType, mutation, mutationId) => {
const buildConfigureSecurityFeatureMock = buildConfigureSecurityFeatureMockFactory(mutationId);
const successHandler = async () => buildConfigureSecurityFeatureMock();
const noSuccessPathHandler = async () =>
buildConfigureSecurityFeatureMock({
successPath: '',
});
const errorHandler = async () =>
buildConfigureSecurityFeatureMock({
errors: ['foo'],
});
const pendingHandler = () => new Promise(() => {});
function createMockApolloProvider(handler) {
const requestHandlers = [[mutation, handler]]; const requestHandlers = [[mutation, handler]];
return createMockApollo(requestHandlers); return createMockApollo(requestHandlers);
} }
function createComponent({ mockApollo, isFeatureConfigured = false } = {}) { function createComponent({
featureName = 'SAST',
featureType = 'sast',
isFeatureConfigured = false,
variant = undefined,
category = undefined,
...options
} = {}) {
wrapper = extendedWrapper( wrapper = extendedWrapper(
mount(ManageViaMr, { mount(ManageViaMr, {
apolloProvider: mockApollo,
provide: { provide: {
projectPath: 'testProjectPath', projectPath: 'testProjectPath',
}, },
...@@ -62,7 +45,10 @@ describe('ManageViaMr component', () => { ...@@ -62,7 +45,10 @@ describe('ManageViaMr component', () => {
type: featureType, type: featureType,
configured: isFeatureConfigured, configured: isFeatureConfigured,
}, },
variant,
category,
}, },
...options,
}), }),
); );
} }
...@@ -71,10 +57,33 @@ describe('ManageViaMr component', () => { ...@@ -71,10 +57,33 @@ describe('ManageViaMr component', () => {
wrapper.destroy(); wrapper.destroy();
}); });
// This component supports different report types/mutations depending on
// whether it's in a CE or EE context. This makes sure we are only testing
// the ones available in the current test context.
const supportedReportTypes = Object.entries(featureToMutationMap).map(
([featureType, { getMutationPayload, mutationId }]) => {
const { mutation } = getMutationPayload();
return [humanize(featureType), featureType, mutation, mutationId];
},
);
describe.each(supportedReportTypes)('%s', (featureName, featureType, mutation, mutationId) => {
const buildConfigureSecurityFeatureMock = buildConfigureSecurityFeatureMockFactory(mutationId);
const successHandler = async () => buildConfigureSecurityFeatureMock();
const noSuccessPathHandler = async () =>
buildConfigureSecurityFeatureMock({
successPath: '',
});
const errorHandler = async () =>
buildConfigureSecurityFeatureMock({
errors: ['foo'],
});
const pendingHandler = () => new Promise(() => {});
describe('when feature is configured', () => { describe('when feature is configured', () => {
beforeEach(() => { beforeEach(() => {
const mockApollo = createMockApolloProvider(successHandler); const apolloProvider = createMockApolloProvider(mutation, successHandler);
createComponent({ mockApollo, isFeatureConfigured: true }); createComponent({ apolloProvider, featureName, featureType, isFeatureConfigured: true });
}); });
it('it does not render a button', () => { it('it does not render a button', () => {
...@@ -84,8 +93,8 @@ describe('ManageViaMr component', () => { ...@@ -84,8 +93,8 @@ describe('ManageViaMr component', () => {
describe('when feature is not configured', () => { describe('when feature is not configured', () => {
beforeEach(() => { beforeEach(() => {
const mockApollo = createMockApolloProvider(successHandler); const apolloProvider = createMockApolloProvider(mutation, successHandler);
createComponent({ mockApollo, isFeatureConfigured: false }); createComponent({ apolloProvider, featureName, featureType, isFeatureConfigured: false });
}); });
it('it does render a button', () => { it('it does render a button', () => {
...@@ -95,8 +104,8 @@ describe('ManageViaMr component', () => { ...@@ -95,8 +104,8 @@ describe('ManageViaMr component', () => {
describe('given a pending response', () => { describe('given a pending response', () => {
beforeEach(() => { beforeEach(() => {
const mockApollo = createMockApolloProvider(pendingHandler); const apolloProvider = createMockApolloProvider(mutation, pendingHandler);
createComponent({ mockApollo }); createComponent({ apolloProvider, featureName, featureType });
}); });
it('renders spinner correctly', async () => { it('renders spinner correctly', async () => {
...@@ -109,8 +118,8 @@ describe('ManageViaMr component', () => { ...@@ -109,8 +118,8 @@ describe('ManageViaMr component', () => {
describe('given a successful response', () => { describe('given a successful response', () => {
beforeEach(() => { beforeEach(() => {
const mockApollo = createMockApolloProvider(successHandler); const apolloProvider = createMockApolloProvider(mutation, successHandler);
createComponent({ mockApollo }); createComponent({ apolloProvider, featureName, featureType });
}); });
it('should call redirect helper with correct value', async () => { it('should call redirect helper with correct value', async () => {
...@@ -133,8 +142,8 @@ describe('ManageViaMr component', () => { ...@@ -133,8 +142,8 @@ describe('ManageViaMr component', () => {
${errorHandler} | ${'foo'} ${errorHandler} | ${'foo'}
`('given an error response', ({ handler, message }) => { `('given an error response', ({ handler, message }) => {
beforeEach(() => { beforeEach(() => {
const mockApollo = createMockApolloProvider(handler); const apolloProvider = createMockApolloProvider(mutation, handler);
createComponent({ mockApollo }); createComponent({ apolloProvider, featureName, featureType });
}); });
it('should catch and emit error', async () => { it('should catch and emit error', async () => {
...@@ -145,4 +154,17 @@ describe('ManageViaMr component', () => { ...@@ -145,4 +154,17 @@ describe('ManageViaMr component', () => {
}); });
}); });
}); });
describe('button props', () => {
it('passes the variant and category props to the GlButton', () => {
const variant = 'danger';
const category = 'tertiary';
createComponent({ variant, category });
expect(wrapper.findComponent(GlButton).props()).toMatchObject({
variant,
category,
});
});
});
}); });
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