Commit 2dea92b9 authored by Ammar Alakkad's avatar Ammar Alakkad Committed by Martin Wortschack

Fix manual renew button feature flag usage

parent 935ed217
...@@ -5,6 +5,7 @@ import { GlLoadingIcon } from '@gitlab/ui'; ...@@ -5,6 +5,7 @@ import { GlLoadingIcon } from '@gitlab/ui';
import { TABLE_TYPE_DEFAULT, TABLE_TYPE_FREE, TABLE_TYPE_TRIAL } from 'ee/billings/constants'; import { TABLE_TYPE_DEFAULT, TABLE_TYPE_FREE, TABLE_TYPE_TRIAL } from 'ee/billings/constants';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import SubscriptionTableRow from './subscription_table_row.vue'; import SubscriptionTableRow from './subscription_table_row.vue';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
export default { export default {
name: 'SubscriptionTable', name: 'SubscriptionTable',
...@@ -12,6 +13,7 @@ export default { ...@@ -12,6 +13,7 @@ export default {
SubscriptionTableRow, SubscriptionTableRow,
GlLoadingIcon, GlLoadingIcon,
}, },
mixins: [glFeatureFlagsMixin()],
props: { props: {
namespaceName: { namespaceName: {
type: String, type: String,
...@@ -54,7 +56,11 @@ export default { ...@@ -54,7 +56,11 @@ export default {
}; };
}, },
renewButton() { renewButton() {
if (this.isFreePlan && !this.plan.trial && !gon.features.saasManualRenewButton) { if (!this.glFeatures.saasManualRenewButton) {
return null;
}
if (this.isFreePlan) {
return null; return null;
} }
......
...@@ -6,10 +6,6 @@ Array [ ...@@ -6,10 +6,6 @@ Array [
"href": "http://test.host/plan/upgrade/bronze", "href": "http://test.host/plan/upgrade/bronze",
"text": "Upgrade", "text": "Upgrade",
}, },
Object {
"href": "http://test.host/plan/renew",
"text": "Renew",
},
Object { Object {
"href": "https://customers.gitlab.com/subscriptions", "href": "https://customers.gitlab.com/subscriptions",
"text": "Manage", "text": "Manage",
...@@ -23,10 +19,6 @@ Array [ ...@@ -23,10 +19,6 @@ Array [
"href": "http://test.host/plan/upgrade/free", "href": "http://test.host/plan/upgrade/free",
"text": "Upgrade", "text": "Upgrade",
}, },
Object {
"href": "http://test.host/plan/renew",
"text": "Renew",
},
Object { Object {
"href": "https://customers.gitlab.com/subscriptions", "href": "https://customers.gitlab.com/subscriptions",
"text": "Manage", "text": "Manage",
...@@ -36,10 +28,6 @@ Array [ ...@@ -36,10 +28,6 @@ Array [
exports[`SubscriptionTable component given a gold plan with state: isFreePlan=false, upgradable=false, isTrialPlan=false has Renew and Manage buttons 1`] = ` exports[`SubscriptionTable component given a gold plan with state: isFreePlan=false, upgradable=false, isTrialPlan=false has Renew and Manage buttons 1`] = `
Array [ Array [
Object {
"href": "http://test.host/plan/renew",
"text": "Renew",
},
Object { Object {
"href": "https://customers.gitlab.com/subscriptions", "href": "https://customers.gitlab.com/subscriptions",
"text": "Manage", "text": "Manage",
...@@ -49,10 +37,6 @@ Array [ ...@@ -49,10 +37,6 @@ Array [
exports[`SubscriptionTable component given a trial-gold plan with state: isFreePlan=false, upgradable=false, isTrialPlan=true has Manage button 1`] = ` exports[`SubscriptionTable component given a trial-gold plan with state: isFreePlan=false, upgradable=false, isTrialPlan=true has Manage button 1`] = `
Array [ Array [
Object {
"href": "http://test.host/plan/renew",
"text": "Renew",
},
Object { Object {
"href": "https://customers.gitlab.com/subscriptions", "href": "https://customers.gitlab.com/subscriptions",
"text": "Manage", "text": "Manage",
......
...@@ -20,6 +20,7 @@ describe('SubscriptionTable component', () => { ...@@ -20,6 +20,7 @@ describe('SubscriptionTable component', () => {
const findButtonProps = () => const findButtonProps = () =>
wrapper.findAll('a').wrappers.map(x => ({ text: x.text(), href: x.attributes('href') })); wrapper.findAll('a').wrappers.map(x => ({ text: x.text(), href: x.attributes('href') }));
const findRenewButton = () => findButtonProps().filter(({ text }) => text === 'Renew');
const factory = (options = {}) => { const factory = (options = {}) => {
store = new Vuex.Store(initialStore()); store = new Vuex.Store(initialStore());
...@@ -130,26 +131,39 @@ describe('SubscriptionTable component', () => { ...@@ -130,26 +131,39 @@ describe('SubscriptionTable component', () => {
}, },
); );
describe('render button', () => { describe.each`
window.gon = { features: {} }; planName | planCode | isFreePlan | isTrialPlan | featureFlag | expectedBehavior | testDescription
${'free'} | ${null} | ${true} | ${false} | ${true} | ${false} | ${'does not render the renew button for free plan'}
afterEach(() => { ${'gold-trial'} | ${null} | ${false} | ${true} | ${true} | ${false} | ${'does not render the renew button for trial plan'}
window.gon.features = {}; ${'silver'} | ${'silver'} | ${false} | ${false} | ${true} | ${true} | ${'renders the renew button for paid plans if feature flag is on'}
${'silver'} | ${'silver'} | ${false} | ${false} | ${false} | ${false} | ${'does not render the renew button for paid plans if feature flag is off'}
`(
'given plan with state: isFreePlan=$isFreePlan and feature flag saasManualRenewButton=$featureFlag',
({ planName, planCode, isFreePlan, featureFlag, testDescription, expectedBehavior }) => {
beforeEach(() => {
factory({
propsData: { namespaceName: TEST_NAMESPACE_NAME },
provide: {
glFeatures: {
saasManualRenewButton: featureFlag,
},
},
}); });
it('renders the renew button when feature flag is on', () => { Object.assign(store.state, {
gon.features.saasManualRenewButton = true; isLoadingSubscription: false,
factory({ propsData: { namespaceName: TEST_NAMESPACE_NAME } }); isFreePlan,
expect(findButtonProps()).toStrictEqual([ plan: {
{ text: 'Upgrade', href: '' }, code: planCode,
{ text: 'Renew', href: '' }, name: planName,
]); upgradable: true,
},
}); });
it('does not render the renew button when the feature flag is off', () => {
gon.features.saasManualRenewButton = false;
factory({ propsData: { namespaceName: TEST_NAMESPACE_NAME } });
expect(findButtonProps()).toStrictEqual([{ text: 'Upgrade', href: '' }]);
}); });
it(testDescription, () => {
expect(findRenewButton().length > 0).toBe(expectedBehavior);
}); });
},
);
}); });
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