Skip to content

Commit 45ad7e2

Browse files
committed
BN-37 | Fix. Component Structure In Index
1 parent 0636e4e commit 45ad7e2

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ root.render(
1616
<React.StrictMode>
1717
<BrowserRouter basename={process.env.PUBLIC_URL || '/'}>
1818
<NotificationProvider>
19+
<NotificationServiceComponent />
1920
<ClinicalConfigProvider>
20-
<NotificationServiceComponent />
2121
<App />
2222
</ClinicalConfigProvider>
2323
</NotificationProvider>

src/pages/HomePage.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
import React, { Suspense } from 'react';
22
import { Grid, Column, Section, Loading } from '@carbon/react';
3+
import PatientDetails from '@components/patient/PatientDetails';
4+
import ConditionsTable from '@components/conditions/ConditionsTable';
5+
import AllergiesTable from '@components/allergies/AllergiesTable';
36
import { useClinicalConfig } from '@hooks/useClinicalConfig';
47

5-
const PatientDetails = React.lazy(
6-
() => import('@components/patient/PatientDetails'),
7-
);
8-
const ConditionsTable = React.lazy(
9-
() => import('@components/conditions/ConditionsTable'),
10-
);
11-
const AllergiesTable = React.lazy(
12-
() => import('@components/allergies/AllergiesTable'),
13-
);
14-
158
const HomePage: React.FC = () => {
169
const { clinicalConfig } = useClinicalConfig();
1710
if (!clinicalConfig) {
1811
return <Loading description="Loading..." />;
1912
}
2013
console.log(clinicalConfig);
2114
return (
22-
<Suspense fallback={<Loading description="Loading..." />}>
15+
<Suspense fallback="loading">
2316
<Section>
2417
<Grid>
2518
<Column lg={16} md={8} sm={4}>

src/pages/__tests__/HomePage.test.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import React from 'react';
1+
import React, { ReactNode } from 'react';
22
import { render, screen } from '@testing-library/react';
33
import HomePage from '../HomePage';
44
import PatientDetails from '@components/patient/PatientDetails';
55
import ConditionsTable from '@components/conditions/ConditionsTable';
66
import { useClinicalConfig } from '@hooks/useClinicalConfig';
77
import { validFullClinicalConfig } from '@__mocks__/configMocks';
88

9+
// Mock React.Suspense to render children immediately in tests
10+
jest.mock('react', () => ({
11+
...jest.requireActual('react'),
12+
Suspense: ({ children }: { children: ReactNode }) => children,
13+
}));
14+
915
// Mock Carbon components
1016
jest.mock('@carbon/react', () => ({
1117
Grid: jest.fn(({ children }) => (
@@ -67,7 +73,7 @@ describe('HomePage Component', () => {
6773
).not.toBeInTheDocument();
6874
});
6975

70-
it('should render with correct Carbon layout structure when config is loaded', () => {
76+
it('should render with correct Carbon layout structure when config is loaded', async () => {
7177
// Mock useClinicalConfig to return config
7278
(useClinicalConfig as jest.Mock).mockReturnValue({
7379
clinicalConfig: validFullClinicalConfig,
@@ -76,12 +82,12 @@ describe('HomePage Component', () => {
7682
render(<HomePage />);
7783

7884
// Should render Carbon layout components
79-
expect(screen.getByTestId('carbon-section')).toBeInTheDocument();
80-
expect(screen.getByTestId('carbon-grid')).toBeInTheDocument();
81-
expect(screen.getByTestId('carbon-column')).toBeInTheDocument();
85+
expect(await screen.findByTestId('carbon-section')).toBeInTheDocument();
86+
expect(await screen.findByTestId('carbon-grid')).toBeInTheDocument();
87+
expect(await screen.findByTestId('carbon-column')).toBeInTheDocument();
8288
});
8389

84-
it('should render child components when config is loaded', () => {
90+
it('should render child components when config is loaded', async () => {
8591
// Mock useClinicalConfig to return config
8692
(useClinicalConfig as jest.Mock).mockReturnValue({
8793
clinicalConfig: validFullClinicalConfig,
@@ -91,12 +97,20 @@ describe('HomePage Component', () => {
9197

9298
// Should render child components
9399
expect(PatientDetails).toHaveBeenCalled();
94-
expect(screen.getByTestId('mocked-patient-details')).toBeInTheDocument();
95-
expect(screen.getByText('Mocked PatientDetails')).toBeInTheDocument();
100+
expect(
101+
await screen.findByTestId('mocked-patient-details'),
102+
).toBeInTheDocument();
103+
expect(
104+
await screen.findByText('Mocked PatientDetails'),
105+
).toBeInTheDocument();
96106

97107
expect(ConditionsTable).toHaveBeenCalled();
98-
expect(screen.getByTestId('mocked-conditions-table')).toBeInTheDocument();
99-
expect(screen.getByText('Mocked ConditionsTable')).toBeInTheDocument();
108+
expect(
109+
await screen.findByTestId('mocked-conditions-table'),
110+
).toBeInTheDocument();
111+
expect(
112+
await screen.findByText('Mocked ConditionsTable'),
113+
).toBeInTheDocument();
100114
});
101115

102116
it('should match snapshot when loading', () => {

0 commit comments

Comments
 (0)