From f403fce32cce47c2b16173e4bd884d6b9941d672 Mon Sep 17 00:00:00 2001 From: Alina Geesen-Stucky Date: Wed, 4 Dec 2024 10:57:51 +0100 Subject: [PATCH 1/2] test(CarbonFootprintVisualizations): write test for ProductLifecycle --- .../ProductLifecycle.spec.tsx | 62 +++++++++++++++++++ .../ProductLifecycle.tsx | 8 +-- 2 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.spec.tsx diff --git a/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.spec.tsx b/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.spec.tsx new file mode 100644 index 0000000..18be1ca --- /dev/null +++ b/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.spec.tsx @@ -0,0 +1,62 @@ +import { CustomRender } from 'test-utils/CustomRender'; +import { screen } from '@testing-library/react'; +import { expect } from '@jest/globals'; +import { ProductJourney } from './ProductJourney'; +import { ProductLifecycleStage } from 'lib/enums/ProductLifecycleStage.enum'; +import { + ProductLifecycle +} from 'app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle'; +import { CustomRenderReactIntl } from 'test-utils/CustomRenderReactIntl'; + +window.ResizeObserver = + window.ResizeObserver || + jest.fn().mockImplementation(() => ({ + disconnect: jest.fn(), + observe: jest.fn(), + unobserve: jest.fn(), + })); + + +const completedStages = + [ProductLifecycleStage.A1RawMaterialSupply, + ProductLifecycleStage.A2CradleToGate, + ProductLifecycleStage.A3Production, + ProductLifecycleStage.A4TransportToFinalDestination + ] ; + +describe('ProductLifecycle', () => { + it('should render the ProductLifecycle with all steps', async () => { + CustomRenderReactIntl(); + const stepper = screen.getByTestId('product-lifecycle-stepper'); + expect(stepper).toBeDefined(); + expect(stepper).toBeInTheDocument(); + + const completedSteps = screen.getAllByTestId('product-lifecycle-completed-step'); + expect(completedSteps).toBeDefined(); + expect(completedSteps.length).toBe(4); + + completedSteps.forEach((el) => { + expect(el).toBeInTheDocument(); + }); + + const nextSteps = screen.getAllByTestId('product-lifecycle-next-step'); + expect(nextSteps).toBeDefined(); + expect(nextSteps.length).toBe(1); + }); + + it('should render no completed steps if none are completed', async () => { + CustomRenderReactIntl(); + const stepper = screen.getByTestId('product-lifecycle-stepper'); + expect(stepper).toBeDefined(); + expect(stepper).toBeInTheDocument(); + + const completedSteps= screen.queryByTestId('product-lifecycle-completed-step') + expect(completedSteps).toBeNull(); + + const addressList = screen.getAllByTestId('product-lifecycle-next-step'); + expect(addressList).toBeDefined(); + expect(addressList.length).toBe(1); + }); + + +}); diff --git a/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.tsx b/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.tsx index a005e79..d68897b 100644 --- a/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.tsx +++ b/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.tsx @@ -30,9 +30,9 @@ export function ProductLifecycle(props: { completedStages: ProductLifecycleStage data-testid="product-lifecycle-stepper" > {props.completedStages.map((step, index) => ( - + - + {!!step && intl.formatMessage(messages.mnestix.productCarbonFootprint.lifecycleStages[step])} @@ -40,8 +40,8 @@ export function ProductLifecycle(props: { completedStages: ProductLifecycleStage ))} {nextStage && ( - - + + {intl.formatMessage(messages.mnestix.productCarbonFootprint.lifecycleStages[nextStage])}{' '} (not yet included) From f28784ec5d4bd66aac129b32b56a651af7363388 Mon Sep 17 00:00:00 2001 From: Alina Geesen-Stucky Date: Wed, 4 Dec 2024 11:00:02 +0100 Subject: [PATCH 2/2] test(CarbonFootprintVisualizations):PR fix --- .../visualization-components/ProductLifecycle.spec.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.spec.tsx b/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.spec.tsx index 18be1ca..ac7bcf3 100644 --- a/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.spec.tsx +++ b/src/app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/ProductLifecycle.spec.tsx @@ -1,7 +1,5 @@ -import { CustomRender } from 'test-utils/CustomRender'; import { screen } from '@testing-library/react'; import { expect } from '@jest/globals'; -import { ProductJourney } from './ProductJourney'; import { ProductLifecycleStage } from 'lib/enums/ProductLifecycleStage.enum'; import { ProductLifecycle