Skip to content

Commit

Permalink
test - CO2EDistributionBarchart component test to verify axis
Browse files Browse the repository at this point in the history
  • Loading branch information
pawel-baran-se committed Dec 4, 2024
1 parent 599858f commit 63170d1
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { screen } from '@testing-library/react';
import { expect } from '@jest/globals';
import { CustomRenderReactIntl } from 'test-utils/CustomRenderReactIntl';
import { CO2EBarchart } from 'app/[locale]/viewer/_components/submodel/carbon-footprint/visualization-components/CO2EDistributionDiagrams/CO2EDistributionBarchart';

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: ({ children }: never) => (
<OriginalRechartsModule.ResponsiveContainer
className="recharts-responsive-container"
width={800}
height={800}
>
{children}
</OriginalRechartsModule.ResponsiveContainer>
),
};
});

const co2EquivalentsPerLifecycleStage = {
A1: 0.235,
A2: 0.553,
A3: 0.823,
A4: 0.123,
};

describe('CarbonFootprint - CO2EquivalentsDistribution', () => {
it('should renders correct axis descriptions', async () => {
CustomRenderReactIntl(<CO2EBarchart co2EquivalentsPerLifecycleStage={co2EquivalentsPerLifecycleStage} />);
expect(screen.getByText('kg CO2e')).toBeInTheDocument();
expect(screen.getByText('CO2 Equivalents')).toBeInTheDocument();
expect(screen.getByText('A3')).toBeInTheDocument();
expect(screen.getByText('A2')).toBeInTheDocument();
expect(screen.getByText('A1')).toBeInTheDocument();
});
});

0 comments on commit 63170d1

Please sign in to comment.