Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(CarbonFootprintVisualizations): write test for CarbonFootprintVi… #8

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { screen } from '@testing-library/react';
import { expect } from '@jest/globals';
import testSubmodel from '../../submodel/carbon-footprint/test-submodel/carbonFootprint-test.json';
import { Submodel } from '@aas-core-works/aas-core3.0-typescript/types';
import { CustomRenderReactIntl } from 'test-utils/CustomRenderReactIntl';
import {
CarbonFootprintVisualizations
} from 'app/[locale]/viewer/_components/submodel/carbon-footprint/CarbonFootprintVisualizations';

window.ResizeObserver =
window.ResizeObserver ||
jest.fn().mockImplementation(() => ({
disconnect: jest.fn(),
observe: jest.fn(),
unobserve: jest.fn(),
}));

jest.mock('recharts', () => {
const OriginalRechartsModule = jest.requireActual('recharts');

return {
...OriginalRechartsModule,
ResponsiveContainer: ({ height, children }: never) => (
<div className="recharts-responsive-container" style={{ width: 800, height }}>
{children}
</div>
),
};
});

describe('CarbonFootprintVisualizations Detail', () => {
it('should render all submodel visualilzations for irdi id', async () => {
CustomRenderReactIntl(
<CarbonFootprintVisualizations submodel={testSubmodel['carbonFootprint-IrdiId'] as unknown as Submodel} />,
);
assertOnElements();
});

it('should render all submodel visualilzations for URL id', async () => {
CustomRenderReactIntl(
<CarbonFootprintVisualizations submodel={testSubmodel['carbonFootprint-UrlId'] as unknown as Submodel} />,
);
assertOnElements();
});
});

function assertOnElements() {
const totalCo2Equivalents = screen.getByTestId('total-co2-equivalents-text');
expect(totalCo2Equivalents).toBeDefined();
expect(totalCo2Equivalents).toBeInTheDocument();

const productLifecycle = screen.getByTestId('product-lifecycle-stepper');
expect(productLifecycle).toBeDefined();
expect(productLifecycle).toBeInTheDocument();

const co2EquivalentsDistribution = screen.getByTestId('co2-equivalents-distribution-box');
expect(co2EquivalentsDistribution).toBeDefined();
expect(co2EquivalentsDistribution).toBeInTheDocument();

const co2Comparison = screen.getByTestId('co2-comparison-box');
expect(co2Comparison).toBeDefined();
expect(co2Comparison).toBeInTheDocument();

const productJourney = screen.getByTestId('product-journey-box');
expect(productJourney).toBeDefined();
expect(productJourney).toBeInTheDocument();

const calculationMethod = screen.getByTestId('co2-calculation-method-text');
expect(calculationMethod).toBeDefined();
expect(calculationMethod).toBeInTheDocument();
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ 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="total-co2-equivalents-text">
{`${cutDecimalPlaces(props.totalCO2Equivalents, 3)} ${unit}`}
</Typography>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function CO2EquivalentsDistribution(props: {
};

return (
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<Box sx={{ display: 'flex', flexDirection: 'column' }} data-testid="co2-equivalents-distribution-box">
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end' }}>
<Typography sx={{ color: 'primary.main', fontSize: 24 }}>
<Typography sx={{ color: 'inherit', fontSize: 'inherit', fontWeight: 600 }} component="span">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export function CalculationMethod(props: { calculationMethod: string }) {
const { calculationMethod } = props;

return (
<Typography sx={{ color: 'primary.main', fontSize: 24, fontWeight: 'bold' }}>
<Typography sx={{ color: 'primary.main', fontSize: 24, fontWeight: 'bold' }}
data-testid="co2-calculation-method-text">
{calculationMethod}{' '}
{calculationMethod === 'GHG Protocol' && (
<Link href={LinkGHG} target="_blank">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function Comparison(props: { co2Equivalents: number }) {
const { value: timePeriod, unit: unitOfTimePeriod } = determineTimePeriod(props.co2Equivalents);

return (
<Box>
<Box data-testid="co2-comparison-box">
<Box sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', gap: 2 }}>
<Tree alt="Tree" />
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('ProductJourney', () => {
it('renders the ProductJourney', async () => {

CustomRender(<ProductJourney addressesPerLifeCyclePhase={[firstAddress, secondAddress]} />);
const map = screen.getByTestId('test-map');
const map = screen.getByTestId('product-journey-box');
expect(map).toBeDefined();
expect(map).toBeInTheDocument();

Expand All @@ -56,7 +56,7 @@ describe('ProductJourney', () => {

CustomRender(<ProductJourney addressesPerLifeCyclePhase={[firstAddress, secondAddress]} />);

const map = screen.getByTestId('test-map');
const map = screen.getByTestId('product-journey-box');
expect(map).toBeDefined();
expect(map).toBeInTheDocument();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function ProductJourney(props: { addressesPerLifeCyclePhase: AddressPerLi
<>
<Box
id="map"
data-testid="test-map"
data-testid="product-journey-box"
sx={{
height: '320px',
width: '100%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function ProductLifecycle(props: { completedStages: ProductLifecycleStage
activeStep={props.completedStages.length}
orientation="vertical"
sx={{ '& .Muistel-root': { color: 'blue' } }}
data-testid="product-lifecycle-stepper"
>
{props.completedStages.map((step, index) => (
<Step key={index}>
Expand Down
Loading