Commit f80415d4 authored by Paul Slaughter's avatar Paul Slaughter Committed by Alex Buijs

Clean zuora component spec

- New store in beforeEach
- Only one component instance
- Only testing component interface
Signed-off-by: default avatarAlex Buijs <abuijs@gitlab.com>
parent dc0a92be
...@@ -9,26 +9,32 @@ describe('Zuora', () => { ...@@ -9,26 +9,32 @@ describe('Zuora', () => {
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
let store;
let wrapper; let wrapper;
const store = createStore(); const methodMocks = {
loadZuoraScript: jest.fn(),
renderZuoraIframe: jest.fn(),
};
const createComponent = (opts = {}) => { const createComponent = (props = {}) => {
wrapper = shallowMount(Component, { wrapper = shallowMount(Component, {
propsData: {
active: true,
...props,
},
localVue, localVue,
sync: false, sync: false,
store, store,
...opts, methods: methodMocks,
}); });
}; };
const methodMocks = { const findLoading = () => wrapper.find(GlLoadingIcon);
loadZuoraScript: jest.fn(), const findZuoraPayment = () => wrapper.find('#zuora_payment');
renderZuoraIframe: jest.fn(),
};
beforeEach(() => { beforeEach(() => {
createComponent({ methods: methodMocks, propsData: { active: true } }); store = createStore();
}); });
afterEach(() => { afterEach(() => {
...@@ -37,75 +43,70 @@ describe('Zuora', () => { ...@@ -37,75 +43,70 @@ describe('Zuora', () => {
describe('mounted', () => { describe('mounted', () => {
it('should call loadZuoraScript', () => { it('should call loadZuoraScript', () => {
createComponent();
expect(methodMocks.loadZuoraScript).toHaveBeenCalled(); expect(methodMocks.loadZuoraScript).toHaveBeenCalled();
}); });
}); });
describe('when active and loading', () => { describe('when active', () => {
it('the loading indicator should not be shown', () => { beforeEach(() => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true); createComponent();
}); });
it('the zuora_payment selector should be visible', () => { it('shows the loading icon', () => {
expect(wrapper.find('#zuora_payment').element.style.display).toEqual('none'); expect(findLoading().exists()).toBe(true);
}); });
});
describe('when active and not loading', () => { it('the zuora_payment selector should not be visible', () => {
beforeEach(() => { expect(findZuoraPayment().element.style.display).toEqual('none');
wrapper.vm.toggleLoading();
}); });
it('the loading indicator should not be shown', () => { describe.each`
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false); desc | commitType | commitPayload
}); ${'when paymentMethodId is updated'} | ${types.UPDATE_PAYMENT_METHOD_ID} | ${'foo'}
${'when creditCardDetails are updated'} | ${types.UPDATE_CREDIT_CARD_DETAILS} | ${{}}
`('$desc', ({ commitType, commitPayload }) => {
beforeEach(() => {
store.commit(commitType, commitPayload);
it('the zuora_payment selector should be visible', () => { return localVue.nextTick();
expect(wrapper.find('#zuora_payment').element.style.display).toEqual(''); });
});
});
describe('not active and not loading', () => { it('does not show loading icon', () => {
beforeEach(() => { expect(findLoading().exists()).toBe(false);
createComponent({ methods: methodMocks, propsData: { active: false } }); });
wrapper.vm.toggleLoading();
});
it('the zuora_payment selector should not be visible', () => { it('the zuora_payment selector should be visible', () => {
expect(wrapper.find('#zuora_payment').element.style.display).toEqual('none'); expect(findZuoraPayment().element.style.display).toEqual('');
});
}); });
}); });
describe('toggleLoading', () => { describe('when not active and not loading', () => {
let spy;
beforeEach(() => { beforeEach(() => {
spy = jest.spyOn(wrapper.vm, 'toggleLoading'); createComponent({ active: false });
});
afterEach(() => {
spy.mockClear();
});
it('is called when the paymentMethodId is updated', () => {
store.commit(types.UPDATE_PAYMENT_METHOD_ID, 'foo'); store.commit(types.UPDATE_PAYMENT_METHOD_ID, 'foo');
return localVue.nextTick().then(() => { return localVue.nextTick();
expect(spy).toHaveBeenCalled();
});
}); });
it('is called when the creditCardDetails are updated', () => { it('does not show loading icon', () => {
store.commit(types.UPDATE_CREDIT_CARD_DETAILS, {}); expect(findLoading().exists()).toBe(false);
});
return localVue.nextTick().then(() => { it('the zuora_payment selector should not be visible', () => {
expect(spy).toHaveBeenCalled(); expect(wrapper.find('#zuora_payment').element.style.display).toEqual('none');
});
}); });
}); });
describe('renderZuoraIframe', () => { describe('renderZuoraIframe', () => {
it('is called when the paymentFormParams are updated', () => { it('is called when the paymentFormParams are updated', () => {
createComponent();
expect(methodMocks.renderZuoraIframe).not.toHaveBeenCalled();
store.commit(types.UPDATE_PAYMENT_FORM_PARAMS, {}); store.commit(types.UPDATE_PAYMENT_FORM_PARAMS, {});
return localVue.nextTick().then(() => { return localVue.nextTick().then(() => {
......
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