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,6 +20,43 @@ describe('ManageViaMr component', () => { ...@@ -20,6 +20,43 @@ describe('ManageViaMr component', () => {
const findButton = () => wrapper.findComponent(GlButton); const findButton = () => wrapper.findComponent(GlButton);
function createMockApolloProvider(mutation, handler) {
const requestHandlers = [[mutation, handler]];
return createMockApollo(requestHandlers);
}
function createComponent({
featureName = 'SAST',
featureType = 'sast',
isFeatureConfigured = false,
variant = undefined,
category = undefined,
...options
} = {}) {
wrapper = extendedWrapper(
mount(ManageViaMr, {
provide: {
projectPath: 'testProjectPath',
},
propsData: {
feature: {
name: featureName,
type: featureType,
configured: isFeatureConfigured,
},
variant,
category,
},
...options,
}),
);
}
afterEach(() => {
wrapper.destroy();
});
// This component supports different report types/mutations depending on // 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 // whether it's in a CE or EE context. This makes sure we are only testing
// the ones available in the current test context. // the ones available in the current test context.
...@@ -43,38 +80,10 @@ describe('ManageViaMr component', () => { ...@@ -43,38 +80,10 @@ describe('ManageViaMr component', () => {
}); });
const pendingHandler = () => new Promise(() => {}); const pendingHandler = () => new Promise(() => {});
function createMockApolloProvider(handler) {
const requestHandlers = [[mutation, handler]];
return createMockApollo(requestHandlers);
}
function createComponent({ mockApollo, isFeatureConfigured = false } = {}) {
wrapper = extendedWrapper(
mount(ManageViaMr, {
apolloProvider: mockApollo,
provide: {
projectPath: 'testProjectPath',
},
propsData: {
feature: {
name: featureName,
type: featureType,
configured: isFeatureConfigured,
},
},
}),
);
}
afterEach(() => {
wrapper.destroy();
});
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