Commit 2313f1cb authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'xanf-vtu-v1-subscriptions' into 'master'

Upgrading VTU to v1: Remove deprecated `methods` from components/checkout

See merge request gitlab-org/gitlab!50498
parents f4b18186 d955b6da
...@@ -8,10 +8,11 @@ import createState from './state'; ...@@ -8,10 +8,11 @@ import createState from './state';
Vue.use(Vuex); Vue.use(Vuex);
export default (initialState = {}) => export const getStoreConfig = (initialState = {}) => ({
new Vuex.Store({
state: createState(initialState), state: createState(initialState),
actions, actions,
getters, getters,
mutations, mutations,
}); });
export default (initialState = {}) => new Vuex.Store(getStoreConfig(initialState));
import { mount, createLocalVue } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import Component from 'ee/subscriptions/new/components/checkout/billing_address.vue'; import Component from 'ee/subscriptions/new/components/checkout/billing_address.vue';
import Step from 'ee/subscriptions/new/components/checkout/step.vue'; import Step from 'ee/subscriptions/new/components/checkout/step.vue';
import createStore from 'ee/subscriptions/new/store'; import { getStoreConfig } from 'ee/subscriptions/new/store';
import * as types from 'ee/subscriptions/new/store/mutation_types'; import * as types from 'ee/subscriptions/new/store/mutation_types';
describe('Billing Address', () => { Vue.use(Vuex);
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Billing Address', () => {
let store; let store;
let wrapper; let wrapper;
const methodMocks = { const actionMocks = {
fetchCountries: jest.fn(), fetchCountries: jest.fn(),
fetchStates: jest.fn(), fetchStates: jest.fn(),
}; };
const createComponent = () => { const createComponent = () => {
const { actions, ...storeConfig } = getStoreConfig();
store = new Vuex.Store({
...storeConfig,
actions: { ...actions, ...actionMocks },
});
wrapper = mount(Component, { wrapper = mount(Component, {
localVue,
store, store,
methods: methodMocks,
}); });
}; };
beforeEach(() => { beforeEach(() => {
store = createStore();
createComponent(); createComponent();
}); });
...@@ -36,7 +39,7 @@ describe('Billing Address', () => { ...@@ -36,7 +39,7 @@ describe('Billing Address', () => {
describe('mounted', () => { describe('mounted', () => {
it('should load the countries', () => { it('should load the countries', () => {
expect(methodMocks.fetchCountries).toHaveBeenCalled(); expect(actionMocks.fetchCountries).toHaveBeenCalled();
}); });
}); });
...@@ -55,12 +58,11 @@ describe('Billing Address', () => { ...@@ -55,12 +58,11 @@ describe('Billing Address', () => {
expect(countrySelect().html()).toContain('<option value="NL">Netherlands</option>'); expect(countrySelect().html()).toContain('<option value="NL">Netherlands</option>');
}); });
it('should fetch states when selecting a country', () => { it('should fetch states when selecting a country', async () => {
countrySelect().trigger('change'); countrySelect().trigger('change');
await nextTick();
return localVue.nextTick().then(() => { expect(actionMocks.fetchStates).toHaveBeenCalled();
expect(methodMocks.fetchStates).toHaveBeenCalled();
});
}); });
}); });
...@@ -78,38 +80,34 @@ describe('Billing Address', () => { ...@@ -78,38 +80,34 @@ describe('Billing Address', () => {
expect(isStepValid()).toBe(true); expect(isStepValid()).toBe(true);
}); });
it('should be invalid when country is undefined', () => { it('should be invalid when country is undefined', async () => {
store.commit(types.UPDATE_COUNTRY, null); store.commit(types.UPDATE_COUNTRY, null);
await nextTick();
return localVue.nextTick().then(() => {
expect(isStepValid()).toBe(false); expect(isStepValid()).toBe(false);
}); });
});
it('should be invalid when streetAddressLine1 is undefined', () => { it('should be invalid when streetAddressLine1 is undefined', async () => {
store.commit(types.UPDATE_STREET_ADDRESS_LINE_ONE, null); store.commit(types.UPDATE_STREET_ADDRESS_LINE_ONE, null);
await nextTick();
return localVue.nextTick().then(() => {
expect(isStepValid()).toBe(false); expect(isStepValid()).toBe(false);
}); });
});
it('should be invalid when city is undefined', () => { it('should be invalid when city is undefined', async () => {
store.commit(types.UPDATE_CITY, null); store.commit(types.UPDATE_CITY, null);
await nextTick();
return localVue.nextTick().then(() => {
expect(isStepValid()).toBe(false); expect(isStepValid()).toBe(false);
}); });
});
it('should be invalid when zipCode is undefined', () => { it('should be invalid when zipCode is undefined', async () => {
store.commit(types.UPDATE_ZIP_CODE, null); store.commit(types.UPDATE_ZIP_CODE, null);
await nextTick();
return localVue.nextTick().then(() => {
expect(isStepValid()).toBe(false); expect(isStepValid()).toBe(false);
}); });
}); });
});
describe('showing the summary', () => { describe('showing the summary', () => {
beforeEach(() => { beforeEach(() => {
......
...@@ -2,7 +2,7 @@ import { GlLoadingIcon } from '@gitlab/ui'; ...@@ -2,7 +2,7 @@ import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import Component from 'ee/subscriptions/new/components/checkout/zuora.vue'; import Component from 'ee/subscriptions/new/components/checkout/zuora.vue';
import createStore from 'ee/subscriptions/new/store'; import { getStoreConfig } from 'ee/subscriptions/new/store';
import * as types from 'ee/subscriptions/new/store/mutation_types'; import * as types from 'ee/subscriptions/new/store/mutation_types';
describe('Zuora', () => { describe('Zuora', () => {
...@@ -12,21 +12,30 @@ describe('Zuora', () => { ...@@ -12,21 +12,30 @@ describe('Zuora', () => {
let store; let store;
let wrapper; let wrapper;
const methodMocks = { const actionMocks = {
loadZuoraScript: jest.fn(), startLoadingZuoraScript: jest.fn(),
renderZuoraIframe: jest.fn(), fetchPaymentFormParams: jest.fn(),
zuoraIframeRendered: jest.fn(),
paymentFormSubmitted: jest.fn(),
}; };
const createComponent = (props = {}) => { const createComponent = (props = {}) => {
const { actions, ...storeConfig } = getStoreConfig();
store = new Vuex.Store({
...storeConfig,
actions: {
...actions,
...actionMocks,
},
});
wrapper = shallowMount(Component, { wrapper = shallowMount(Component, {
propsData: { propsData: {
active: true, active: true,
...props, ...props,
}, },
localVue, localVue,
sync: false,
store, store,
methods: methodMocks,
}); });
}; };
...@@ -34,18 +43,24 @@ describe('Zuora', () => { ...@@ -34,18 +43,24 @@ describe('Zuora', () => {
const findZuoraPayment = () => wrapper.find('#zuora_payment'); const findZuoraPayment = () => wrapper.find('#zuora_payment');
beforeEach(() => { beforeEach(() => {
store = createStore(); window.Z = {
runAfterRender(fn) {
return Promise.resolve().then(fn);
},
render() {},
};
}); });
afterEach(() => { afterEach(() => {
delete window.Z;
wrapper.destroy(); wrapper.destroy();
}); });
describe('mounted', () => { describe('mounted', () => {
it('should call loadZuoraScript', () => { it('starts loading zuora script', () => {
createComponent(); createComponent();
expect(methodMocks.loadZuoraScript).toHaveBeenCalled(); expect(actionMocks.startLoadingZuoraScript).toHaveBeenCalled();
}); });
}); });
...@@ -97,12 +112,12 @@ describe('Zuora', () => { ...@@ -97,12 +112,12 @@ describe('Zuora', () => {
it('is called when the paymentFormParams are updated', () => { it('is called when the paymentFormParams are updated', () => {
createComponent(); createComponent();
expect(methodMocks.renderZuoraIframe).not.toHaveBeenCalled(); expect(actionMocks.zuoraIframeRendered).not.toHaveBeenCalled();
store.commit(types.UPDATE_PAYMENT_FORM_PARAMS, {}); store.commit(types.UPDATE_PAYMENT_FORM_PARAMS, {});
return localVue.nextTick().then(() => { return localVue.nextTick().then(() => {
expect(methodMocks.renderZuoraIframe).toHaveBeenCalled(); expect(actionMocks.zuoraIframeRendered).toHaveBeenCalled();
}); });
}); });
}); });
......
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