-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) O3-3676 Implement ability to add patient to a queue from lab a…
…pp (#111) * (feat) ability to patient to new queue from laboratory * (feat) added jest unit
- Loading branch information
1 parent
9dc548f
commit ef73f5f
Showing
7 changed files
with
162 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...abs/actions/transition-patient-to-new-queue/transition-patient-to-new-queue.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import styles from './transition-patient-to-new-queue.scss'; | ||
import { showModal } from '@openmrs/esm-framework'; | ||
import { Button } from '@carbon/react'; | ||
import { AirlineManageGates } from '@carbon/react/icons'; | ||
|
||
interface TransitionLatestQueueEntryButtonProps { | ||
patientUuid: string; | ||
} | ||
|
||
const TransitionLatestQueueEntryButton: React.FC<TransitionLatestQueueEntryButtonProps> = ({ patientUuid }) => { | ||
const { t } = useTranslation(); | ||
|
||
const launchModal = () => { | ||
const dispose = showModal('transition-patient-to-latest-queue-modal', { | ||
closeModal: () => dispose(), | ||
patientUuid, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Button | ||
kind="tertiary" | ||
className={styles.addPatientToQueue} | ||
onClick={launchModal} | ||
size="sm" | ||
renderIcon={() => <AirlineManageGates size={18} />} | ||
> | ||
{t('transition', 'Transition')} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default TransitionLatestQueueEntryButton; |
13 changes: 13 additions & 0 deletions
13
src/lab-tabs/actions/transition-patient-to-new-queue/transition-patient-to-new-queue.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@use '@carbon/layout'; | ||
@use '@carbon/styles/scss/type'; | ||
|
||
.addPatientToQueue { | ||
--cds-layout-size-height-context: var(--cds-layout-size-height-sm, 2rem); | ||
--cds-layout-size-height: var(--cds-layout-size-height-context); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
text-align: center; | ||
padding: 0 layout.$spacing-04; | ||
gap: layout.$spacing-05; | ||
} |
64 changes: 64 additions & 0 deletions
64
...lab-tabs/actions/transition-patient-to-new-queue/transition-patient-to-new-queue.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { showModal } from '@openmrs/esm-framework'; | ||
import TransitionLatestQueueEntryButton from './transition-patient-to-new-queue.component'; | ||
|
||
jest.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ | ||
t: (key: string) => key, | ||
}), | ||
})); | ||
|
||
jest.mock('@openmrs/esm-framework', () => ({ | ||
showModal: jest.fn(), | ||
})); | ||
|
||
jest.mock('@carbon/react', () => ({ | ||
Button: ({ children, onClick, renderIcon }: any) => ( | ||
<button onClick={onClick} data-testid="transition-button"> | ||
{renderIcon && renderIcon()} | ||
{children} | ||
</button> | ||
), | ||
})); | ||
|
||
jest.mock('@carbon/react/icons', () => ({ | ||
AirlineManageGates: () => <svg data-testid="airline-icon" />, | ||
})); | ||
|
||
describe('TransitionLatestQueueEntryButton', () => { | ||
const patientUuid = '1234-uuid'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('renders the button with correct text and icon', () => { | ||
render(<TransitionLatestQueueEntryButton patientUuid={patientUuid} />); | ||
|
||
const button = screen.getByTestId('transition-button'); | ||
expect(button).toBeInTheDocument(); | ||
expect(button).toHaveTextContent('transition'); | ||
|
||
const icon = screen.getByTestId('airline-icon'); | ||
expect(icon).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls the showModal function when clicked', () => { | ||
render(<TransitionLatestQueueEntryButton patientUuid={patientUuid} />); | ||
|
||
const button = screen.getByTestId('transition-button'); | ||
fireEvent.click(button); | ||
|
||
expect(showModal).toHaveBeenCalledTimes(1); | ||
expect(showModal).toHaveBeenCalledWith( | ||
'transition-patient-to-latest-queue-modal', | ||
expect.objectContaining({ | ||
closeModal: expect.any(Function), | ||
patientUuid, | ||
}), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters