Skip to content

Commit

Permalink
cost-insights: avoid re-export of all of test-utils
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
  • Loading branch information
Rugvip committed Dec 27, 2021
1 parent aa8f764 commit 7858c2a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-bugs-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-cost-insights': patch
---

Fixed an accidental re-export of `@backstage/test-utils` that broke this plugin in the most recent release.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/

import React from 'react';
import { renderInTestApp } from '@backstage/test-utils';
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { ProductInsights } from './ProductInsights';
import { ProductInsightsOptions } from '../../api';
import { costInsightsApiRef, ProductInsightsOptions } from '../../api';
import {
mockDefaultLoadingState,
MockConfigProvider,
MockCostInsightsApiProvider,
MockCurrencyProvider,
MockFilterProvider,
MockBillingDateProvider,
Expand Down Expand Up @@ -139,7 +138,7 @@ const costInsightsApi = {

function renderInContext(children: JSX.Element) {
return renderInTestApp(
<MockCostInsightsApiProvider costInsightsApi={costInsightsApi}>
<TestApiProvider apis={[[costInsightsApiRef, costInsightsApi]]}>
<MockConfigProvider>
<MockFilterProvider>
<MockCurrencyProvider>
Expand All @@ -151,7 +150,7 @@ function renderInContext(children: JSX.Element) {
</MockCurrencyProvider>
</MockFilterProvider>
</MockConfigProvider>
</MockCostInsightsApiProvider>,
</TestApiProvider>,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/

import React from 'react';
import { renderInTestApp } from '@backstage/test-utils';
import { renderInTestApp, TestApiProvider } from '@backstage/test-utils';
import { ProductInsightsCard } from './ProductInsightsCard';
import { CostInsightsApi } from '../../api';
import { CostInsightsApi, costInsightsApiRef } from '../../api';
import {
createMockEntity,
mockDefaultLoadingState,
MockComputeEngine,
MockConfigProvider,
MockCostInsightsApiProvider,
MockCurrencyProvider,
MockBillingDateProvider,
MockScrollProvider,
Expand Down Expand Up @@ -55,7 +54,7 @@ const renderProductInsightsCardInTestApp = async (
onSelectAsync = jest.fn(() => Promise.resolve(mockProductCost)),
) =>
await renderInTestApp(
<MockCostInsightsApiProvider costInsightsApi={costInsightsApi(entity)}>
<TestApiProvider apis={[[costInsightsApiRef, costInsightsApi(entity)]]}>
<MockConfigProvider>
<MockCurrencyProvider>
<MockLoadingProvider state={mockDefaultLoadingState}>
Expand All @@ -71,7 +70,7 @@ const renderProductInsightsCardInTestApp = async (
</MockLoadingProvider>
</MockCurrencyProvider>
</MockConfigProvider>
</MockCostInsightsApiProvider>,
</TestApiProvider>,
);

describe('<ProductInsightsCard/>', () => {
Expand Down
52 changes: 0 additions & 52 deletions plugins/cost-insights/src/testUtils/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import React, { PropsWithChildren } from 'react';
import { costInsightsApiRef, CostInsightsApi } from '../api';
import { LoadingContext, LoadingContextProps } from '../hooks/useLoading';
import { GroupsContext, GroupsContextProps } from '../hooks/useGroups';
import { FilterContext, FilterContextProps } from '../hooks/useFilters';
Expand All @@ -28,12 +27,6 @@ import {
import { ScrollContext, ScrollContextProps } from '../hooks/useScroll';
import { Group, Duration } from '../types';

// TODO(Rugvip): Could be good to have a clear place to put test utils that is linted accordingly
// eslint-disable-next-line import/no-extraneous-dependencies
import { IdentityApi, identityApiRef } from '@backstage/core-plugin-api';
// eslint-disable-next-line import/no-extraneous-dependencies
import { TestApiProvider } from '@backstage/test-utils';

type PartialPropsWithChildren<T> = PropsWithChildren<Partial<T>>;

export const MockGroups: Group[] = [{ id: 'tech' }, { id: 'mock-group' }];
Expand Down Expand Up @@ -172,48 +165,3 @@ export const MockGroupsProvider = ({
</GroupsContext.Provider>
);
};

export type MockCostInsightsApiProviderProps = PartialPropsWithChildren<{
identityApi: Partial<IdentityApi>;
costInsightsApi: Partial<CostInsightsApi>;
}>;

export const MockCostInsightsApiProvider = ({
children,
...context
}: MockCostInsightsApiProviderProps) => {
const defaultIdentityApi: IdentityApi = {
getProfile: jest.fn(),
getIdToken: jest.fn(),
getUserId: jest.fn(),
signOut: jest.fn(),
getProfileInfo: jest.fn(),
getBackstageIdentity: jest.fn(),
getCredentials: jest.fn(),
};

const defaultCostInsightsApi: CostInsightsApi = {
getAlerts: jest.fn(),
getDailyMetricData: jest.fn(),
getGroupDailyCost: jest.fn(),
getGroupProjects: jest.fn(),
getLastCompleteBillingDate: jest.fn(),
getProductInsights: jest.fn(),
getProjectDailyCost: jest.fn(),
getUserGroups: jest.fn(),
};

return (
<TestApiProvider
apis={[
[identityApiRef, { ...defaultIdentityApi, ...context.identityApi }],
[
costInsightsApiRef,
{ ...defaultCostInsightsApi, ...context.costInsightsApi },
],
]}
>
{children}
</TestApiProvider>
);
};

0 comments on commit 7858c2a

Please sign in to comment.