Skip to content

Commit

Permalink
Merge pull request #16 from XAlinaGS/test(ProductLifecycle)test-produ…
Browse files Browse the repository at this point in the history
…ct-lifecycle

test(CarbonFootprintVisualizations): write test for ProductLifecycle
  • Loading branch information
XAlinaGS authored Dec 8, 2024
2 parents 72fbf68 + f28784e commit 7fcaa10
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { screen } from '@testing-library/react';
import { expect } from '@jest/globals';
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(<ProductLifecycle completedStages={completedStages} />);
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(<ProductLifecycle completedStages={[]} />);
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);
});


});
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ export function ProductLifecycle(props: { completedStages: ProductLifecycleStage
data-testid="product-lifecycle-stepper"
>
{props.completedStages.map((step, index) => (
<Step key={index}>
<Step key={index} data-testid="product-lifecycle-completed-step">
<StepLabel>
<Typography fontSize={24}>
<Typography fontSize={24} data-testid="product-lifecycle-step-text">
{!!step &&
intl.formatMessage(messages.mnestix.productCarbonFootprint.lifecycleStages[step])}
</Typography>
</StepLabel>
</Step>
))}
{nextStage && (
<Step key="20" active={false}>
<StepLabel StepIconComponent={CustomCircle}>
<Step key="20" active={false} data-testid="product-lifecycle-next-step">
<StepLabel StepIconComponent={CustomCircle} data-testid="product-lifecycle-step-label">
<Typography fontSize={24} color={colorOfNextStep}>
{intl.formatMessage(messages.mnestix.productCarbonFootprint.lifecycleStages[nextStage])}{' '}
(not yet included)
Expand Down

0 comments on commit 7fcaa10

Please sign in to comment.