Commit fae78a06 authored by Savas Vedova's avatar Savas Vedova

Merge branch '346620-change-shared-addon-tests-to-accommodate-tests-for-minutes' into 'master'

Change shared addon component tests to accommodate tests for CI minutes

See merge request gitlab-org/gitlab!77920
parents 0b66f2f4 557c40b0
...@@ -30,14 +30,25 @@ import { mockStoragePlans } from 'ee_jest/subscriptions/mock_data'; ...@@ -30,14 +30,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,
...@@ -54,17 +65,7 @@ describe('Buy Storage App', () => { ...@@ -54,17 +65,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);
...@@ -79,10 +80,12 @@ describe('Buy Storage App', () => { ...@@ -79,10 +80,12 @@ 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 plansQueryMock = jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } });
return createComponent(mockApollo); const mockApollo = createMockApolloProvider({ plansQueryMock });
return createComponent(mockApollo, STORAGE_ADDON_PROPS);
}); });
it('should display the root element', () => { it('should display the root element', () => {
...@@ -123,7 +126,7 @@ describe('Buy Storage App', () => { ...@@ -123,7 +126,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);
...@@ -133,7 +136,7 @@ describe('Buy Storage App', () => { ...@@ -133,7 +136,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);
...@@ -143,7 +146,7 @@ describe('Buy Storage App', () => { ...@@ -143,7 +146,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);
...@@ -155,7 +158,7 @@ describe('Buy Storage App', () => { ...@@ -155,7 +158,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);
...@@ -163,11 +166,10 @@ describe('Buy Storage App', () => { ...@@ -163,11 +166,10 @@ describe('Buy Storage App', () => {
}); });
describe('labels', () => { describe('labels', () => {
const plansQueryMock = jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } });
it('shows labels correctly for 1 pack', async () => { it('shows labels correctly for 1 pack', async () => {
const mockApollo = createMockApolloProvider({ const mockApollo = createMockApolloProvider({ plansQueryMock });
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }), await createComponent(mockApollo, STORAGE_ADDON_PROPS);
});
await createComponent(mockApollo);
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',
...@@ -178,8 +180,8 @@ describe('Buy Storage App', () => { ...@@ -178,8 +180,8 @@ describe('Buy Storage App', () => {
}); });
it('shows labels correctly for 2 packs', async () => { it('shows labels correctly for 2 packs', async () => {
const mockApollo = createMockApolloProvider({}, { quantity: 2 }); const mockApollo = createMockApolloProvider({ plansQueryMock }, { 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',
...@@ -189,10 +191,11 @@ describe('Buy Storage App', () => { ...@@ -189,10 +191,11 @@ describe('Buy Storage App', () => {
}); });
it('does not show labels if input is invalid', async () => { it('does not show labels if input is invalid', async () => {
const mockApollo = createMockApolloProvider({}, { quantity: -1 }); const mockApollo = createMockApolloProvider({ plansQueryMock }, { 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');
}); });
}); });
});
}); });
...@@ -4,15 +4,11 @@ import plansQuery from 'ee/subscriptions/graphql/queries/plans.customer.query.gr ...@@ -4,15 +4,11 @@ import plansQuery from 'ee/subscriptions/graphql/queries/plans.customer.query.gr
import orderPreviewQuery from 'ee/subscriptions/graphql/queries/order_preview.customer.query.graphql'; import orderPreviewQuery from 'ee/subscriptions/graphql/queries/order_preview.customer.query.graphql';
import { createMockClient } from 'helpers/mock_apollo_helper'; import { createMockClient } from 'helpers/mock_apollo_helper';
import { CUSTOMERSDOT_CLIENT } from 'ee/subscriptions/buy_addons_shared/constants'; import { CUSTOMERSDOT_CLIENT } from 'ee/subscriptions/buy_addons_shared/constants';
import { import { mockDefaultCache, mockOrderPreview } from 'ee_jest/subscriptions/mock_data';
mockCiMinutesPlans,
mockDefaultCache,
mockOrderPreview,
} from 'ee_jest/subscriptions/mock_data';
export function createMockApolloProvider(mockResponses = {}, dataset = {}) { export function createMockApolloProvider(mockResponses = {}, dataset = {}) {
const { const {
plansQueryMock = jest.fn().mockResolvedValue({ data: { plans: mockCiMinutesPlans } }), plansQueryMock,
orderPreviewQueryMock = jest orderPreviewQueryMock = jest
.fn() .fn()
.mockResolvedValue({ data: { orderPreview: mockOrderPreview } }), .mockResolvedValue({ data: { orderPreview: mockOrderPreview } }),
......
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