cost-insights: avoid re-export of all of test-utils
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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.
|
||||
@@ -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(
|
||||
<MockCostInsightsApiProvider costInsightsApi={costInsightsApi}>
|
||||
<TestApiProvider apis={[[costInsightsApiRef, costInsightsApi]]}>
|
||||
<MockConfigProvider>
|
||||
<MockFilterProvider>
|
||||
<MockCurrencyProvider>
|
||||
@@ -151,7 +150,7 @@ function renderInContext(children: JSX.Element) {
|
||||
</MockCurrencyProvider>
|
||||
</MockFilterProvider>
|
||||
</MockConfigProvider>
|
||||
</MockCostInsightsApiProvider>,
|
||||
</TestApiProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -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(
|
||||
<MockCostInsightsApiProvider costInsightsApi={costInsightsApi(entity)}>
|
||||
<TestApiProvider apis={[[costInsightsApiRef, costInsightsApi(entity)]]}>
|
||||
<MockConfigProvider>
|
||||
<MockCurrencyProvider>
|
||||
<MockLoadingProvider state={mockDefaultLoadingState}>
|
||||
@@ -71,7 +70,7 @@ const renderProductInsightsCardInTestApp = async (
|
||||
</MockLoadingProvider>
|
||||
</MockCurrencyProvider>
|
||||
</MockConfigProvider>
|
||||
</MockCostInsightsApiProvider>,
|
||||
</TestApiProvider>,
|
||||
);
|
||||
|
||||
describe('<ProductInsightsCard/>', () => {
|
||||
|
||||
@@ -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<T> = PropsWithChildren<Partial<T>>;
|
||||
|
||||
export const MockGroups: Group[] = [{ id: 'tech' }, { id: 'mock-group' }];
|
||||
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user