Skip to content

Commit

Permalink
test(CarbonFootprintSubmodel): Add tests for CO2 Equivalent View
Browse files Browse the repository at this point in the history
Description
Added component tests to verify that the total CO2 Equivalents are displayed correctly

Fixes # (MNES-1365)

Type of change
[x] Minor change (non-breaking change, e.g. documentation adaption)
  • Loading branch information
JonathanXITASO authored Dec 3, 2024
1 parent 0216061 commit d55a475
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { screen } from '@testing-library/react';
import { expect } from '@jest/globals';
import { CustomRenderReactIntl } from 'test-utils/CustomRenderReactIntl';
import { CO2Equivalents } from 'app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/CO2Equivalents';

describe('CarbonFootprint - CO2 Equivalents', () => {
it('should use correct style', async () => {
CustomRenderReactIntl(<CO2Equivalents totalCO2Equivalents={7.125} />);
const component = screen.getByTestId('co2-equivalents');
expect(component).toBeDefined();
expect(component).toBeInTheDocument();
expect(component).toHaveStyle('color: rgb(25, 118, 210)');
expect(component).toHaveStyle('fontSize: [72, 96]');
expect(component).toHaveStyle('font-weight: 700');
expect(component).toHaveStyle('lineHeight: 1');
});

it('should display three digit number', async () => {
CustomRenderReactIntl(<CO2Equivalents totalCO2Equivalents={7.125} />);
const component = screen.getByTestId('co2-equivalents');
expect(component).toHaveTextContent('7.125 kg');
});

it('should round to three digits', async () => {
CustomRenderReactIntl(<CO2Equivalents totalCO2Equivalents={7.125857} />);
const component = screen.getByTestId('co2-equivalents');
expect(component).toHaveTextContent('7.126 kg');
});

it('should not fill to three digits', async () => {
CustomRenderReactIntl(<CO2Equivalents totalCO2Equivalents={7.1} />);
const component = screen.getByTestId('co2-equivalents');
expect(component).toHaveTextContent('7.1 kg');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const unit = 'kg';

export function CO2Equivalents(props: { totalCO2Equivalents: number }) {
return (
<Typography sx={{ color: 'primary.main', fontSize: [72, 96], fontWeight: 'bold', lineHeight: 1 }}>
<Typography
sx={{ color: 'primary.main', fontSize: [72, 96], fontWeight: 'bold', lineHeight: 1 }}
data-testid="co2-equivalents"
>
{`${cutDecimalPlaces(props.totalCO2Equivalents, 3)} ${unit}`}
</Typography>
);
Expand Down

0 comments on commit d55a475

Please sign in to comment.