Skip to content

Commit

Permalink
Merge pull request #12 from XAlinaGS/test(CarbonFootprintVisualizatio…
Browse files Browse the repository at this point in the history
…ns)test-carbon-footprint-visualizations

test(CarbonFootprintVisualizations): write test for CarbonFootprintVi…
  • Loading branch information
pawel-baran-se authored Dec 4, 2024
2 parents e096da9 + 19b4911 commit 6fa448d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 6 deletions.
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('co2-equivalents');
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 @@ -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

0 comments on commit 6fa448d

Please sign in to comment.