diff --git a/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx b/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx index 5f47544f7b..6c21e243c8 100644 --- a/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx +++ b/plugins/cost-insights/src/components/CostGrowth/CostGrowth.test.tsx @@ -17,7 +17,7 @@ import React, { PropsWithChildren } from 'react'; import { renderInTestApp } from '@backstage/test-utils'; import { CostGrowth } from './CostGrowth'; -import { Currency, CurrencyType, Duration } from '../../types'; +import { ChangeThreshold, Currency, CurrencyType, Duration } from '../../types'; import { findAlways } from '../../utils/assert'; import { MockConfigProvider, MockCurrencyProvider } from '../../testUtils'; import { defaultCurrencies } from '../../utils/currency'; @@ -33,11 +33,16 @@ const MockContext = ({ children, currency, engineerCost, + engineerThreshold, }: PropsWithChildren<{ currency: Currency; engineerCost: number; + engineerThreshold?: number; }>) => ( - + {children} ); @@ -104,3 +109,28 @@ describe.each` expect(getByText(expected)).toBeInTheDocument(); }); }); + +describe.each` + ratio | amount | threshold | expected + ${0} | ${0} | ${0} | ${'less than an engineer'} + ${0} | ${0} | ${200} | ${'Negligible'} + ${ChangeThreshold.lower} | ${0.5} | ${0} | ${'less than an engineer'} + ${ChangeThreshold.lower} | ${0.5} | ${0.5} | ${'Negligible'} + ${ChangeThreshold.upper} | ${0.5} | ${0.000001} | ${'less than an engineer'} + ${ChangeThreshold.upper} | ${0.5} | ${0.5} | ${'Negligible'} + ${3} | ${500_000} | ${0} | ${`300% or ~ 30 engineers`} + ${3} | ${500_000} | ${30} | ${'Negligible'} +`('', ({ ratio, amount, threshold, expected }) => { + it(`should display the correct difference the threshold is different. ratio: ${ratio} threshold:${threshold} expected:${expected}`, async () => { + const { getByText } = await renderInTestApp( + + + , + ); + expect(getByText(expected)).toBeInTheDocument(); + }); +}); diff --git a/plugins/cost-insights/src/components/CostGrowth/CostGrowthIndicator.test.tsx b/plugins/cost-insights/src/components/CostGrowth/CostGrowthIndicator.test.tsx index d0e7d3ff74..a83a520db2 100644 --- a/plugins/cost-insights/src/components/CostGrowth/CostGrowthIndicator.test.tsx +++ b/plugins/cost-insights/src/components/CostGrowth/CostGrowthIndicator.test.tsx @@ -18,6 +18,7 @@ import React from 'react'; import { renderInTestApp } from '@backstage/test-utils'; import { CostGrowthIndicator } from './CostGrowthIndicator'; import { ChangeThreshold, EngineerThreshold } from '../../types'; +import { MockConfigProvider } from '../../testUtils'; describe.each` ratio | amount | ariaLabel @@ -30,7 +31,9 @@ describe.each` `('growthOf', ({ ratio, amount, ariaLabel }) => { it(`should display the correct indicator for ${ariaLabel}`, async () => { const { getByLabelText } = await renderInTestApp( - , + + + , ); expect(getByLabelText(ariaLabel)).toBeInTheDocument(); }); @@ -48,7 +51,9 @@ describe.each` `('growthOf', ({ ratio, amount }) => { it('should display the correct indicator for negligible growth', async () => { const { queryByLabelText } = await renderInTestApp( - , + + + , ); expect(queryByLabelText('savings')).not.toBeInTheDocument(); expect(queryByLabelText('excess')).not.toBeInTheDocument();