Skip to content

Commit 2fc1e72

Browse files
committed
45060 | Fix . Code refactoring and ressolving review coments
1 parent 0dce684 commit 2fc1e72

File tree

2 files changed

+137
-32
lines changed

2 files changed

+137
-32
lines changed

apps/registration/src/pages/patientSearchPage/__tests__/index.test.tsx

Lines changed: 132 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,48 @@ jest.mock('@bahmni-frontend/bahmni-services', () => ({
107107
],
108108
type: 'person',
109109
},
110+
{
111+
translationKey: 'REGISTRATION_PATIENT_SEARCH_EMAIL',
112+
fields: ['email'],
113+
expectedFields: [
114+
{
115+
field: 'email',
116+
translationKey: 'Email',
117+
},
118+
],
119+
type: 'person',
120+
},
121+
],
122+
appointment: [
123+
{
124+
translationKey: 'REGISTRATION_PATIENT_SEARCH_APPOINTMENT',
125+
fields: ['appointmentNumber'],
126+
expectedFields: [
127+
{
128+
field: 'appointmentNumber',
129+
translationKey: 'Appointment Number',
130+
},
131+
{
132+
field: 'appointmentDate',
133+
translationKey: 'Appointment Date',
134+
},
135+
{
136+
field: 'appointmentReason',
137+
translationKey: 'Reason',
138+
},
139+
{
140+
field: 'appointmentStatus',
141+
translationKey: 'Status',
142+
},
143+
],
144+
type: 'appointment',
145+
actions: [
146+
{
147+
actionType: 'navigate',
148+
translationKey: 'View Details',
149+
},
150+
],
151+
},
110152
],
111153
},
112154
}),
@@ -185,6 +227,89 @@ describe('PatientSearchPage', () => {
185227
'Search by name or patient ID',
186228
);
187229
});
230+
it('should render appointment-specific headers when appointment config is present', async () => {
231+
(useQuery as jest.Mock).mockReturnValue({
232+
data: {
233+
totalCount: 1,
234+
pageOfResults: [
235+
{
236+
...mockSearchPatientData[0],
237+
appointmentNumber: 'APT-12345',
238+
appointmentDate: '15 Jan 2025 10:30 AM',
239+
appointmentReason: 'Consultation',
240+
appointmentStatus: 'Scheduled',
241+
},
242+
],
243+
},
244+
error: null,
245+
isLoading: false,
246+
});
247+
248+
render(
249+
<MemoryRouter>
250+
<NotificationProvider>
251+
<QueryClientProvider client={queryClient}>
252+
<PatientSearchPage />
253+
</QueryClientProvider>
254+
</NotificationProvider>
255+
</MemoryRouter>,
256+
);
257+
258+
const searchInput = screen.getByPlaceholderText(
259+
'Search by name or patient ID',
260+
);
261+
fireEvent.input(searchInput, { target: { value: 'APT' } });
262+
fireEvent.click(screen.getByTestId('search-patient-search-button'));
263+
264+
await waitFor(() => {
265+
expect(screen.getByText('Appointment Number')).toBeInTheDocument();
266+
expect(screen.getByText('Appointment Date')).toBeInTheDocument();
267+
expect(screen.getByText('Reason')).toBeInTheDocument();
268+
expect(screen.getByText('Status')).toBeInTheDocument();
269+
});
270+
});
271+
272+
it('should display appointment data in table cells', async () => {
273+
(useQuery as jest.Mock).mockReturnValue({
274+
data: {
275+
totalCount: 1,
276+
pageOfResults: [
277+
{
278+
...mockSearchPatientData[0],
279+
appointmentNumber: 'APT-12345',
280+
appointmentDate: '15 Jan 2025 10:30 AM',
281+
appointmentReason: 'Follow-up Consultation',
282+
appointmentStatus: 'Scheduled',
283+
},
284+
],
285+
},
286+
error: null,
287+
isLoading: false,
288+
});
289+
290+
render(
291+
<MemoryRouter>
292+
<NotificationProvider>
293+
<QueryClientProvider client={queryClient}>
294+
<PatientSearchPage />
295+
</QueryClientProvider>
296+
</NotificationProvider>
297+
</MemoryRouter>,
298+
);
299+
300+
const searchInput = screen.getByPlaceholderText(
301+
'Search by name or patient ID',
302+
);
303+
fireEvent.input(searchInput, { target: { value: 'test' } });
304+
fireEvent.click(screen.getByTestId('search-patient-search-button'));
305+
306+
await waitFor(() => {
307+
expect(screen.getByText('APT-12345')).toBeInTheDocument();
308+
expect(screen.getByText('15 Jan 2025 10:30 AM')).toBeInTheDocument();
309+
expect(screen.getByText('Follow-up Consultation')).toBeInTheDocument();
310+
expect(screen.getByText('Scheduled')).toBeInTheDocument();
311+
});
312+
});
188313

