Commit 689606d6 authored by Vitaly Slobodin's avatar Vitaly Slobodin Committed by Brandon Labuschagne

Async import of Qrtly Recon Alert

parent bb30daee
...@@ -20,12 +20,17 @@ export default { ...@@ -20,12 +20,17 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
dotCom: { usesNamespacePlan: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
}, },
}, },
data() {
return {
isAlertDismissed: false,
};
},
computed: { computed: {
alertTitle() { alertTitle() {
return sprintf(this.$options.i18n.title, { qrtlyDate: this.formattedDate }); return sprintf(this.$options.i18n.title, { qrtlyDate: this.formattedDate });
...@@ -34,8 +39,8 @@ export default { ...@@ -34,8 +39,8 @@ export default {
return formatDate(this.date, 'isoDate'); return formatDate(this.date, 'isoDate');
}, },
description() { description() {
return this.dotCom return this.usesNamespacePlan
? this.$options.i18n.description.dotCom ? this.$options.i18n.description.usesNamespacePlan
: this.$options.i18n.description.ee; : this.$options.i18n.description.ee;
}, },
}, },
...@@ -44,6 +49,7 @@ export default { ...@@ -44,6 +49,7 @@ export default {
Cookie.set(this.cookieKey, true, { Cookie.set(this.cookieKey, true, {
expires: getDayDifference(new Date(), new Date(this.date)), expires: getDayDifference(new Date(), new Date(this.date)),
}); });
this.isAlertDismissed = true;
}, },
}, },
i18n, i18n,
...@@ -52,6 +58,7 @@ export default { ...@@ -52,6 +58,7 @@ export default {
<template> <template>
<gl-alert <gl-alert
v-if="!isAlertDismissed"
data-testid="qrtly-reconciliation-alert" data-testid="qrtly-reconciliation-alert"
variant="info" variant="info"
:title="alertTitle" :title="alertTitle"
......
...@@ -14,7 +14,7 @@ On %{qrtlyDate}, GitLab will process a quarterly reconciliation ...@@ -14,7 +14,7 @@ On %{qrtlyDate}, GitLab will process a quarterly reconciliation
and automatically bill you a prorated amount for the overage. and automatically bill you a prorated amount for the overage.
There is no action needed from you. If you have a credit card on file, There is no action needed from you. If you have a credit card on file,
it will be charged. Otherwise, you will receive an invoice.`), it will be charged. Otherwise, you will receive an invoice.`),
dotCom: s__(`Admin|The number of max seats used for your namespace is currently usesNamespacePlan: s__(`Admin|The number of max seats used for your namespace is currently
exceeding the number of seats in your subscription. exceeding the number of seats in your subscription.
On %{qrtlyDate}, GitLab will process a quarterly reconciliation and On %{qrtlyDate}, GitLab will process a quarterly reconciliation and
automatically bill you a prorated amount for the overage. automatically bill you a prorated amount for the overage.
......
export const shouldQrtlyReconciliationMount = async () => {
const el = document.querySelector('#js-qrtly-reconciliation-alert');
if (el) {
const { initQrtlyReconciliationAlert } = await import(
/* webpackChunkName: 'init_qrtly_reconciliation_alert' */ './init_qrtly_reconciliation_alert'
);
initQrtlyReconciliationAlert();
}
};
...@@ -8,7 +8,7 @@ export const initQrtlyReconciliationAlert = (selector = '#js-qrtly-reconciliatio ...@@ -8,7 +8,7 @@ export const initQrtlyReconciliationAlert = (selector = '#js-qrtly-reconciliatio
return false; return false;
} }
const { reconciliationDate, cookieKey, dotCom } = el.dataset; const { reconciliationDate, cookieKey, usesNamespacePlan } = el.dataset;
return new Vue({ return new Vue({
el, el,
...@@ -17,7 +17,7 @@ export const initQrtlyReconciliationAlert = (selector = '#js-qrtly-reconciliatio ...@@ -17,7 +17,7 @@ export const initQrtlyReconciliationAlert = (selector = '#js-qrtly-reconciliatio
props: { props: {
date: new Date(reconciliationDate), date: new Date(reconciliationDate),
cookieKey, cookieKey,
dotCom, usesNamespacePlan,
}, },
}); });
}, },
......
import { initQrtlyReconciliationAlert } from 'ee/billings/qrtly_reconciliation/init_qrtly_reconciliation_alert'; import { shouldQrtlyReconciliationMount } from 'ee/billings/qrtly_reconciliation';
initQrtlyReconciliationAlert(); shouldQrtlyReconciliationMount();
import { initQrtlyReconciliationAlert } from 'ee/billings/qrtly_reconciliation/init_qrtly_reconciliation_alert'; import { shouldQrtlyReconciliationMount } from 'ee/billings/qrtly_reconciliation';
initQrtlyReconciliationAlert(); shouldQrtlyReconciliationMount();
import { initQrtlyReconciliationAlert } from 'ee/billings/qrtly_reconciliation/init_qrtly_reconciliation_alert'; import { shouldQrtlyReconciliationMount } from 'ee/billings/qrtly_reconciliation';
import initSubscriptions from 'ee/billings/subscriptions'; import initSubscriptions from 'ee/billings/subscriptions';
import PersistentUserCallout from '~/persistent_user_callout'; import PersistentUserCallout from '~/persistent_user_callout';
PersistentUserCallout.factory(document.querySelector('.js-gold-trial-callout')); PersistentUserCallout.factory(document.querySelector('.js-gold-trial-callout'));
initSubscriptions(); initSubscriptions();
initQrtlyReconciliationAlert(); shouldQrtlyReconciliationMount();
import initGroupAnalytics from 'ee/analytics/group_analytics/group_analytics_bundle'; import initGroupAnalytics from 'ee/analytics/group_analytics/group_analytics_bundle';
import { initQrtlyReconciliationAlert } from 'ee/billings/qrtly_reconciliation/init_qrtly_reconciliation_alert'; import { shouldQrtlyReconciliationMount } from 'ee/billings/qrtly_reconciliation';
import leaveByUrl from '~/namespaces/leave_by_url'; import leaveByUrl from '~/namespaces/leave_by_url';
import initGroupDetails from '~/pages/groups/shared/group_details'; import initGroupDetails from '~/pages/groups/shared/group_details';
import initVueAlerts from '~/vue_alerts'; import initVueAlerts from '~/vue_alerts';
...@@ -8,4 +8,4 @@ leaveByUrl('group'); ...@@ -8,4 +8,4 @@ leaveByUrl('group');
initGroupDetails(); initGroupDetails();
initGroupAnalytics(); initGroupAnalytics();
initVueAlerts(); initVueAlerts();
initQrtlyReconciliationAlert(); shouldQrtlyReconciliationMount();
...@@ -10,7 +10,7 @@ module GitlabSubscriptions ...@@ -10,7 +10,7 @@ module GitlabSubscriptions
{ {
reconciliation_date: entity.next_reconciliation_date.to_s, reconciliation_date: entity.next_reconciliation_date.to_s,
cookie_key: entity.cookie_key, cookie_key: entity.cookie_key,
dot_com: Gitlab::CurrentSettings.should_check_namespace_plan? uses_namespace_plan: Gitlab::CurrentSettings.should_check_namespace_plan?
} }
end end
......
import { GlAlert } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Cookie from 'js-cookie';
import QrtlyReconciliationAlert from 'ee/billings/qrtly_reconciliation/components/qrtly_reconciliation_alert.vue';
jest.mock('js-cookie', () => ({
set: jest.fn(),
}));
describe('Qrtly Reconciliation Alert', () => {
let wrapper;
const reconciliationDate = new Date('2020-07-10');
const createComponent = () => {
return shallowMount(QrtlyReconciliationAlert, {
propsData: {
cookieKey: 'key',
date: reconciliationDate,
},
});
};
const findAlert = () => wrapper.findComponent(GlAlert);
beforeEach(() => {
wrapper = createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('Rendering', () => {
it('renders alert title with date', () => {
expect(findAlert().attributes('title')).toContain(`occur on 2020-07-10`);
});
it('has the correct link to the help page', () => {
expect(findAlert().attributes('primarybuttonlink')).toBe(
'/help/subscriptions/self_managed/index#quarterly-subscription-reconciliation',
);
});
it('has the correct link to contact support', () => {
expect(findAlert().attributes('secondarybuttonlink')).toBe(
'https://about.gitlab.com/support/#contact-support',
);
});
});
describe('methods', () => {
it('sets the cookie on dismis', () => {
findAlert().vm.$emit('dismiss');
expect(Cookie.set).toHaveBeenCalledTimes(1);
expect(Cookie.set).toHaveBeenCalledWith('key', true, { expires: 4 });
});
});
});
...@@ -24,15 +24,15 @@ describe('Qrtly Reconciliation Alert', () => { ...@@ -24,15 +24,15 @@ describe('Qrtly Reconciliation Alert', () => {
const findAlert = () => wrapper.find(GlAlert); const findAlert = () => wrapper.find(GlAlert);
beforeEach(() => {
wrapper = createComponent();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('Rendering', () => { describe('Rendering', () => {
beforeEach(() => {
wrapper = createComponent();
});
it('renders alert title with date', () => { it('renders alert title with date', () => {
expect(findAlert().attributes('title')).toContain(`occur on 2020-07-10`); expect(findAlert().attributes('title')).toContain(`occur on 2020-07-10`);
}); });
...@@ -51,14 +51,14 @@ describe('Qrtly Reconciliation Alert', () => { ...@@ -51,14 +51,14 @@ describe('Qrtly Reconciliation Alert', () => {
expect(wrapper.findComponent(GlSprintf).attributes('message')).toContain(i18n.description.ee); expect(wrapper.findComponent(GlSprintf).attributes('message')).toContain(i18n.description.ee);
}); });
describe('dotcom', () => { describe('when gitlab.com', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent({ dotCom: true }); wrapper = createComponent({ usesNamespacePlan: true });
}); });
it('has the correct description', () => { it('has the correct description', () => {
expect(wrapper.findComponent(GlSprintf).attributes('message')).toContain( expect(wrapper.findComponent(GlSprintf).attributes('message')).toContain(
i18n.description.dotCom, i18n.description.usesNamespacePlan,
); );
}); });
}); });
......
...@@ -27,7 +27,7 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do ...@@ -27,7 +27,7 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do
expect(helper.upcoming_reconciliation_hash(namespace)).to eq( expect(helper.upcoming_reconciliation_hash(namespace)).to eq(
reconciliation_date: upcoming_reconciliation.next_reconciliation_date.to_s, reconciliation_date: upcoming_reconciliation.next_reconciliation_date.to_s,
cookie_key: cookie_key, cookie_key: cookie_key,
dot_com: true uses_namespace_plan: true
) )
end end
...@@ -48,7 +48,7 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do ...@@ -48,7 +48,7 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do
expect(helper.upcoming_reconciliation_hash(group)).to eq( expect(helper.upcoming_reconciliation_hash(group)).to eq(
reconciliation_date: upcoming_reconciliation2.next_reconciliation_date.to_s, reconciliation_date: upcoming_reconciliation2.next_reconciliation_date.to_s,
cookie_key: cookie_key, cookie_key: cookie_key,
dot_com: true uses_namespace_plan: true
) )
end end
end end
...@@ -100,7 +100,7 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do ...@@ -100,7 +100,7 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do
expect(helper.upcoming_reconciliation_hash).to eq( expect(helper.upcoming_reconciliation_hash).to eq(
reconciliation_date: upcoming_reconciliation.next_reconciliation_date.to_s, reconciliation_date: upcoming_reconciliation.next_reconciliation_date.to_s,
cookie_key: cookie_key, cookie_key: cookie_key,
dot_com: false uses_namespace_plan: false
) )
end end
......
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