Skip to content

Commit

Permalink
Merge branch 'main' into id-field
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush-AI authored Sep 21, 2023
2 parents 737c2fd + 0eb6147 commit b3c5172
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import Pagination from './pagination.component';

describe('Pagination', () => {
it('should render correctly with page numbers', () => {
render(<Pagination totalPages={5} currentPage={3} setCurrentPage={() => {}} hasMore={true} />);

for (let i = 1; i <= 5; i++) {
const pageButtons = screen.getByRole('button', { name: `${i}` });
expect(pageButtons).toBeInTheDocument();
}
});

it('should disable previous button on first page', () => {
render(<Pagination totalPages={5} currentPage={1} setCurrentPage={() => {}} hasMore={true} />);
const previousButton = screen.getByLabelText(/previous page/i);
expect(previousButton).toBeDisabled();
});

it('should disable next button on last page when hasMore is false', () => {
render(<Pagination totalPages={5} currentPage={5} setCurrentPage={() => {}} hasMore={false} />);
const nextButton = screen.getByLabelText(/next page/i);
expect(nextButton).toBeDisabled();
});

it('should increment the page when next button is clicked', () => {
const setCurrentPageMock = jest.fn();
render(<Pagination totalPages={5} currentPage={1} setCurrentPage={setCurrentPageMock} hasMore={true} />);

const nextButton = screen.getByLabelText(/next page/i);
fireEvent.click(nextButton);
expect(setCurrentPageMock).toHaveBeenCalledWith(2);
});

it('should decrement the page when previous button is clicked', () => {
const setCurrentPageMock = jest.fn();
render(<Pagination totalPages={5} currentPage={3} setCurrentPage={setCurrentPageMock} hasMore={true} />);

const previousButton = screen.getByLabelText(/previous page/i);
fireEvent.click(previousButton);
expect(setCurrentPageMock).toHaveBeenCalledWith(2);
});

it('should call setCurrentPage when page button is clicked', () => {
const setCurrentPageMock = jest.fn();
render(<Pagination totalPages={5} currentPage={3} setCurrentPage={setCurrentPageMock} hasMore={true} />);

const pageButton = screen.getByRole('button', { name: '4' });
fireEvent.click(pageButton);
expect(setCurrentPageMock).toHaveBeenCalledWith(4);
});

it('should render empty component when totalPages is 1', () => {
render(<Pagination totalPages={1} currentPage={1} setCurrentPage={() => {}} hasMore={true} />);
const pagination = screen.queryByRole('button', { name: 'next page' });
expect(pagination).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ function ActiveVisitsTable() {
},
{
id: 3,
header: t('locationComingFrom', 'Coming from'),
key: 'locationComingFrom',
header: t('queueComingFrom', 'Coming from'),
key: 'queueComingFrom',
},
{
id: 4,
Expand Down Expand Up @@ -218,8 +218,8 @@ function ActiveVisitsTable() {
</>
),
},
locationComingFrom: {
content: <span className={styles.statusContainer}>{entry?.locationComingFrom}</span>,
queueComingFrom: {
content: <span className={styles.statusContainer}>{entry?.queueComingFrom}</span>,
},
status: {
content: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface VisitQueueEntry {
uuid: string;
visit: Visit;
sortWeight: number;
locationComingFrom: {
queueComingFrom: {
name: string;
};
}
Expand Down Expand Up @@ -102,7 +102,7 @@ export interface MappedVisitQueueEntry {
sortWeight: number;
visitQueueNumber: string;
identifiers: Array<Identifer>;
locationComingFrom: string;
queueComingFrom: string;
}

interface UseVisitQueueEntries {
Expand Down Expand Up @@ -248,7 +248,7 @@ export function useVisitQueueEntries(currServiceName: string, locationUuid: stri
(e) => e.attributeType.uuid === visitQueueNumberAttributeUuid,
)?.value,
identifiers: visitQueueEntry.queueEntry.patient?.identifiers,
locationComingFrom: visitQueueEntry.queueEntry?.locationComingFrom?.name,
queueComingFrom: visitQueueEntry.queueEntry?.queueComingFrom?.name,
});

let mappedVisitQueueEntries;
Expand Down Expand Up @@ -315,7 +315,7 @@ export async function updateQueueEntry(
},
startedAt: toDateObjectStrict(toOmrsIsoString(new Date())),
sortWeight: sortWeight,
locationComingFrom: previousQueueUuid,
queueComingFrom: previousQueueUuid,
},
},
});
Expand Down
10 changes: 5 additions & 5 deletions packages/esm-service-queues-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ export const configSchema = {
_description: 'The UUID of the default status for attending a service in the queues eg In Service.',
_default: 'ca7494ae-437f-4fd0-8aae-b88b9a2ba47d',
},
visitQueueNumberAttributeUuid: {
_type: Type.ConceptUuid,
_description: 'The UUID of the visit attribute that contains the visit queue number.',
_default: 'c61ce16f-272a-41e7-9924-4c555d0932c5',
},
systolicBloodPressureUuid: {
_type: Type.ConceptUuid,
_default: '5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
Expand Down Expand Up @@ -93,6 +88,11 @@ export const configSchema = {
'The Uuids of person attribute-type that captures contact information `e.g Next of kin contact details`',
_default: [],
},
visitQueueNumberAttributeUuid: {
_type: Type.UUID,
_description: 'The UUID of the visit attribute that contains the visit queue number.',
_default: 'c61ce16f-272a-41e7-9924-4c555d0932c5',
},
vitals: vitalsConfigSchema,
biometrics: biometricsConfigSchema,
showQueueTableTab: {
Expand Down

0 comments on commit b3c5172

Please sign in to comment.