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(submodel detail) check carbon footprint submodel visualization #6

Merged
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
10 changes: 9 additions & 1 deletion jest.frontend.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import nextJest from 'next/jest';
import { Config } from 'jest';
import { TextDecoder, TextEncoder } from 'util';

export {};
const createJestConfig = nextJest({
Expand All @@ -11,6 +12,13 @@ const config: Config = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testEnvironment: 'jsdom',
modulePathIgnorePatterns: ['cypress'],
globals: {
'ts-jest': {
tsConfigFile: 'tsconfig.json',
},
TextEncoder: TextEncoder,
TextDecoder: TextDecoder,
},
// mock all svg files
moduleNameMapper: {
'^.+\\.(svg)$': '<rootDir>/__mocks__/svg.tsx',
Expand All @@ -28,7 +36,7 @@ const jestConfigWithOverrides = async (...args) => {
// Don't ignore specific node_modules during transformation. This is needed if a node_module doesn't return valid JavaScript files.
res.transformIgnorePatterns = res.transformIgnorePatterns!.map((pattern) => {
if (pattern === '/node_modules/') {
return '/node_modules/(?!flat|jose|ol|color-space|color-rgba|color-parse|color-name|quick-lru)';
return '/node_modules/(?!.+)';
}
return pattern;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { screen } from '@testing-library/react';
import { expect } from '@jest/globals';
import { SubmodelDetail } from 'app/[locale]/viewer/_components/submodel/SubmodelDetail';
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';

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>
),
};
});

jest.mock('next-auth', jest.fn());

describe('Submodel Detail', () => {
it('should render CarbonFootprintVisualizations for irdi id', async () => {
CustomRenderReactIntl(
<SubmodelDetail submodel={testSubmodel['carbonFootprint-IrdiId'] as unknown as Submodel} />,
);
const map = screen.getByTestId('carbonFootprintVisualizations');
expect(map).toBeDefined();
expect(map).toBeInTheDocument();
});

it('should render CarbonFootprintVisualizations for URL id', async () => {
CustomRenderReactIntl(
<SubmodelDetail submodel={testSubmodel['carbonFootprint-UrlId'] as unknown as Submodel} />,
);
const map = screen.getByTestId('carbonFootprintVisualizations');
expect(map).toBeDefined();
expect(map).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function CarbonFootprintVisualizations(props: { submodel: Submodel }) {
const calculationMethod = extractCalculationMethod(pcfSubmodelElements);

return (
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
<Box sx={{ display: 'flex', flexDirection: 'column' }} data-testid="carbonFootprintVisualizations">
<StyledDataRow title={intl.formatMessage(messages.mnestix.productCarbonFootprint.totalCO2Equivalents)}>
<CO2Equivalents totalCO2Equivalents={totalCO2Equivalents} />
</StyledDataRow>
Expand Down
Loading