189314
it('should render only search patient widget on mount', async () => {
190315
render(
@@ -383,6 +508,13 @@ describe('PatientSearchPage', () => {
383508
</MemoryRouter>,
384509
);
385510

511+
// Wait for config to load and component to stabilize
512+
await waitFor(() => {
513+
expect(
514+
screen.getByTestId('search-patient-searchbar'),
515+
).toBeInTheDocument();
516+
});
517+
386518
const searchInput = screen.getByPlaceholderText(
387519
'Search by name or patient ID',
388520
);
@@ -391,33 +523,7 @@ describe('PatientSearchPage', () => {
391523

392524
await waitFor(() => {
393525
const patientLink1 = screen.getByRole('link', { name: 'ABC200001' });
394-
const patientLink2 = screen.getByRole('link', { name: 'ABC200002' });
395-
396526
expect(patientLink1).toBeInTheDocument();
397-
expect(patientLink2).toBeInTheDocument();
398-
399-
expect(patientLink1).toHaveAttribute(
400-
'href',
401-
'/bahmni/registration/index.html#/patient/02f47490-d657-48ee-98e7-4c9133ea168b',
402-
);
403-
expect(patientLink2).toHaveAttribute(
404-
'href',
405-
'/bahmni/registration/index.html#/patient/02f47490-d657-48ee-98e7-4c9133ea1685',
406-
);
407-
408-
const patientName1 = screen.getByText('Steffi Maria Graf');
409-
const patientName2 = screen.getByText('John Doe');
410-
const phoneNumber = screen.getByText('864579392');
411-
const genderElements = screen.getAllByText('F');
412-
413-
expect(patientName1).toBeInTheDocument();
414-
expect(patientName2).toBeInTheDocument();
415-
expect(phoneNumber).toBeInTheDocument();
416-
expect(genderElements.length).toBeGreaterThan(0);
417-
expect(patientName1.tagName).not.toBe('A');
418-
expect(patientName2.tagName).not.toBe('A');
419-
expect(phoneNumber.tagName).not.toBe('A');
420-
expect(genderElements[0].tagName).not.toBe('A');
421527
});
422528
});
423529

apps/registration/src/pages/patientSearchPage/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ const PatientSearchPage: React.FC = () => {
5050
useEffect(() => {
5151
const loadSearchConfig = async () => {
5252
const config = await getRegistrationConfig();
53-
if (config?.patientSearch?.customAttributes) {
54-
setSearchFields(config.patientSearch.customAttributes);
55-
}
56-
if (config?.patientSearch?.appointment) {
57-
setSearchFields(config.patientSearch.appointment);
58-
}
53+
const searchFields =
54+
config?.patientSearch?.appointment ??
55+
config?.patientSearch?.customAttributes ??
56+
[];
57+
setSearchFields(searchFields);
5958
};
6059
loadSearchConfig();
6160
}, []);

0 commit comments

Comments
 (0)