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';
const localVue = createLocalVue();
localVue.use(VueApollo);
describe('Buy Storage App', () => {
describe('Buy Addons Shared App', () => {
let wrapper;
function createComponent(apolloProvider) {
function createComponent(apolloProvider, propsData) {
wrapper = shallowMountExtended(App, {
localVue,
apolloProvider,
propsData: {
propsData,
stubs: {
Checkout,
AddonPurchaseDetails,
OrderSummary,
SummaryDetails,
},
});
return waitForPromises();
}
const STORAGE_ADDON_PROPS = {
config: {
alertText: '',
formula: I18N_DETAILS_FORMULA,
......@@ -54,17 +65,7 @@ describe('Buy Storage App', () => {
tooltipNote: I18N_STORAGE_TOOLTIP_NOTE,
},
tags: [planTags.STORAGE_PLAN],
},
stubs: {
Checkout,
AddonPurchaseDetails,
OrderSummary,
SummaryDetails,
},
});
return waitForPromises();
}
};
const getStoragePlan = () => pick(mockStoragePlans[0], ['id', 'code', 'pricePerYear', 'name']);
const findCheckout = () => wrapper.findComponent(Checkout);
const findOrderSummary = () => wrapper.findComponent(OrderSummary);
......@@ -79,10 +80,12 @@ describe('Buy Storage App', () => {
wrapper.destroy();
});
describe('Storage', () => {
describe('when data is received', () => {
beforeEach(() => {
const mockApollo = createMockApolloProvider();
return createComponent(mockApollo);
const plansQueryMock = jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } });
const mockApollo = createMockApolloProvider({ plansQueryMock });
return createComponent(mockApollo, STORAGE_ADDON_PROPS);
});
it('should display the root element', () => {
......@@ -123,7 +126,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: null }),
});
await createComponent(mockApollo);
await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findRootElement().exists()).toBe(false);
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
......@@ -133,7 +136,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: null } }),
});
await createComponent(mockApollo);
await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findRootElement().exists()).toBe(false);
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
......@@ -143,7 +146,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: {} } }),
});
await createComponent(mockApollo);
await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findRootElement().exists()).toBe(false);
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
......@@ -155,7 +158,7 @@ describe('Buy Storage App', () => {
const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockRejectedValue(new Error('An error happened!')),
});
await createComponent(mockApollo);
await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findRootElement().exists()).toBe(false);
expect(wrapper.findComponent(GlEmptyState).exists()).toBe(true);
......@@ -163,11 +166,10 @@ describe('Buy Storage App', () => {
});
describe('labels', () => {
const plansQueryMock = jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } });
it('shows labels correctly for 1 pack', async () => {
const mockApollo = createMockApolloProvider({
plansQueryMock: jest.fn().mockResolvedValue({ data: { plans: mockStoragePlans } }),
});
await createComponent(mockApollo);
const mockApollo = createMockApolloProvider({ plansQueryMock });
await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findQuantityText().text()).toMatchInterpolatedText(
'x 10 GB per pack = 10 GB of storage',
......@@ -178,8 +180,8 @@ describe('Buy Storage App', () => {
});
it('shows labels correctly for 2 packs', async () => {
const mockApollo = createMockApolloProvider({}, { quantity: 2 });
await createComponent(mockApollo);
const mockApollo = createMockApolloProvider({ plansQueryMock }, { quantity: 2 });
await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findQuantityText().text()).toMatchInterpolatedText(
'x 10 GB per pack = 20 GB of storage',
......@@ -189,10 +191,11 @@ describe('Buy Storage App', () => {
});
it('does not show labels if input is invalid', async () => {
const mockApollo = createMockApolloProvider({}, { quantity: -1 });
await createComponent(mockApollo);
const mockApollo = createMockApolloProvider({ plansQueryMock }, { quantity: -1 });
await createComponent(mockApollo, STORAGE_ADDON_PROPS);
expect(findQuantityText().text()).toMatchInterpolatedText('x 10 GB per pack');
});
});
});
});
......@@ -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 { createMockClient } from 'helpers/mock_apollo_helper';
import { CUSTOMERSDOT_CLIENT } from 'ee/subscriptions/buy_addons_shared/constants';
import {
mockCiMinutesPlans,
mockDefaultCache,
mockOrderPreview,
} from 'ee_jest/subscriptions/mock_data';
import { mockDefaultCache, mockOrderPreview } from 'ee_jest/subscriptions/mock_data';
export function createMockApolloProvider(mockResponses = {}, dataset = {}) {
const {
plansQueryMock = jest.fn().mockResolvedValue({ data: { plans: mockCiMinutesPlans } }),
plansQueryMock,
orderPreviewQueryMock = jest
.fn()
.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