From a5ecdb99f036e1a24e6565f4db23f5190cf9b119 Mon Sep 17 00:00:00 2001 From: bnechyporenko Date: Wed, 16 Nov 2022 10:57:36 +0100 Subject: [PATCH 01/11] Making a possibility to hide a trending line in a cost insights plugin Signed-off-by: bnechyporenko --- .changeset/yellow-forks-knock.md | 5 ++++ plugins/cost-insights/api-report.md | 2 +- .../CostOverviewCard/CostOverviewChart.tsx | 25 +++++++++------- plugins/cost-insights/src/options.ts | 29 +++++++++++++++++++ plugins/cost-insights/src/plugin.ts | 12 ++++++++ 5 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 .changeset/yellow-forks-knock.md create mode 100644 plugins/cost-insights/src/options.ts diff --git a/.changeset/yellow-forks-knock.md b/.changeset/yellow-forks-knock.md new file mode 100644 index 0000000000..98c4b5b675 --- /dev/null +++ b/.changeset/yellow-forks-knock.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-cost-insights': patch +--- + +Making a possibility to hide a trending line in a cost insights plugin diff --git a/plugins/cost-insights/api-report.md b/plugins/cost-insights/api-report.md index dd4e404450..27f7c94f21 100644 --- a/plugins/cost-insights/api-report.md +++ b/plugins/cost-insights/api-report.md @@ -316,7 +316,7 @@ const costInsightsPlugin: BackstagePlugin< unlabeledDataflowAlerts: RouteRef; }, {}, - {} + CostInsightsInputPluginOptions >; export { costInsightsPlugin }; export { costInsightsPlugin as plugin }; diff --git a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewChart.tsx b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewChart.tsx index 1c58bf58e6..687f9bdd39 100644 --- a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewChart.tsx +++ b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewChart.tsx @@ -48,7 +48,8 @@ import { useCostOverviewStyles as useStyles } from '../../utils/styles'; import { groupByDate, toDataMax, trendFrom } from '../../utils/charts'; import { aggregationSort } from '../../utils/sort'; import { CostOverviewLegend } from './CostOverviewLegend'; -import { TooltipRenderer } from '../../types/Tooltip'; +import { TooltipRenderer } from '../../types'; +import { useCostInsightsOptions } from '../../options'; type CostOverviewChartProps = { metric: Maybe; @@ -132,6 +133,8 @@ export const CostOverviewChart = ({ ); }; + const { showTrendLine } = useCostInsightsOptions(); + return ( - + {showTrendLine && ( + + )} {metric && ( + usePluginOptions(); diff --git a/plugins/cost-insights/src/plugin.ts b/plugins/cost-insights/src/plugin.ts index 04d58d1877..1d776660ce 100644 --- a/plugins/cost-insights/src/plugin.ts +++ b/plugins/cost-insights/src/plugin.ts @@ -19,6 +19,10 @@ import { createRouteRef, createRoutableExtension, } from '@backstage/core-plugin-api'; +import { + CostInsightsInputPluginOptions, + CostInsightsPluginOptions, +} from './options'; export const rootRouteRef = createRouteRef({ id: 'cost-insights', @@ -41,6 +45,14 @@ export const costInsightsPlugin = createPlugin({ growthAlerts: projectGrowthAlertRef, unlabeledDataflowAlerts: unlabeledDataflowAlertRef, }, + __experimentalConfigure( + options?: CostInsightsInputPluginOptions, + ): CostInsightsPluginOptions { + const defaultOptions = { + showTrendLine: true, + }; + return { ...defaultOptions, ...options }; + }, }); /** @public */ From c860237e31e64a5331404264ade182f79a2bf8d0 Mon Sep 17 00:00:00 2001 From: bnechyporenko Date: Wed, 16 Nov 2022 12:39:56 +0100 Subject: [PATCH 02/11] Test fixes Signed-off-by: bnechyporenko --- .../CostOverviewCard.test.tsx | 20 ++++++++++++++++++- .../EntityCosts/EntityCost.test.tsx | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx index e3de9593d9..ca438b75ac 100644 --- a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx +++ b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx @@ -30,6 +30,7 @@ import { MockScrollProvider, } from '../../testUtils'; import { CostInsightsThemeProvider } from '../CostInsightsPage/CostInsightsThemeProvider'; +import { createPlugin, PluginProvider } from '@backstage/core-plugin-api'; const mockGroupDailyCost: Cost = { id: 'test-group', @@ -38,13 +39,30 @@ const mockGroupDailyCost: Cost = { trendline: trendlineOf(MockAggregatedDailyCosts), }; +type TestInputPluginOptions = { + showTrendLine: boolean; +}; + +type TestPluginOptions = { + showTrendLine: boolean; +}; + +const plugin = createPlugin({ + id: 'my-plugin', + __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { + return { showTrendLine: false }; + }, +}); + function renderInContext(children: JSX.Element) { return renderInTestApp( - {children} + + {children} + diff --git a/plugins/cost-insights/src/components/EntityCosts/EntityCost.test.tsx b/plugins/cost-insights/src/components/EntityCosts/EntityCost.test.tsx index 53e1a13ebf..e2b6a28247 100644 --- a/plugins/cost-insights/src/components/EntityCosts/EntityCost.test.tsx +++ b/plugins/cost-insights/src/components/EntityCosts/EntityCost.test.tsx @@ -32,6 +32,7 @@ import { EntityProvider } from '@backstage/plugin-catalog-react'; import { Entity } from '@backstage/catalog-model'; import { LoadingProvider } from '../../hooks'; import { Cost } from '@backstage/plugin-cost-insights-common'; +import { createPlugin, PluginProvider } from '@backstage/core-plugin-api'; function renderInContext(children: JSX.Element) { const mockEntity = { @@ -56,6 +57,21 @@ function renderInContext(children: JSX.Element) { getAlerts: jest.fn().mockResolvedValue({}), }; + type TestInputPluginOptions = { + showTrendLine: boolean; + }; + + type TestPluginOptions = { + showTrendLine: boolean; + }; + + const plugin = createPlugin({ + id: 'my-plugin', + __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { + return { showTrendLine: false }; + }, + }); + return renderInTestApp( @@ -64,7 +80,9 @@ function renderInContext(children: JSX.Element) { - {children} + + {children} + From 9e824cfd4a530843ab554e1cadc0799ff48bac32 Mon Sep 17 00:00:00 2001 From: bogdannechyporenko Date: Wed, 16 Nov 2022 21:17:12 +0100 Subject: [PATCH 03/11] Incorporated the feedback Signed-off-by: bogdannechyporenko --- .../CostOverviewCard.test.tsx | 19 ++--------------- .../CostOverviewCard/CostOverviewChart.tsx | 4 ++-- .../EntityCosts/EntityCost.test.tsx | 21 ++++--------------- plugins/cost-insights/src/options.ts | 4 ++-- plugins/cost-insights/src/plugin.ts | 2 +- .../cost-insights/src/testUtils/providers.tsx | 14 +++++++++++++ 6 files changed, 25 insertions(+), 39 deletions(-) diff --git a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx index ca438b75ac..074c3a64bd 100644 --- a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx +++ b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx @@ -28,9 +28,9 @@ import { MockConfigProvider, MockFilterProvider, MockScrollProvider, + MockPluginProvider, } from '../../testUtils'; import { CostInsightsThemeProvider } from '../CostInsightsPage/CostInsightsThemeProvider'; -import { createPlugin, PluginProvider } from '@backstage/core-plugin-api'; const mockGroupDailyCost: Cost = { id: 'test-group', @@ -39,21 +39,6 @@ const mockGroupDailyCost: Cost = { trendline: trendlineOf(MockAggregatedDailyCosts), }; -type TestInputPluginOptions = { - showTrendLine: boolean; -}; - -type TestPluginOptions = { - showTrendLine: boolean; -}; - -const plugin = createPlugin({ - id: 'my-plugin', - __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { - return { showTrendLine: false }; - }, -}); - function renderInContext(children: JSX.Element) { return renderInTestApp( @@ -61,7 +46,7 @@ function renderInContext(children: JSX.Element) { - {children} + {children} diff --git a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewChart.tsx b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewChart.tsx index 687f9bdd39..f91fe472c6 100644 --- a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewChart.tsx +++ b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewChart.tsx @@ -133,7 +133,7 @@ export const CostOverviewChart = ({ ); }; - const { showTrendLine } = useCostInsightsOptions(); + const { hideTrendLine } = useCostInsightsOptions(); return ( @@ -180,7 +180,7 @@ export const CostOverviewChart = ({ stroke="none" yAxisId={data.dailyCost.dataKey} /> - {showTrendLine && ( + {!hideTrendLine && ( @@ -81,7 +66,9 @@ function renderInContext(children: JSX.Element) { - {children} + + {children} + diff --git a/plugins/cost-insights/src/options.ts b/plugins/cost-insights/src/options.ts index 820bea7654..287935d703 100644 --- a/plugins/cost-insights/src/options.ts +++ b/plugins/cost-insights/src/options.ts @@ -17,12 +17,12 @@ import { usePluginOptions } from '@backstage/core-plugin-api'; export type CostInsightsPluginOptions = { - showTrendLine: boolean; + hideTrendLine?: boolean; }; /** @ignore */ export type CostInsightsInputPluginOptions = { - showTrendLine: boolean; + hideTrendLine?: boolean; }; export const useCostInsightsOptions = () => diff --git a/plugins/cost-insights/src/plugin.ts b/plugins/cost-insights/src/plugin.ts index 1d776660ce..c863c9e03a 100644 --- a/plugins/cost-insights/src/plugin.ts +++ b/plugins/cost-insights/src/plugin.ts @@ -49,7 +49,7 @@ export const costInsightsPlugin = createPlugin({ options?: CostInsightsInputPluginOptions, ): CostInsightsPluginOptions { const defaultOptions = { - showTrendLine: true, + hideTrendLine: false, }; return { ...defaultOptions, ...options }; }, diff --git a/plugins/cost-insights/src/testUtils/providers.tsx b/plugins/cost-insights/src/testUtils/providers.tsx index 8088fca3c6..f8d23dda3c 100644 --- a/plugins/cost-insights/src/testUtils/providers.tsx +++ b/plugins/cost-insights/src/testUtils/providers.tsx @@ -26,6 +26,7 @@ import { } from '../hooks/useLastCompleteBillingDate'; import { ScrollContext, ScrollContextProps } from '../hooks/useScroll'; import { Group, Duration } from '../types'; +import { createPlugin, PluginProvider } from '@backstage/core-plugin-api'; export const MockGroups: Group[] = [{ id: 'tech' }, { id: 'mock-group' }]; @@ -144,6 +145,19 @@ export const MockBillingDateProvider = ({ export type MockScrollProviderProps = PropsWithChildren<{}>; +export const MockPluginProvider = ({ children }: PropsWithChildren<{}>) => { + type TestInputPluginOptions = {}; + type TestPluginOptions = {}; + const plugin = createPlugin({ + id: 'my-plugin', + __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { + return {}; + }, + }); + + return {children}; +}; + export const MockScrollProvider = ({ children }: MockScrollProviderProps) => { const defaultContext: ScrollContextProps = { scroll: null, From 03360e1d40c86be3a0e6c1e7afbb530ed85136d6 Mon Sep 17 00:00:00 2001 From: bogdannechyporenko Date: Thu, 17 Nov 2022 16:58:58 +0100 Subject: [PATCH 04/11] Incorporated the feedback Signed-off-by: bogdannechyporenko --- packages/test-utils/src/testUtils/index.tsx | 1 + .../test-utils/src/testUtils/providers.tsx | 31 +++++++++++++++++ .../CatalogPage/DefaultCatalogPage.test.tsx | 23 ++----------- plugins/cost-insights/package.json | 1 + .../CostOverviewCard.test.tsx | 5 ++- .../EntityCosts/EntityCost.test.tsx | 8 +++-- .../cost-insights/src/testUtils/providers.tsx | 34 +++++++------------ 7 files changed, 56 insertions(+), 47 deletions(-) create mode 100644 packages/test-utils/src/testUtils/providers.tsx diff --git a/packages/test-utils/src/testUtils/index.tsx b/packages/test-utils/src/testUtils/index.tsx index bfd870e2ad..1df236d92c 100644 --- a/packages/test-utils/src/testUtils/index.tsx +++ b/packages/test-utils/src/testUtils/index.tsx @@ -24,6 +24,7 @@ export { export type { TestAppOptions } from './appWrappers'; export * from './msw'; export * from './logCollector'; +export * from './providers'; export * from './testingLibrary'; export { TestApiProvider, TestApiRegistry } from './TestApiProvider'; export type { TestApiProviderProps } from './TestApiProvider'; diff --git a/packages/test-utils/src/testUtils/providers.tsx b/packages/test-utils/src/testUtils/providers.tsx new file mode 100644 index 0000000000..cf4787099b --- /dev/null +++ b/packages/test-utils/src/testUtils/providers.tsx @@ -0,0 +1,31 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React, { PropsWithChildren } from 'react'; +import { createPlugin, PluginProvider } from '@backstage/core-plugin-api'; + +export const MockPluginProvider = ({ children }: PropsWithChildren<{}>) => { + type TestInputPluginOptions = {}; + type TestPluginOptions = {}; + const plugin = createPlugin({ + id: 'my-plugin', + __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { + return {}; + }, + }); + + return {children}; +}; diff --git a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx index cc00a57314..4636db5576 100644 --- a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx +++ b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx @@ -23,21 +23,20 @@ import { } from '@backstage/catalog-model'; import { TableColumn, TableProps } from '@backstage/core-components'; import { - createPlugin, IdentityApi, identityApiRef, - PluginProvider, ProfileInfo, storageApiRef, } from '@backstage/core-plugin-api'; import { catalogApiRef, entityRouteRef, - starredEntitiesApiRef, MockStarredEntitiesApi, + starredEntitiesApiRef, } from '@backstage/plugin-catalog-react'; import { mockBreakpoint, + MockPluginProvider, MockStorageApi, renderWithEffects, TestApiProvider, @@ -135,22 +134,6 @@ describe('DefaultCatalogPage', () => { }; const storageApi = MockStorageApi.create(); - type TestInputPluginOptions = { - 'key-1': string; - }; - - type TestPluginOptions = { - 'key-1': string; - 'key-2': string; - }; - - const plugin = createPlugin({ - id: 'my-plugin', - __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { - return { 'key-1': 'value-1', 'key-2': 'value-2' }; - }, - }); - const renderWrapped = (children: React.ReactNode) => renderWithEffects( wrapInTestApp( @@ -162,7 +145,7 @@ describe('DefaultCatalogPage', () => { [starredEntitiesApiRef, new MockStarredEntitiesApi()], ]} > - {children} + {children} , { mountedRoutes: { diff --git a/plugins/cost-insights/package.json b/plugins/cost-insights/package.json index 3ef57bf70b..8f383b5d47 100644 --- a/plugins/cost-insights/package.json +++ b/plugins/cost-insights/package.json @@ -38,6 +38,7 @@ "@backstage/core-plugin-api": "workspace:^", "@backstage/plugin-catalog-react": "workspace:^", "@backstage/plugin-cost-insights-common": "workspace:^", + "@backstage/test-utils": "workspace:^", "@backstage/theme": "workspace:^", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", diff --git a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx index 074c3a64bd..e8fbb7abcb 100644 --- a/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx +++ b/plugins/cost-insights/src/components/CostOverviewCard/CostOverviewCard.test.tsx @@ -15,7 +15,7 @@ */ import React from 'react'; import { fireEvent } from '@testing-library/react'; -import { renderInTestApp } from '@backstage/test-utils'; +import { MockPluginProvider, renderInTestApp } from '@backstage/test-utils'; import { CostOverviewCard } from './CostOverviewCard'; import { Cost } from '../../types'; import { @@ -23,12 +23,11 @@ import { getGroupedProducts, getGroupedProjects, MockAggregatedDailyCosts, - trendlineOf, MockBillingDateProvider, MockConfigProvider, MockFilterProvider, MockScrollProvider, - MockPluginProvider, + trendlineOf, } from '../../testUtils'; import { CostInsightsThemeProvider } from '../CostInsightsPage/CostInsightsThemeProvider'; diff --git a/plugins/cost-insights/src/components/EntityCosts/EntityCost.test.tsx b/plugins/cost-insights/src/components/EntityCosts/EntityCost.test.tsx index da3f4300bb..f288f54e9b 100644 --- a/plugins/cost-insights/src/components/EntityCosts/EntityCost.test.tsx +++ b/plugins/cost-insights/src/components/EntityCosts/EntityCost.test.tsx @@ -14,20 +14,22 @@ * limitations under the License. */ import React from 'react'; -import { renderInTestApp } from '@backstage/test-utils'; +import { + MockPluginProvider, + renderInTestApp, + TestApiProvider, +} from '@backstage/test-utils'; import { changeOf, MockAggregatedDailyCosts, MockBillingDateProvider, MockConfigProvider, MockFilterProvider, - MockPluginProvider, MockScrollProvider, trendlineOf, } from '../../testUtils'; import { CostInsightsThemeProvider } from '../CostInsightsPage/CostInsightsThemeProvider'; import { EntityCostsCard } from './EntityCosts'; -import { TestApiProvider } from '@backstage/test-utils'; import { CostInsightsApi, costInsightsApiRef } from '../../api'; import { EntityProvider } from '@backstage/plugin-catalog-react'; import { Entity } from '@backstage/catalog-model'; diff --git a/plugins/cost-insights/src/testUtils/providers.tsx b/plugins/cost-insights/src/testUtils/providers.tsx index f8d23dda3c..a8610c44ba 100644 --- a/plugins/cost-insights/src/testUtils/providers.tsx +++ b/plugins/cost-insights/src/testUtils/providers.tsx @@ -15,18 +15,23 @@ */ import React, { PropsWithChildren } from 'react'; -import { LoadingContext, LoadingContextProps } from '../hooks/useLoading'; -import { GroupsContext, GroupsContextProps } from '../hooks/useGroups'; -import { FilterContext, FilterContextProps } from '../hooks/useFilters'; -import { ConfigContext, ConfigContextProps } from '../hooks/useConfig'; -import { CurrencyContext, CurrencyContextProps } from '../hooks/useCurrency'; import { + LoadingContext, + LoadingContextProps, + GroupsContext, + GroupsContextProps, + FilterContext, + FilterContextProps, + ConfigContext, + ConfigContextProps, + CurrencyContext, + CurrencyContextProps, BillingDateContext, BillingDateContextProps, -} from '../hooks/useLastCompleteBillingDate'; -import { ScrollContext, ScrollContextProps } from '../hooks/useScroll'; + ScrollContext, + ScrollContextProps, +} from '../hooks'; import { Group, Duration } from '../types'; -import { createPlugin, PluginProvider } from '@backstage/core-plugin-api'; export const MockGroups: Group[] = [{ id: 'tech' }, { id: 'mock-group' }]; @@ -145,19 +150,6 @@ export const MockBillingDateProvider = ({ export type MockScrollProviderProps = PropsWithChildren<{}>; -export const MockPluginProvider = ({ children }: PropsWithChildren<{}>) => { - type TestInputPluginOptions = {}; - type TestPluginOptions = {}; - const plugin = createPlugin({ - id: 'my-plugin', - __experimentalConfigure(_: TestInputPluginOptions): TestPluginOptions { - return {}; - }, - }); - - return {children}; -}; - export const MockScrollProvider = ({ children }: MockScrollProviderProps) => { const defaultContext: ScrollContextProps = { scroll: null, From c0f423a54c9df5424dc0c0decb9308922c2b170b Mon Sep 17 00:00:00 2001 From: bogdannechyporenko Date: Thu, 17 Nov 2022 20:06:15 +0100 Subject: [PATCH 05/11] Fixed build issues Signed-off-by: bogdannechyporenko --- .changeset/yellow-forks-knock.md | 1 + packages/test-utils/api-report.md | 6 ++++++ packages/test-utils/src/testUtils/providers.tsx | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/.changeset/yellow-forks-knock.md b/.changeset/yellow-forks-knock.md index 98c4b5b675..6c3d300026 100644 --- a/.changeset/yellow-forks-knock.md +++ b/.changeset/yellow-forks-knock.md @@ -1,5 +1,6 @@ --- '@backstage/plugin-cost-insights': patch +'@backstage/test-utils': patch --- Making a possibility to hide a trending line in a cost insights plugin diff --git a/packages/test-utils/api-report.md b/packages/test-utils/api-report.md index 38d6a85f5f..1b0aa44fc6 100644 --- a/packages/test-utils/api-report.md +++ b/packages/test-utils/api-report.md @@ -25,6 +25,7 @@ import { JsonObject } from '@backstage/types'; import { JsonValue } from '@backstage/types'; import { Observable } from '@backstage/types'; import { PermissionApi } from '@backstage/plugin-permission-react'; +import { PropsWithChildren } from 'react'; import { ReactElement } from 'react'; import { ReactNode } from 'react'; import { RenderOptions } from '@testing-library/react'; @@ -165,6 +166,11 @@ export class MockPermissionApi implements PermissionApi { ): Promise; } +// @alpha +export const MockPluginProvider: ({ + children, +}: PropsWithChildren<{}>) => JSX.Element; + // @public export class MockStorageApi implements StorageApi { // (undocumented) diff --git a/packages/test-utils/src/testUtils/providers.tsx b/packages/test-utils/src/testUtils/providers.tsx index cf4787099b..8bc4b5122d 100644 --- a/packages/test-utils/src/testUtils/providers.tsx +++ b/packages/test-utils/src/testUtils/providers.tsx @@ -17,6 +17,10 @@ import React, { PropsWithChildren } from 'react'; import { createPlugin, PluginProvider } from '@backstage/core-plugin-api'; +/** + * Mock for PluginProvider to use in unit tests + * @alpha + */ export const MockPluginProvider = ({ children }: PropsWithChildren<{}>) => { type TestInputPluginOptions = {}; type TestPluginOptions = {}; From 5e238ed56a8f4091917f95e083d41410e0a0447b Mon Sep 17 00:00:00 2001 From: bnechyporenko Date: Fri, 18 Nov 2022 10:29:09 +0100 Subject: [PATCH 06/11] Incorporated the feedback Signed-off-by: bnechyporenko --- .changeset/gold-yaks-join.md | 6 ++++++ .changeset/yellow-forks-knock.md | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/gold-yaks-join.md diff --git a/.changeset/gold-yaks-join.md b/.changeset/gold-yaks-join.md new file mode 100644 index 0000000000..4502a516cd --- /dev/null +++ b/.changeset/gold-yaks-join.md @@ -0,0 +1,6 @@ +--- +'@backstage/test-utils': patch +--- + +The test util for PluginProvider called MockPluginProvider has been created. It will be handy in the cases when you use +\_\_experimentalConfigure in your plugin diff --git a/.changeset/yellow-forks-knock.md b/.changeset/yellow-forks-knock.md index 6c3d300026..98c4b5b675 100644 --- a/.changeset/yellow-forks-knock.md +++ b/.changeset/yellow-forks-knock.md @@ -1,6 +1,5 @@ --- '@backstage/plugin-cost-insights': patch -'@backstage/test-utils': patch --- Making a possibility to hide a trending line in a cost insights plugin From 7a08bbdb870ef84c6b220baaf9af68754133b7b1 Mon Sep 17 00:00:00 2001 From: bnechyporenko Date: Fri, 18 Nov 2022 10:33:35 +0100 Subject: [PATCH 07/11] Incorporated the feedback Signed-off-by: bnechyporenko --- .changeset/gold-yaks-join.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/gold-yaks-join.md b/.changeset/gold-yaks-join.md index 4502a516cd..e035d97b27 100644 --- a/.changeset/gold-yaks-join.md +++ b/.changeset/gold-yaks-join.md @@ -2,5 +2,5 @@ '@backstage/test-utils': patch --- -The test util for PluginProvider called MockPluginProvider has been created. It will be handy in the cases when you use +The test utilility for PluginProvider called MockPluginProvider has been created. It will be handy in the cases when you use \_\_experimentalConfigure in your plugin From 4638404d76c006e88a1e0650d1fe3e84fc909732 Mon Sep 17 00:00:00 2001 From: bnechyporenko Date: Fri, 18 Nov 2022 10:34:10 +0100 Subject: [PATCH 08/11] Fixed the reviewdog validation Signed-off-by: bnechyporenko --- .changeset/gold-yaks-join.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/gold-yaks-join.md b/.changeset/gold-yaks-join.md index e035d97b27..6871948c81 100644 --- a/.changeset/gold-yaks-join.md +++ b/.changeset/gold-yaks-join.md @@ -2,5 +2,5 @@ '@backstage/test-utils': patch --- -The test utilility for PluginProvider called MockPluginProvider has been created. It will be handy in the cases when you use +The test utility for PluginProvider called MockPluginProvider has been created. It will be handy in the cases when you use \_\_experimentalConfigure in your plugin From 85868de3556a41cb4e6a13ee3eeacc57b657e488 Mon Sep 17 00:00:00 2001 From: Bogdan Nechyporenko Date: Mon, 21 Nov 2022 21:07:43 +0100 Subject: [PATCH 09/11] Update .changeset/gold-yaks-join.md Co-authored-by: Patrik Oldsberg Signed-off-by: Bogdan Nechyporenko --- .changeset/gold-yaks-join.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/gold-yaks-join.md b/.changeset/gold-yaks-join.md index 6871948c81..29996d1f74 100644 --- a/.changeset/gold-yaks-join.md +++ b/.changeset/gold-yaks-join.md @@ -2,5 +2,5 @@ '@backstage/test-utils': patch --- -The test utility for PluginProvider called MockPluginProvider has been created. It will be handy in the cases when you use -\_\_experimentalConfigure in your plugin +The test utility for the plugin context called `MockPluginProvider` has been created. It will be handy in the cases when you use +`__experimentalConfigure` in your plugin. It is experimental and exported through `@backstage/test-utils/alpha`. From 3355c5a5f1dae668760d998a9c2d4732d0ee2f77 Mon Sep 17 00:00:00 2001 From: bogdannechyporenko Date: Mon, 21 Nov 2022 21:25:26 +0100 Subject: [PATCH 10/11] Incorporated the feedback Signed-off-by: bogdannechyporenko --- packages/test-utils/package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index fb8dff4192..1734a17f6b 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -5,7 +5,8 @@ "publishConfig": { "access": "public", "main": "dist/index.esm.js", - "types": "dist/index.d.ts" + "types": "dist/index.d.ts", + "alphaTypes": "dist/index.alpha.d.ts" }, "backstage": { "role": "web-library" @@ -23,7 +24,7 @@ "main": "src/index.ts", "types": "src/index.ts", "scripts": { - "build": "backstage-cli package build", + "build": "backstage-cli package build --experimental-type-build", "lint": "backstage-cli package lint", "test": "backstage-cli package test", "prepack": "backstage-cli package prepack", @@ -60,6 +61,7 @@ "msw": "^0.48.0" }, "files": [ - "dist" + "dist", + "alpha" ] } From 79db155e4d4eca5a8fc88523e6a3d057c54cd365 Mon Sep 17 00:00:00 2001 From: bnechyporenko Date: Tue, 22 Nov 2022 17:23:23 +0100 Subject: [PATCH 11/11] Cleaned up the code Signed-off-by: bnechyporenko --- plugins/cost-insights/src/testUtils/providers.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/cost-insights/src/testUtils/providers.tsx b/plugins/cost-insights/src/testUtils/providers.tsx index 1b3f8b29aa..46eab60163 100644 --- a/plugins/cost-insights/src/testUtils/providers.tsx +++ b/plugins/cost-insights/src/testUtils/providers.tsx @@ -31,11 +31,9 @@ import { ScrollContext, ScrollContextProps, } from '../hooks'; -import { Group, Duration } from '../types'; +import { Duration } from '../types'; import { createCurrencyFormat } from '../utils/currency'; -export const MockGroups: Group[] = [{ id: 'tech' }, { id: 'mock-group' }]; - export type MockFilterProviderProps = PropsWithChildren< Partial >;