From 7858c2abdc5a2d984d4ca9d17b4193c3808efe27 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 27 Dec 2021 16:03:29 +0100 Subject: [PATCH] cost-insights: avoid re-export of all of test-utils Signed-off-by: Patrik Oldsberg --- .changeset/curly-bugs-stare.md | 5 ++ .../ProductInsights/ProductInsights.test.tsx | 9 ++-- .../ProductInsightsCard.test.tsx | 9 ++-- .../cost-insights/src/testUtils/providers.tsx | 52 ------------------- 4 files changed, 13 insertions(+), 62 deletions(-) create mode 100644 .changeset/curly-bugs-stare.md diff --git a/.changeset/curly-bugs-stare.md b/.changeset/curly-bugs-stare.md new file mode 100644 index 0000000000..88e1d86e84 --- /dev/null +++ b/.changeset/curly-bugs-stare.md @@ -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. diff --git a/plugins/cost-insights/src/components/ProductInsights/ProductInsights.test.tsx b/plugins/cost-insights/src/components/ProductInsights/ProductInsights.test.tsx index 7253febd71..128c9d50b9 100644 --- a/plugins/cost-insights/src/components/ProductInsights/ProductInsights.test.tsx +++ b/plugins/cost-insights/src/components/ProductInsights/ProductInsights.test.tsx @@ -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, @@ -139,7 +138,7 @@ const costInsightsApi = { function renderInContext(children: JSX.Element) { return renderInTestApp( - + @@ -151,7 +150,7 @@ function renderInContext(children: JSX.Element) { - , + , ); } diff --git a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.test.tsx b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.test.tsx index 6cc1817e1c..9fc816bbbf 100644 --- a/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.test.tsx +++ b/plugins/cost-insights/src/components/ProductInsightsCard/ProductInsightsCard.test.tsx @@ -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, @@ -55,7 +54,7 @@ const renderProductInsightsCardInTestApp = async ( onSelectAsync = jest.fn(() => Promise.resolve(mockProductCost)), ) => await renderInTestApp( - + @@ -71,7 +70,7 @@ const renderProductInsightsCardInTestApp = async ( - , + , ); describe('', () => { diff --git a/plugins/cost-insights/src/testUtils/providers.tsx b/plugins/cost-insights/src/testUtils/providers.tsx index fb18c1a68c..efcb15b5a3 100644 --- a/plugins/cost-insights/src/testUtils/providers.tsx +++ b/plugins/cost-insights/src/testUtils/providers.tsx @@ -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'; @@ -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 = PropsWithChildren>; export const MockGroups: Group[] = [{ id: 'tech' }, { id: 'mock-group' }]; @@ -172,48 +165,3 @@ export const MockGroupsProvider = ({ ); }; - -export type MockCostInsightsApiProviderProps = PartialPropsWithChildren<{ - identityApi: Partial; - costInsightsApi: Partial; -}>; - -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 ( - - {children} - - ); -};