Commit 43650748 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'growth-87-billing-address-component' into 'master'

Billing address component for paid signup flow

Closes gitlab-org/growth/engineering#5052

See merge request gitlab-org/gitlab!21638
parents 49ce6812 7b0bcbda
......@@ -23,6 +23,11 @@ export default {
cycleAnalyticsStagePath: '/-/analytics/cycle_analytics/stages/:stage_id',
cycleAnalyticsDurationChartPath: '/-/analytics/cycle_analytics/stages/:stage_id/duration_chart',
codeReviewAnalyticsPath: '/api/:version/analytics/code_review',
countriesPath: '/-/countries',
countryStatesPath: '/-/country_states',
paymentFormPath: '/-/subscriptions/payment_form',
paymentMethodPath: '/-/subscriptions/payment_method',
confirmOrderPath: '/-/subscriptions',
userSubscription(namespaceId) {
const url = Api.buildUrl(this.subscriptionPath).replace(':id', encodeURIComponent(namespaceId));
......@@ -231,4 +236,29 @@ export default {
const url = Api.buildUrl(this.geoDesignsPath);
return axios.put(`${url}/${projectId}/${action}`, {});
},
fetchCountries() {
const url = Api.buildUrl(this.countriesPath);
return axios.get(url);
},
fetchStates(country) {
const url = Api.buildUrl(this.countryStatesPath);
return axios.get(url, { params: { country } });
},
fetchPaymentFormParams(id) {
const url = Api.buildUrl(this.paymentFormPath);
return axios.get(url, { params: { id } });
},
fetchPaymentMethodDetails(id) {
const url = Api.buildUrl(this.paymentMethodPath);
return axios.get(url, { params: { id } });
},
confirmOrder(params = {}) {
const url = Api.buildUrl(this.confirmOrderPath);
return axios.post(url, params);
},
};
......@@ -2,9 +2,12 @@
import { s__ } from '~/locale';
import ProgressBar from './checkout/progress_bar.vue';
import SubscriptionDetails from './checkout/subscription_details.vue';
import BillingAddress from './checkout/billing_address.vue';
import PaymentMethod from './checkout/payment_method.vue';
import ConfirmOrder from './checkout/confirm_order.vue';
export default {
components: { ProgressBar, SubscriptionDetails },
components: { ProgressBar, SubscriptionDetails, BillingAddress, PaymentMethod, ConfirmOrder },
i18n: {
checkout: s__('Checkout|Checkout'),
},
......@@ -17,6 +20,9 @@ export default {
<div class="flash-container"></div>
<h2 class="mt-4 mb-3 mb-lg-5">{{ $options.i18n.checkout }}</h2>
<subscription-details />
<billing-address />
<payment-method />
</div>
<confirm-order />
</div>
</template>
<script>
import _ from 'underscore';
import autofocusonshow from '~/vue_shared/directives/autofocusonshow';
import { mapState, mapActions } from 'vuex';
import { GlFormGroup, GlFormInput, GlFormSelect } from '@gitlab/ui';
import { s__ } from '~/locale';
import Step from './components/step.vue';
export default {
components: {
Step,
GlFormGroup,
GlFormInput,
GlFormSelect,
},
directives: {
autofocusonshow,
},
computed: {
...mapState([
'country',
'streetAddressLine1',
'streetAddressLine2',
'city',
'countryState',
'zipCode',
'countryOptions',
'stateOptions',
]),
countryModel: {
get() {
return this.country;
},
set(country) {
this.updateCountry(country);
},
},
streetAddressLine1Model: {
get() {
return this.streetAddressLine1;
},
set(streetAddressLine1) {
this.updateStreetAddressLine1(streetAddressLine1);
},
},
streetAddressLine2Model: {
get() {
return this.streetAddressLine2;
},
set(streetAddressLine2) {
this.updateStreetAddressLine2(streetAddressLine2);
},
},
cityModel: {
get() {
return this.city;
},
set(city) {
this.updateCity(city);
},
},
countryStateModel: {
get() {
return this.countryState;
},
set(countryState) {
this.updateCountryState(countryState);
},
},
zipCodeModel: {
get() {
return this.zipCode;
},
set(zipCode) {
this.updateZipCode(zipCode);
},
},
isValid() {
return (
!_.isEmpty(this.country) &&
!_.isEmpty(this.streetAddressLine1) &&
!_.isEmpty(this.city) &&
!_.isEmpty(this.zipCode)
);
},
countryOptionsWithDefault() {
return [
{
text: this.$options.i18n.countrySelectPrompt,
value: null,
},
...this.countryOptions,
];
},
stateOptionsWithDefault() {
return [
{
text: this.$options.i18n.stateSelectPrompt,
value: null,
},
...this.stateOptions,
];
},
},
mounted() {
this.fetchCountries();
},
methods: {
...mapActions([
'fetchCountries',
'fetchStates',
'updateCountry',
'updateStreetAddressLine1',
'updateStreetAddressLine2',
'updateCity',
'updateCountryState',
'updateZipCode',
]),
},
i18n: {
stepTitle: s__('Checkout|Billing address'),
nextStepButtonText: s__('Checkout|Continue to payment'),
countryLabel: s__('Checkout|Country'),
countrySelectPrompt: s__('Checkout|Please select a country'),
streetAddressLabel: s__('Checkout|Street address'),
cityLabel: s__('Checkout|City'),
stateLabel: s__('Checkout|State'),
stateSelectPrompt: s__('Checkout|Please select a state'),
zipCodeLabel: s__('Checkout|Zip code'),
},
};
</script>
<template>
<step
step="billingAddress"
:title="$options.i18n.stepTitle"
:is-valid="isValid"
:next-step-button-text="$options.i18n.nextStepButtonText"
>
<template #body>
<gl-form-group :label="$options.i18n.countryLabel" label-size="sm" class="mb-3">
<gl-form-select
v-model="countryModel"
v-autofocusonshow
:options="countryOptionsWithDefault"
class="js-country"
@change="fetchStates"
/>
</gl-form-group>
<gl-form-group :label="$options.i18n.streetAddressLabel" label-size="sm" class="mb-3">
<gl-form-input v-model="streetAddressLine1Model" type="text" />
<gl-form-input v-model="streetAddressLine2Model" type="text" class="mt-2" />
</gl-form-group>
<gl-form-group :label="$options.i18n.cityLabel" label-size="sm" class="mb-3">
<gl-form-input v-model="cityModel" type="text" />
</gl-form-group>
<div class="combined d-flex">
<gl-form-group :label="$options.i18n.stateLabel" label-size="sm" class="mr-3 w-50">
<gl-form-select v-model="countryStateModel" :options="stateOptionsWithDefault" />
</gl-form-group>
<gl-form-group :label="$options.i18n.zipCodeLabel" label-size="sm" class="w-50">
<gl-form-input v-model="zipCodeModel" type="text" />
</gl-form-group>
</div>
</template>
<template #summary>
<div class="js-summary-line-1">{{ streetAddressLine1 }}</div>
<div class="js-summary-line-2">{{ streetAddressLine2 }}</div>
<div class="js-summary-line-3">{{ city }}, {{ countryState }} {{ zipCode }}</div>
</template>
</step>
</template>
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { mapState, mapActions } from 'vuex';
import { ZUORA_SCRIPT_URL, ZUORA_IFRAME_OVERRIDE_PARAMS } from 'ee/subscriptions/new/constants';
export default {
components: {
GlLoadingIcon,
},
props: {
active: {
type: Boolean,
required: true,
},
},
computed: {
...mapState([
'paymentFormParams',
'paymentMethodId',
'creditCardDetails',
'isLoadingPaymentMethod',
]),
},
watch: {
// The Zuora script has loaded and the parameters for rendering the iframe have been fetched.
paymentFormParams() {
this.renderZuoraIframe();
},
},
mounted() {
this.loadZuoraScript();
},
methods: {
...mapActions([
'startLoadingZuoraScript',
'fetchPaymentFormParams',
'zuoraIframeRendered',
'paymentFormSubmitted',
]),
loadZuoraScript() {
this.startLoadingZuoraScript();
if (!window.Z) {
const zuoraScript = document.createElement('script');
zuoraScript.type = 'text/javascript';
zuoraScript.async = true;
zuoraScript.onload = this.fetchPaymentFormParams;
zuoraScript.src = ZUORA_SCRIPT_URL;
document.head.appendChild(zuoraScript);
} else {
this.fetchPaymentFormParams();
}
},
renderZuoraIframe() {
const params = { ...this.paymentFormParams, ...ZUORA_IFRAME_OVERRIDE_PARAMS };
window.Z.runAfterRender(this.zuoraIframeRendered);
window.Z.render(params, {}, this.paymentFormSubmitted);
},
},
};
</script>
<template>
<div>
<gl-loading-icon v-if="isLoadingPaymentMethod" size="lg" />
<div v-show="active && !isLoadingPaymentMethod" id="zuora_payment"></div>
</div>
</template>
<script>
import { mapState, mapActions, mapGetters } from 'vuex';
import { GlButton, GlLoadingIcon } from '@gitlab/ui';
import { s__ } from '~/locale';
export default {
components: {
GlButton,
GlLoadingIcon,
},
computed: {
...mapState(['isConfirmingOrder']),
...mapGetters(['currentStep']),
isActive() {
return this.currentStep === 'confirmOrder';
},
},
methods: {
...mapActions(['confirmOrder']),
},
i18n: {
confirm: s__('Checkout|Confirm purchase'),
confirming: s__('Checkout|Confirming...'),
},
};
</script>
<template>
<div v-if="isActive" class="full-width prepend-bottom-32">
<gl-button :disabled="isConfirmingOrder" variant="success" @click="confirmOrder">
<gl-loading-icon v-if="isConfirmingOrder" inline size="sm" />
{{ isConfirmingOrder ? $options.i18n.confirming : $options.i18n.confirm }}
</gl-button>
</div>
</template>
<script>
import { GlSprintf } from '@gitlab/ui';
import { sprintf, s__ } from '~/locale';
import { mapState } from 'vuex';
import Step from './components/step.vue';
import Zuora from './components/zuora.vue';
export default {
components: {
GlSprintf,
Step,
Zuora,
},
computed: {
...mapState(['paymentMethodId', 'creditCardDetails']),
isValid() {
return Boolean(this.paymentMethodId);
},
expirationDate() {
return sprintf(this.$options.i18n.expirationDate, {
expirationMonth: this.creditCardDetails.credit_card_expiration_month,
expirationYear: this.creditCardDetails.credit_card_expiration_year.toString(10).slice(-2),
});
},
},
i18n: {
stepTitle: s__('Checkout|Payment method'),
creditCardDetails: s__('Checkout|%{cardType} ending in %{lastFourDigits}'),
expirationDate: s__('Checkout|Exp %{expirationMonth}/%{expirationYear}'),
},
};
</script>
<template>
<step step="paymentMethod" :title="$options.i18n.stepTitle" :is-valid="isValid">
<template #body="props">
<zuora :active="props.active" />
</template>
<template #summary>
<div class="js-summary-line-1">
<gl-sprintf :message="$options.i18n.creditCardDetails">
<template #cardType>
{{ creditCardDetails.credit_card_type }}
</template>
<template #lastFourDigits>
<strong>{{ creditCardDetails.credit_card_mask_number.slice(-4) }}</strong>
</template>
</gl-sprintf>
</div>
<div class="js-summary-line-2">
{{ expirationDate }}
</div>
</template>
</step>
</template>
export const STEPS = ['subscriptionDetails'];
// The order of the steps in this array determines the flow of the application
export const STEPS = ['subscriptionDetails', 'billingAddress', 'paymentMethod', 'confirmOrder'];
export const ZUORA_SCRIPT_URL = 'https://static.zuora.com/Resources/libs/hosted/1.3.1/zuora-min.js';
export const PAYMENT_FORM_ID = 'paid_signup_flow';
export const ZUORA_IFRAME_OVERRIDE_PARAMS = {
style: 'inline',
submitEnabled: 'true',
retainValues: 'true',
};
export const TAX_RATE = 0;
import * as types from './mutation_types';
import { STEPS } from '../constants';
import { sprintf, s__ } from '~/locale';
import createFlash from '~/flash';
import Api from 'ee/api';
import { redirectTo } from '~/lib/utils/url_utility';
import { STEPS, PAYMENT_FORM_ID } from '../constants';
export const activateStep = ({ commit }, currentStep) => {
if (STEPS.includes(currentStep)) {
......@@ -32,3 +36,164 @@ export const updateNumberOfUsers = ({ commit }, numberOfUsers) => {
export const updateOrganizationName = ({ commit }, organizationName) => {
commit(types.UPDATE_ORGANIZATION_NAME, organizationName);
};
export const fetchCountries = ({ dispatch }) =>
Api.fetchCountries()
.then(({ data }) => dispatch('fetchCountriesSuccess', data))
.catch(() => dispatch('fetchCountriesError'));
export const fetchCountriesSuccess = ({ commit }, data = []) => {
const countries = data.map(country => ({ text: country[0], value: country[1] }));
commit(types.UPDATE_COUNTRY_OPTIONS, countries);
};
export const fetchCountriesError = () => {
createFlash(s__('Checkout|Failed to load countries. Please try again.'));
};
export const fetchStates = ({ state, dispatch }) => {
dispatch('resetStates');
if (!state.country) {
return;
}
Api.fetchStates(state.country)
.then(({ data }) => dispatch('fetchStatesSuccess', data))
.catch(() => dispatch('fetchStatesError'));
};
export const fetchStatesSuccess = ({ commit }, data = {}) => {
const states = Object.keys(data).map(state => ({ text: state, value: data[state] }));
commit(types.UPDATE_STATE_OPTIONS, states);
};
export const fetchStatesError = () => {
createFlash(s__('Checkout|Failed to load states. Please try again.'));
};
export const resetStates = ({ commit }) => {
commit(types.UPDATE_COUNTRY_STATE, null);
commit(types.UPDATE_STATE_OPTIONS, []);
};
export const updateCountry = ({ commit }, country) => {
commit(types.UPDATE_COUNTRY, country);
};
export const updateStreetAddressLine1 = ({ commit }, streetAddressLine1) => {
commit(types.UPDATE_STREET_ADDRESS_LINE_ONE, streetAddressLine1);
};
export const updateStreetAddressLine2 = ({ commit }, streetAddressLine2) => {
commit(types.UPDATE_STREET_ADDRESS_LINE_TWO, streetAddressLine2);
};
export const updateCity = ({ commit }, city) => {
commit(types.UPDATE_CITY, city);
};
export const updateCountryState = ({ commit }, countryState) => {
commit(types.UPDATE_COUNTRY_STATE, countryState);
};
export const updateZipCode = ({ commit }, zipCode) => {
commit(types.UPDATE_ZIP_CODE, zipCode);
};
export const startLoadingZuoraScript = ({ commit }) =>
commit(types.UPDATE_IS_LOADING_PAYMENT_METHOD, true);
export const fetchPaymentFormParams = ({ dispatch }) =>
Api.fetchPaymentFormParams(PAYMENT_FORM_ID)
.then(({ data }) => dispatch('fetchPaymentFormParamsSuccess', data))
.catch(() => dispatch('fetchPaymentFormParamsError'));
export const fetchPaymentFormParamsSuccess = ({ commit }, data) => {
if (data.errors) {
createFlash(
sprintf(s__('Checkout|Credit card form failed to load: %{message}'), {
message: data.errors,
}),
);
} else {
commit(types.UPDATE_PAYMENT_FORM_PARAMS, data);
}
};
export const fetchPaymentFormParamsError = () => {
createFlash(s__('Checkout|Credit card form failed to load. Please try again.'));
};
export const zuoraIframeRendered = ({ commit }) =>
commit(types.UPDATE_IS_LOADING_PAYMENT_METHOD, false);
export const paymentFormSubmitted = ({ dispatch, commit }, response) => {
if (response.success) {
commit(types.UPDATE_IS_LOADING_PAYMENT_METHOD, true);
dispatch('paymentFormSubmittedSuccess', response.refId);
} else {
dispatch('paymentFormSubmittedError', response);
}
};
export const paymentFormSubmittedSuccess = ({ commit, dispatch }, paymentMethodId) => {
commit(types.UPDATE_PAYMENT_METHOD_ID, paymentMethodId);
dispatch('fetchPaymentMethodDetails');
};
export const paymentFormSubmittedError = (_, response) => {
createFlash(
sprintf(
s__(
'Checkout|Submitting the credit card form failed with code %{errorCode}: %{errorMessage}',
),
response,
),
);
};
export const fetchPaymentMethodDetails = ({ state, dispatch, commit }) =>
Api.fetchPaymentMethodDetails(state.paymentMethodId)
.then(({ data }) => dispatch('fetchPaymentMethodDetailsSuccess', data))
.catch(() => dispatch('fetchPaymentMethodDetailsError'))
.finally(() => commit(types.UPDATE_IS_LOADING_PAYMENT_METHOD, false));
export const fetchPaymentMethodDetailsSuccess = ({ commit, dispatch }, creditCardDetails) => {
commit(types.UPDATE_CREDIT_CARD_DETAILS, creditCardDetails);
dispatch('activateNextStep');
};
export const fetchPaymentMethodDetailsError = () => {
createFlash(s__('Checkout|Failed to register credit card. Please try again.'));
};
export const confirmOrder = ({ getters, dispatch, commit }) => {
commit(types.UPDATE_IS_CONFIRMING_ORDER, true);
Api.confirmOrder(getters.confirmOrderParams)
.then(({ data }) => {
if (data.location) dispatch('confirmOrderSuccess', data.location);
else dispatch('confirmOrderError', JSON.stringify(data.errors));
})
.catch(() => dispatch('confirmOrderError'));
};
export const confirmOrderSuccess = (_, location) => {
redirectTo(location);
};
export const confirmOrderError = ({ commit }, message = null) => {
commit(types.UPDATE_IS_CONFIRMING_ORDER, false);
const errorString = message
? s__('Checkout|Failed to confirm your order: %{message}. Please try again.')
: s__('Checkout|Failed to confirm your order! Please try again.');
createFlash(sprintf(errorString, { message }, false));
};
......@@ -15,6 +15,24 @@ export const selectedPlanPrice = (state, getters) =>
export const selectedPlanDetails = state =>
state.availablePlans.find(plan => plan.value === state.selectedPlan);
export const confirmOrderParams = state => ({
setup_for_company: state.isSetupForCompany,
customer: {
country: state.country,
address_1: state.streetAddressLine1,
address_2: state.streetAddressLine2,
city: state.city,
state: state.countryState,
zip_code: state.zipCode,
company: state.organizationName,
},
subscription: {
plan_id: state.selectedPlan,
payment_method_id: state.paymentMethodId,
quantity: state.numberOfUsers,
},
});
export const endDate = state =>
new Date(state.startDate).setFullYear(state.startDate.getFullYear() + 1);
......
......@@ -7,3 +7,29 @@ export const UPDATE_IS_SETUP_FOR_COMPANY = 'UPDATE_IS_SETUP_FOR_COMPANY';
export const UPDATE_NUMBER_OF_USERS = 'UPDATE_NUMBER_OF_USERS';
export const UPDATE_ORGANIZATION_NAME = 'UPDATE_ORGANIZATION_NAME';
export const UPDATE_COUNTRY_OPTIONS = 'UPDATE_COUNTRY_OPTIONS';
export const UPDATE_STATE_OPTIONS = 'UPDATE_STATE_OPTIONS';
export const UPDATE_COUNTRY = 'UPDATE_COUNTRY';
export const UPDATE_STREET_ADDRESS_LINE_ONE = 'UPDATE_STREET_ADDRESS_LINE_ONE';
export const UPDATE_STREET_ADDRESS_LINE_TWO = 'UPDATE_STREET_ADDRESS_LINE_TWO';
export const UPDATE_CITY = 'UPDATE_CITY';
export const UPDATE_COUNTRY_STATE = 'UPDATE_COUNTRY_STATE';
export const UPDATE_ZIP_CODE = 'UPDATE_ZIP_CODE';
export const UPDATE_PAYMENT_FORM_PARAMS = 'UPDATE_PAYMENT_FORM_PARAMS';
export const UPDATE_PAYMENT_METHOD_ID = 'UPDATE_PAYMENT_METHOD_ID';
export const UPDATE_CREDIT_CARD_DETAILS = 'UPDATE_CREDIT_CARD_DETAILS';
export const UPDATE_IS_LOADING_PAYMENT_METHOD = 'UPDATE_IS_LOADING_PAYMENT_METHOD';
export const UPDATE_IS_CONFIRMING_ORDER = 'UPDATE_IS_CONFIRMING_ORDER';
......@@ -20,4 +20,56 @@ export default {
[types.UPDATE_ORGANIZATION_NAME](state, organizationName) {
state.organizationName = organizationName;
},
[types.UPDATE_COUNTRY_OPTIONS](state, countryOptions) {
state.countryOptions = countryOptions;
},
[types.UPDATE_STATE_OPTIONS](state, stateOptions) {
state.stateOptions = stateOptions;
},
[types.UPDATE_COUNTRY](state, country) {
state.country = country;
},
[types.UPDATE_STREET_ADDRESS_LINE_ONE](state, streetAddressLine1) {
state.streetAddressLine1 = streetAddressLine1;
},
[types.UPDATE_STREET_ADDRESS_LINE_TWO](state, streetAddressLine2) {
state.streetAddressLine2 = streetAddressLine2;
},
[types.UPDATE_CITY](state, city) {
state.city = city;
},
[types.UPDATE_COUNTRY_STATE](state, countryState) {
state.countryState = countryState;
},
[types.UPDATE_ZIP_CODE](state, zipCode) {
state.zipCode = zipCode;
},
[types.UPDATE_PAYMENT_FORM_PARAMS](state, paymentFormParams) {
state.paymentFormParams = paymentFormParams;
},
[types.UPDATE_PAYMENT_METHOD_ID](state, paymentMethodId) {
state.paymentMethodId = paymentMethodId;
},
[types.UPDATE_CREDIT_CARD_DETAILS](state, creditCardDetails) {
state.creditCardDetails = creditCardDetails;
},
[types.UPDATE_IS_LOADING_PAYMENT_METHOD](state, isLoadingPaymentMethod) {
state.isLoadingPaymentMethod = isLoadingPaymentMethod;
},
[types.UPDATE_IS_CONFIRMING_ORDER](state, isConfirmingOrder) {
state.isConfirmingOrder = isConfirmingOrder;
},
};
......@@ -27,6 +27,19 @@ export default ({ planData = '[]', planId, setupForCompany, fullName }) => {
fullName,
organizationName: null,
numberOfUsers: parseBoolean(setupForCompany) ? 0 : 1,
country: null,
streetAddressLine1: null,
streetAddressLine2: null,
city: null,
countryState: null,
zipCode: null,
countryOptions: [],
stateOptions: [],
paymentFormParams: {},
paymentMethodId: null,
creditCardDetails: {},
isLoadingPaymentMethod: false,
isConfirmingOrder: false,
taxRate: TAX_RATE,
startDate: new Date(Date.now()),
};
......
......@@ -83,15 +83,19 @@ $subscriptions-full-width-lg: 541px;
flex-grow: 1;
max-width: 420px;
legend {
border-bottom: 0;
font-weight: $gl-font-weight-bold;
}
.gl-form-input,
.gl-form-select {
height: 32px;
line-height: 1rem;
}
}
.number {
width: 50%;
@media(min-width: map-get($grid-breakpoints, lg)) {
max-width: 202px;
}
......@@ -99,7 +103,6 @@ $subscriptions-full-width-lg: 541px;
.label {
padding: 0;
width: 50%;
.gl-link {
font-size: inherit;
......@@ -130,6 +133,20 @@ $subscriptions-full-width-lg: 541px;
}
}
#zuora_payment {
margin-right: -8px;
@media(min-width: map-get($grid-breakpoints, lg)) {
margin-right: 0;
}
iframe {
background-color: $white-light;
margin: -4px;
width: 100% !important;
}
}
.order-summary {
max-width: $subscriptions-full-width-md;
......
import Vuex from 'vuex';
import { mount, createLocalVue } from '@vue/test-utils';
import createStore from 'ee/subscriptions/new/store';
import * as types from 'ee/subscriptions/new/store/mutation_types';
import Step from 'ee/subscriptions/new/components/checkout/components/step.vue';
import Component from 'ee/subscriptions/new/components/checkout/billing_address.vue';
describe('Billing Address', () => {
const localVue = createLocalVue();
localVue.use(Vuex);
let store;
let wrapper;
const methodMocks = {
fetchCountries: jest.fn(),
fetchStates: jest.fn(),
};
const createComponent = () => {
wrapper = mount(Component, {
localVue,
store,
methods: methodMocks,
});
};
beforeEach(() => {
store = createStore();
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('mounted', () => {
it('should load the countries', () => {
expect(methodMocks.fetchCountries).toHaveBeenCalled();
});
});
describe('country options', () => {
const countrySelect = () => wrapper.find('.js-country');
beforeEach(() => {
store.commit(types.UPDATE_COUNTRY_OPTIONS, [{ text: 'Netherlands', value: 'NL' }]);
});
it('should display the select prompt', () => {
expect(countrySelect().html()).toContain('<option value="">Please select a country</option>');
});
it('should display the countries returned from the server', () => {
expect(countrySelect().html()).toContain('<option value="NL">Netherlands</option>');
});
it('should fetch states when selecting a country', () => {
countrySelect().trigger('change');
return localVue.nextTick().then(() => {
expect(methodMocks.fetchStates).toHaveBeenCalled();
});
});
});
describe('validations', () => {
const isStepValid = () => wrapper.find(Step).props('isValid');
beforeEach(() => {
store.commit(types.UPDATE_COUNTRY, 'country');
store.commit(types.UPDATE_STREET_ADDRESS_LINE_ONE, 'address line 1');
store.commit(types.UPDATE_CITY, 'city');
store.commit(types.UPDATE_ZIP_CODE, 'zip');
});
it('should be valid when country, streetAddressLine1, city and zipCode have been entered', () => {
expect(isStepValid()).toBe(true);
});
it('should be invalid when country is undefined', () => {
store.commit(types.UPDATE_COUNTRY, null);
return localVue.nextTick().then(() => {
expect(isStepValid()).toBe(false);
});
});
it('should be invalid when streetAddressLine1 is undefined', () => {
store.commit(types.UPDATE_STREET_ADDRESS_LINE_ONE, null);
return localVue.nextTick().then(() => {
expect(isStepValid()).toBe(false);
});
});
it('should be invalid when city is undefined', () => {
store.commit(types.UPDATE_CITY, null);
return localVue.nextTick().then(() => {
expect(isStepValid()).toBe(false);
});
});
it('should be invalid when zipCode is undefined', () => {
store.commit(types.UPDATE_ZIP_CODE, null);
return localVue.nextTick().then(() => {
expect(isStepValid()).toBe(false);
});
});
});
describe('showing the summary', () => {
beforeEach(() => {
store.commit(types.UPDATE_COUNTRY, 'country');
store.commit(types.UPDATE_STREET_ADDRESS_LINE_ONE, 'address line 1');
store.commit(types.UPDATE_STREET_ADDRESS_LINE_TWO, 'address line 2');
store.commit(types.UPDATE_COUNTRY_STATE, 'state');
store.commit(types.UPDATE_CITY, 'city');
store.commit(types.UPDATE_ZIP_CODE, 'zip');
store.commit(types.UPDATE_CURRENT_STEP, 'nextStep');
});
it('should show the entered address line 1', () => {
expect(wrapper.find('.js-summary-line-1').text()).toEqual('address line 1');
});
it('should show the entered address line 2', () => {
expect(wrapper.find('.js-summary-line-2').text()).toEqual('address line 2');
});
it('should show the entered address city, state and zip code', () => {
expect(wrapper.find('.js-summary-line-3').text()).toEqual('city, state zip');
});
});
});
......@@ -3,17 +3,16 @@ import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui';
import createStore from 'ee/subscriptions/new/store';
import * as constants from 'ee/subscriptions/new/constants';
import component from 'ee/subscriptions/new/components/checkout/components/step.vue';
import Component from 'ee/subscriptions/new/components/checkout/components/step.vue';
import StepSummary from 'ee/subscriptions/new/components/checkout/components/step_summary.vue';
describe('Step', () => {
const localVue = createLocalVue();
localVue.use(Vuex);
let store;
let wrapper;
const store = createStore();
const initialProps = {
step: 'secondStep',
isValid: true,
......@@ -21,11 +20,11 @@ describe('Step', () => {
nextStepButtonText: 'next',
};
const factory = propsData => {
wrapper = shallowMount(component, {
store,
const createComponent = propsData => {
wrapper = shallowMount(Component, {
propsData: { ...initialProps, ...propsData },
localVue,
store,
});
};
......@@ -36,6 +35,7 @@ describe('Step', () => {
constants.STEPS = ['firstStep', 'secondStep'];
beforeEach(() => {
store = createStore();
store.dispatch('activateStep', 'secondStep');
});
......@@ -45,14 +45,14 @@ describe('Step', () => {
describe('Step Body', () => {
it('should display the step body when this step is the current step', () => {
factory();
createComponent();
expect(wrapper.find('.card > div').attributes('style')).toBeUndefined();
});
it('should not display the step body when this step is not the current step', () => {
activatePreviousStep();
factory();
createComponent();
expect(wrapper.find('.card > div').attributes('style')).toBe('display: none;');
});
......@@ -61,26 +61,26 @@ describe('Step', () => {
describe('Step Summary', () => {
it('should be shown when this step is valid and not active', () => {
activatePreviousStep();
factory();
createComponent();
expect(wrapper.find(StepSummary).exists()).toBe(true);
});
it('should not be shown when this step is not valid and not active', () => {
activatePreviousStep();
factory({ isValid: false });
createComponent({ isValid: false });
expect(wrapper.find(StepSummary).exists()).toBe(false);
});
it('should not be shown when this step is valid and active', () => {
factory();
createComponent();
expect(wrapper.find(StepSummary).exists()).toBe(false);
});
it('should not be shown when this step is not valid and active', () => {
factory({ isValid: false });
createComponent({ isValid: false });
expect(wrapper.find(StepSummary).exists()).toBe(false);
});
......@@ -88,7 +88,7 @@ describe('Step', () => {
describe('isEditable', () => {
it('should set the isEditable property to true when this step is finished and comes before the current step', () => {
factory({ step: 'firstStep' });
createComponent({ step: 'firstStep' });
expect(wrapper.find(StepSummary).props('isEditable')).toBe(true);
});
......@@ -97,13 +97,13 @@ describe('Step', () => {
describe('Showing the summary', () => {
it('shows the summary when this step is finished', () => {
activatePreviousStep();
factory();
createComponent();
expect(wrapper.find(StepSummary).exists()).toBe(true);
});
it('does not show the summary when this step is not finished', () => {
factory();
createComponent();
expect(wrapper.find(StepSummary).exists()).toBe(false);
});
......@@ -111,25 +111,25 @@ describe('Step', () => {
describe('Next button', () => {
it('shows the next button when the text was passed', () => {
factory();
createComponent();
expect(wrapper.text()).toBe('next');
});
it('does not show the next button when no text was passed', () => {
factory({ nextStepButtonText: '' });
createComponent({ nextStepButtonText: '' });
expect(wrapper.text()).toBe('');
});
it('is disabled when this step is not valid', () => {
factory({ isValid: false });
createComponent({ isValid: false });
expect(wrapper.find(GlButton).attributes('disabled')).toBe('true');
});
it('is enabled when this step is valid', () => {
factory();
createComponent();
expect(wrapper.find(GlButton).attributes('disabled')).toBeUndefined();
});
......
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import createStore from 'ee/subscriptions/new/store';
import * as types from 'ee/subscriptions/new/store/mutation_types';
import { GlLoadingIcon } from '@gitlab/ui';
import Component from 'ee/subscriptions/new/components/checkout/components/zuora.vue';
describe('Zuora', () => {
const localVue = createLocalVue();
localVue.use(Vuex);
let store;
let wrapper;
const methodMocks = {
loadZuoraScript: jest.fn(),
renderZuoraIframe: jest.fn(),
};
const createComponent = (props = {}) => {
wrapper = shallowMount(Component, {
propsData: {
active: true,
...props,
},
localVue,
sync: false,
store,
methods: methodMocks,
});
};
const findLoading = () => wrapper.find(GlLoadingIcon);
const findZuoraPayment = () => wrapper.find('#zuora_payment');
beforeEach(() => {
store = createStore();
});
afterEach(() => {
wrapper.destroy();
});
describe('mounted', () => {
it('should call loadZuoraScript', () => {
createComponent();
expect(methodMocks.loadZuoraScript).toHaveBeenCalled();
});
});
describe('when active', () => {
beforeEach(() => {
createComponent();
});
it('does not show the loading icon', () => {
expect(findLoading().exists()).toBe(false);
});
it('the zuora_payment selector should be visible', () => {
expect(findZuoraPayment().element.style.display).toEqual('');
});
describe('when toggling the loading indicator', () => {
beforeEach(() => {
store.commit(types.UPDATE_IS_LOADING_PAYMENT_METHOD, true);
return localVue.nextTick();
});
it('shows the loading icon', () => {
expect(findLoading().exists()).toBe(true);
});
it('the zuora_payment selector should not be visible', () => {
expect(findZuoraPayment().element.style.display).toEqual('none');
});
});
});
describe('when not active', () => {
beforeEach(() => {
createComponent({ active: false });
});
it('does not show loading icon', () => {
expect(findLoading().exists()).toBe(false);
});
it('the zuora_payment selector should not be visible', () => {
expect(findZuoraPayment().element.style.display).toEqual('none');
});
});
describe('renderZuoraIframe', () => {
it('is called when the paymentFormParams are updated', () => {
createComponent();
expect(methodMocks.renderZuoraIframe).not.toHaveBeenCalled();
store.commit(types.UPDATE_PAYMENT_FORM_PARAMS, {});
return localVue.nextTick().then(() => {
expect(methodMocks.renderZuoraIframe).toHaveBeenCalled();
});
});
});
});
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import createStore from 'ee/subscriptions/new/store';
import * as types from 'ee/subscriptions/new/store/mutation_types';
import { GlButton } from '@gitlab/ui';
import Component from 'ee/subscriptions/new/components/checkout/confirm_order.vue';
describe('Confirm Order', () => {
const localVue = createLocalVue();
localVue.use(Vuex);
let wrapper;
const store = createStore();
const createComponent = (opts = {}) => {
wrapper = shallowMount(Component, {
localVue,
store,
...opts,
});
};
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('Active', () => {
beforeEach(() => {
store.commit(types.UPDATE_CURRENT_STEP, 'confirmOrder');
});
it('button should be visible', () => {
expect(wrapper.find(GlButton).exists()).toBe(true);
});
});
describe('Inactive', () => {
beforeEach(() => {
store.commit(types.UPDATE_CURRENT_STEP, 'otherStep');
});
it('button should not be visible', () => {
expect(wrapper.find(GlButton).exists()).toBe(false);
});
});
});
import Vuex from 'vuex';
import { mount, createLocalVue } from '@vue/test-utils';
import createStore from 'ee/subscriptions/new/store';
import * as types from 'ee/subscriptions/new/store/mutation_types';
import Step from 'ee/subscriptions/new/components/checkout/components/step.vue';
import Component from 'ee/subscriptions/new/components/checkout/payment_method.vue';
describe('Payment Method', () => {
const localVue = createLocalVue();
localVue.use(Vuex);
let store;
let wrapper;
const createComponent = (opts = {}) => {
wrapper = mount(Component, {
localVue,
store,
...opts,
});
};
beforeEach(() => {
store = createStore();
store.commit(types.UPDATE_PAYMENT_METHOD_ID, 'paymentMethodId');
store.commit(types.UPDATE_CREDIT_CARD_DETAILS, {
credit_card_type: 'Visa',
credit_card_mask_number: '************4242',
credit_card_expiration_month: 12,
credit_card_expiration_year: 2009,
});
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('validations', () => {
const isStepValid = () => wrapper.find(Step).props('isValid');
it('should be valid when paymentMethodId is defined', () => {
expect(isStepValid()).toBe(true);
});
it('should be invalid when paymentMethodId is undefined', () => {
store.commit(types.UPDATE_PAYMENT_METHOD_ID, null);
return localVue.nextTick().then(() => {
expect(isStepValid()).toBe(false);
});
});
});
describe('showing the summary', () => {
it('should show the entered credit card details', () => {
expect(
wrapper
.find('.js-summary-line-1')
.html()
.replace(/\s+/g, ' '),
).toContain('Visa ending in <strong>4242</strong>');
});
it('should show the entered credit card expiration date', () => {
expect(wrapper.find('.js-summary-line-2').text()).toEqual('Exp 12/09');
});
});
});
import { shallowMount } from '@vue/test-utils';
import component from 'ee/subscriptions/new/components/checkout/progress_bar.vue';
import Component from 'ee/subscriptions/new/components/checkout/progress_bar.vue';
describe('Progress Bar', () => {
let wrapper;
const factory = propsData => {
wrapper = shallowMount(component, {
const createComponent = propsData => {
wrapper = shallowMount(Component, {
propsData,
});
};
......@@ -14,7 +14,7 @@ describe('Progress Bar', () => {
const secondStep = () => wrapper.find('.bar div:nth-child(2)');
beforeEach(() => {
factory({ step: 2 });
createComponent({ step: 2 });
});
afterEach(() => {
......
......@@ -9,6 +9,7 @@ describe('Subscription Details', () => {
const localVue = createLocalVue();
localVue.use(Vuex);
let store;
let wrapper;
const planData = [
......@@ -23,17 +24,17 @@ describe('Subscription Details', () => {
fullName: 'Full Name',
};
const store = createStore(initialData);
const isStepValid = () => wrapper.find(Step).props('isValid');
const createComponent = (opts = {}) => {
const createComponent = () => {
wrapper = mount(Component, {
localVue,
store,
...opts,
});
};
beforeEach(() => {
store = createStore(initialData);
createComponent();
});
......@@ -41,8 +42,6 @@ describe('Subscription Details', () => {
wrapper.destroy();
});
const isStepValid = () => wrapper.find(Step).props('isValid');
describe('Setting up for personal use', () => {
beforeEach(() => {
store.commit(types.UPDATE_IS_SETUP_FOR_COMPANY, false);
......
......@@ -13,6 +13,15 @@ const state = {
},
],
selectedPlan: 'firstPlan',
country: 'Country',
streetAddressLine1: 'Street address line 1',
streetAddressLine2: 'Street address line 2',
city: 'City',
countryState: 'State',
zipCode: 'Zip code',
organizationName: 'Organization name',
paymentMethodId: 'Payment method ID',
numberOfUsers: 1,
};
describe('Subscriptions Getters', () => {
......@@ -113,4 +122,26 @@ describe('Subscriptions Getters', () => {
expect(getters.usersPresent({ numberOfUsers: 0 })).toBe(false);
});
});
describe('confirmOrderParams', () => {
it('returns the params to confirm the order', () => {
expect(getters.confirmOrderParams(state)).toEqual({
setup_for_company: true,
customer: {
country: 'Country',
address_1: 'Street address line 1',
address_2: 'Street address line 2',
city: 'City',
state: 'State',
zip_code: 'Zip code',
company: 'Organization name',
},
subscription: {
plan_id: 'firstPlan',
payment_method_id: 'Payment method ID',
quantity: 1,
},
});
});
});
});
......@@ -7,6 +7,10 @@ const state = () => ({
isSetupForCompany: true,
numberOfUsers: 1,
organizationName: 'name',
countryOptions: [],
stateOptions: [],
isLoadingPaymentMethod: false,
isConfirmingOrder: false,
});
let stateCopy;
......@@ -15,42 +19,34 @@ beforeEach(() => {
stateCopy = state();
});
describe('UPDATE_CURRENT_STEP', () => {
it('should set the currentStep to the given step', () => {
mutations[types.UPDATE_CURRENT_STEP](stateCopy, 'secondStep');
expect(stateCopy.currentStep).toEqual('secondStep');
});
});
describe('UPDATE_SELECTED_PLAN', () => {
it('should set the selectedPlan to the given plan', () => {
mutations[types.UPDATE_SELECTED_PLAN](stateCopy, 'secondPlan');
expect(stateCopy.selectedPlan).toEqual('secondPlan');
});
});
describe('UPDATE_IS_SETUP_FOR_COMPANY', () => {
it('should set the isSetupForCompany to the given boolean', () => {
mutations[types.UPDATE_IS_SETUP_FOR_COMPANY](stateCopy, false);
expect(stateCopy.isSetupForCompany).toEqual(false);
});
});
describe('UPDATE_NUMBER_OF_USERS', () => {
it('should set the numberOfUsers to the given number', () => {
mutations[types.UPDATE_NUMBER_OF_USERS](stateCopy, 2);
expect(stateCopy.numberOfUsers).toEqual(2);
});
});
describe('UPDATE_ORGANIZATION_NAME', () => {
it('should set the organizationName to the given name', () => {
mutations[types.UPDATE_ORGANIZATION_NAME](stateCopy, 'new name');
expect(stateCopy.organizationName).toEqual('new name');
describe('ee/subscriptions/new/store/mutation', () => {
describe.each`
mutation | value | stateProp
${types.UPDATE_CURRENT_STEP} | ${'secondStep'} | ${'currentStep'}
${types.UPDATE_SELECTED_PLAN} | ${'secondPlan'} | ${'selectedPlan'}
${types.UPDATE_IS_SETUP_FOR_COMPANY} | ${false} | ${'isSetupForCompany'}
${types.UPDATE_NUMBER_OF_USERS} | ${2} | ${'numberOfUsers'}
${types.UPDATE_ORGANIZATION_NAME} | ${'new name'} | ${'organizationName'}
${types.UPDATE_COUNTRY_OPTIONS} | ${[{ text: 'country', value: 'id' }]} | ${'countryOptions'}
${types.UPDATE_STATE_OPTIONS} | ${[{ text: 'state', value: 'id' }]} | ${'stateOptions'}
${types.UPDATE_COUNTRY} | ${'NL'} | ${'country'}
${types.UPDATE_STREET_ADDRESS_LINE_ONE} | ${'streetAddressLine1'} | ${'streetAddressLine1'}
${types.UPDATE_STREET_ADDRESS_LINE_TWO} | ${'streetAddressLine2'} | ${'streetAddressLine2'}
${types.UPDATE_CITY} | ${'city'} | ${'city'}
${types.UPDATE_COUNTRY_STATE} | ${'countryState'} | ${'countryState'}
${types.UPDATE_ZIP_CODE} | ${'zipCode'} | ${'zipCode'}
${types.UPDATE_PAYMENT_FORM_PARAMS} | ${{ token: 'x' }} | ${'paymentFormParams'}
${types.UPDATE_PAYMENT_METHOD_ID} | ${'paymentMethodId'} | ${'paymentMethodId'}
${types.UPDATE_CREDIT_CARD_DETAILS} | ${{ type: 'x' }} | ${'creditCardDetails'}
${types.UPDATE_IS_LOADING_PAYMENT_METHOD} | ${true} | ${'isLoadingPaymentMethod'}
${types.UPDATE_IS_CONFIRMING_ORDER} | ${true} | ${'isConfirmingOrder'}
`('$mutation', ({ mutation, value, stateProp }) => {
it(`should set the ${stateProp} to the given value`, () => {
expect(stateCopy[stateProp]).not.toEqual(value);
mutations[mutation](stateCopy, value);
expect(stateCopy[stateProp]).toEqual(value);
});
});
});
......@@ -98,15 +98,63 @@ describe('projectsSelector default state', () => {
});
});
describe('taxRate', () => {
it('sets the taxRate to the TAX_RATE constant', () => {
expect(state.taxRate).toEqual(0);
});
it('sets the country to null', () => {
expect(state.country).toBeNull();
});
describe('startDate', () => {
it('sets the startDate to the current date', () => {
expect(state.startDate).toEqual(currentDate);
});
it('sets the streetAddressLine1 to null', () => {
expect(state.streetAddressLine1).toBeNull();
});
it('sets the streetAddressLine2 to null', () => {
expect(state.streetAddressLine2).toBeNull();
});
it('sets the city to null', () => {
expect(state.city).toBeNull();
});
it('sets the countryState to null', () => {
expect(state.countryState).toBeNull();
});
it('sets the zipCode to null', () => {
expect(state.zipCode).toBeNull();
});
it('sets the countryOptions to an empty array', () => {
expect(state.countryOptions).toEqual([]);
});
it('sets the stateOptions to an empty array', () => {
expect(state.stateOptions).toEqual([]);
});
it('sets the taxRate to the TAX_RATE constant', () => {
expect(state.taxRate).toEqual(0);
});
it('sets the startDate to the current date', () => {
expect(state.startDate).toEqual(currentDate);
});
it('sets the paymentFormParams to an empty object', () => {
expect(state.paymentFormParams).toEqual({});
});
it('sets the paymentMethodId to null', () => {
expect(state.paymentMethodId).toBeNull();
});
it('sets the creditCardDetails to an empty object', () => {
expect(state.creditCardDetails).toEqual({});
});
it('sets isLoadingPaymentMethod to false', () => {
expect(state.isLoadingPaymentMethod).toEqual(false);
});
it('sets isConfirmingOrder to false', () => {
expect(state.isConfirmingOrder).toBe(false);
});
});
......@@ -3341,6 +3341,9 @@ msgstr ""
msgid "Checkout|$%{selectedPlanPrice} per user per year"
msgstr ""
msgid "Checkout|%{cardType} ending in %{lastFourDigits}"
msgstr ""
msgid "Checkout|%{name}'s GitLab subscription"
msgstr ""
......@@ -3362,15 +3365,57 @@ msgstr ""
msgid "Checkout|3. Your GitLab group"
msgstr ""
msgid "Checkout|Billing address"
msgstr ""
msgid "Checkout|Checkout"
msgstr ""
msgid "Checkout|City"
msgstr ""
msgid "Checkout|Confirm purchase"
msgstr ""
msgid "Checkout|Confirming..."
msgstr ""
msgid "Checkout|Continue to billing"
msgstr ""
msgid "Checkout|Continue to payment"
msgstr ""
msgid "Checkout|Country"
msgstr ""
msgid "Checkout|Credit card form failed to load. Please try again."
msgstr ""
msgid "Checkout|Credit card form failed to load: %{message}"
msgstr ""
msgid "Checkout|Edit"
msgstr ""
msgid "Checkout|Exp %{expirationMonth}/%{expirationYear}"
msgstr ""
msgid "Checkout|Failed to confirm your order! Please try again."
msgstr ""
msgid "Checkout|Failed to confirm your order: %{message}. Please try again."
msgstr ""
msgid "Checkout|Failed to load countries. Please try again."
msgstr ""
msgid "Checkout|Failed to load states. Please try again."
msgstr ""
msgid "Checkout|Failed to register credit card. Please try again."
msgstr ""
msgid "Checkout|GitLab plan"
msgstr ""
......@@ -3386,6 +3431,24 @@ msgstr ""
msgid "Checkout|Number of users"
msgstr ""
msgid "Checkout|Payment method"
msgstr ""
msgid "Checkout|Please select a country"
msgstr ""
msgid "Checkout|Please select a state"
msgstr ""
msgid "Checkout|State"
msgstr ""
msgid "Checkout|Street address"
msgstr ""
msgid "Checkout|Submitting the credit card form failed with code %{errorCode}: %{errorMessage}"
msgstr ""
msgid "Checkout|Subscription details"
msgstr ""
......@@ -3404,6 +3467,9 @@ msgstr ""
msgid "Checkout|Your organization"
msgstr ""
msgid "Checkout|Zip code"
msgstr ""
msgid "Checkout|company or team"
msgstr ""
......
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