Commit 470b4983 authored by vvempati's avatar vvempati

Make propsData an arg so we can use createComponent for CI minutes tests

parent 06df79bc
...@@ -29,14 +29,25 @@ import { mockStoragePlans } from 'ee_jest/subscriptions/mock_data'; ...@@ -29,14 +29,25 @@ import { mockStoragePlans } from 'ee_jest/subscriptions/mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(VueApollo); localVue.use(VueApollo);
describe('Buy Storage App', () => { describe('Buy Addons Shared App', () => {
let wrapper; let wrapper;
function createComponent(apolloProvider) { function createComponent(apolloProvider, propsData) {
wrapper = shallowMountExtended(App, { wrapper = shallowMountExtended(App, {
localVue, localVue,
apolloProvider, apolloProvider,
propsData: { propsData,
stubs: {
Checkout,
AddonPurchaseDetails,
OrderSummary,
SummaryDetails,
},
});
return waitForPromises();
}
const STORAGE_ADDON_PROPS = {
config: { config: {
alertText: '', alertText: '',
formula: I18N_DETAILS_FORMULA, formula: I18N_DETAILS_FORMULA,
...@@ -53,17 +64,7 @@ describe('Buy Storage App', () => { ...@@ -53,17 +64,7 @@ describe('Buy Storage App', () => {
tooltipNote: I18N_STORAGE_TOOLTIP_NOTE, tooltipNote: I18N_STORAGE_TOOLTIP_NOTE,
}, },
tags: [planTags.STORAGE_PLAN], tags: [planTags.STORAGE_PLAN],
}, };
stubs: {
Checkout,
AddonPurchaseDetails,
OrderSummary,
SummaryDetails,
},
});
return waitForPromises();
}
const getStoragePlan = () => pick(mockStoragePlans[0], ['id', 'code', 'pricePerYear', 'name']); const getStoragePlan = () => pick(mockStoragePlans[0], ['id', 'code', 'pricePerYear', 'name']);
const findCheckout = () => wrapper.findComponent(Checkout); const findCheckout = () => wrapper.findComponent(Checkout);
const findOrderSummary = () => wrapper.findComponent(OrderSummary); const findOrderSummary = () => wrapper.findComponent(OrderSummary);
...@@ -77,12 +78,13 @@ describe('Buy Storage App', () => { ...@@ -77,12 +78,13 @@ describe('Buy Storage App', () => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('Storage', () => {
describe('when data is received', () => { describe('when data is received', () => {
beforeEach(() => { beforeEach(() => {
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }), plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }),
}); });
return createComponent(mockApollo); return createComponent(mockApollo, STORAGE_ADDON_PROPS);
}); });
it('should display the root element', () => { it('should display the root element', () => {
...@@ -109,7 +111,7 @@ describe('Buy Storage App', () => { ...@@ -109,7 +111,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: null }), plansQueryMock: jest.fn().mockResolvedValue({ data: null }),
}); });
await createComponent(mockApollo); await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findRootElement().exists()).toBe(false); expect(findRootElement().exists()).toBe(false);
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true); expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
...@@ -119,7 +121,7 @@ describe('Buy Storage App', () => { ...@@ -119,7 +121,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: null } }), plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: null } }),
}); });
await createComponent(mockApollo); await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findRootElement().exists()).toBe(false); expect(findRootElement().exists()).toBe(false);
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true); expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
...@@ -129,7 +131,7 @@ describe('Buy Storage App', () => { ...@@ -129,7 +131,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: {} } }), plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: {} } }),
}); });
await createComponent(mockApollo); await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findRootElement().exists()).toBe(false); expect(findRootElement().exists()).toBe(false);
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true); expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
...@@ -141,7 +143,7 @@ describe('Buy Storage App', () => { ...@@ -141,7 +143,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockRejectedValue(new Error('An error happened!')), plansQueryMock: jest.fn().mockRejectedValue(new Error('An error happened!')),
}); });
await createComponent(mockApollo); await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findRootElement().exists()).toBe(false); expect(findRootElement().exists()).toBe(false);
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true); expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
...@@ -153,7 +155,7 @@ describe('Buy Storage App', () => { ...@@ -153,7 +155,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }), plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }),
}); });
await createComponent(mockApollo); await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findQuantityText().text()).toMatchInterpolatedText( expect(findQuantityText().text()).toMatchInterpolatedText(
'x 10 GB per pack = 10 GB of storage', 'x 10 GB per pack = 10 GB of storage',
...@@ -167,7 +169,7 @@ describe('Buy Storage App', () => { ...@@ -167,7 +169,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }), plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }),
}, { quantity: 2 }); }, { quantity: 2 });
await createComponent(mockApollo); await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findQuantityText().text()).toMatchInterpolatedText( expect(findQuantityText().text()).toMatchInterpolatedText(
'x 10 GB per pack = 20 GB of storage', 'x 10 GB per pack = 20 GB of storage',
...@@ -180,9 +182,10 @@ describe('Buy Storage App', () => { ...@@ -180,9 +182,10 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }), plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }),
}, { quantity: -1 }); }, { quantity: -1 });
await createComponent(mockApollo); await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findQuantityText().text()).toMatchInterpolatedText('x 10 GB per pack'); expect(findQuantityText().text()).toMatchInterpolatedText('x 10 GB per pack');
}); });
}); });
});
}); });
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