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

(fix) O3-3543: Fix test types search in the lab order workspace #1910

Merged
merged 4 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { render, renderHook, screen, waitFor } from '@testing-library/react';
import AddLabOrderWorkspace from './add-lab-order.workspace';
import userEvent from '@testing-library/user-event';
import { render, renderHook, screen, waitFor } from '@testing-library/react';
import { _resetOrderBasketStore } from '@openmrs/esm-patient-common-lib/src/orders/store';
import { type PostDataPrepLabOrderFunction } from '../api';
import { age, closeWorkspace, useConfig, useLayoutType, usePatient, useSession } from '@openmrs/esm-framework';
import { type PostDataPrepFunction, useOrderBasket } from '@openmrs/esm-patient-common-lib';
import { createEmptyLabOrder } from './lab-order';
import AddLabOrderWorkspace from './add-lab-order.workspace';

const mockUseConfig = useConfig as jest.Mock;
const mockUseSession = useSession as jest.Mock;
Expand Down Expand Up @@ -40,10 +40,11 @@ jest.mock('./useTestTypes', () => ({
useTestTypes: () => mockUseTestTypes(),
}));

const mocklaunchPatientWorkspace = jest.fn();
const mockLaunchPatientWorkspace = jest.fn();

jest.mock('@openmrs/esm-patient-common-lib', () => ({
...jest.requireActual('@openmrs/esm-patient-common-lib'),
launchPatientWorkspace: (...args) => mocklaunchPatientWorkspace(...args),
launchPatientWorkspace: (...args) => mockLaunchPatientWorkspace(...args),
}));

jest.mock('@openmrs/esm-patient-common-lib/src/get-patient-uuid-from-url', () => ({
Expand Down Expand Up @@ -95,6 +96,7 @@ describe('AddLabOrder', () => {

beforeEach(() => {
_resetOrderBasketStore();
jest.clearAllMocks();
});

test('happy path fill and submit form', async () => {
Expand All @@ -104,9 +106,9 @@ describe('AddLabOrder', () => {
);
const { mockCloseWorkspaceWithSavedChanges } = renderAddLabOrderWorkspace();
await user.type(screen.getByRole('searchbox'), 'cd4');
const cd4 = screen.getByText('CD4 COUNT');
expect(cd4).toBeInTheDocument();
const cd4OrderButton = screen.getAllByRole('button', { name: 'Order form' })[1];
await screen.findByText('CD4 COUNT');

const cd4OrderButton = screen.getByRole('button', { name: /order form/i });
await user.click(cd4OrderButton);

const testType = screen.getByRole('combobox', { name: 'Test type' });
Expand Down Expand Up @@ -143,7 +145,7 @@ describe('AddLabOrder', () => {
});

expect(mockCloseWorkspaceWithSavedChanges).toHaveBeenCalled();
expect(mocklaunchPatientWorkspace).toHaveBeenCalledWith('order-basket');
expect(mockLaunchPatientWorkspace).toHaveBeenCalledWith('order-basket');
});

test('from lab search, click add directly to order basket', async () => {
Expand All @@ -153,16 +155,22 @@ describe('AddLabOrder', () => {
);
renderAddLabOrderWorkspace();
await user.type(screen.getByRole('searchbox'), 'cd4');
const cd4 = screen.getByText('CD4 COUNT');
expect(cd4).toBeInTheDocument();
const cd4OrderButton = screen.getAllByRole('button', { name: 'Add to basket' })[1];
await user.click(cd4OrderButton);
expect(hookResult.current.orders).toEqual([
{ ...createEmptyLabOrder(mockTestTypes[1], 'test-provider-uuid'), isOrderIncomplete: true },
]);
await screen.findByText('CD4 COUNT');

const cd4AddToBasketButton = screen.getByRole('button', { name: /add to basket/i });
await user.click(cd4AddToBasketButton);

await waitFor(() => {
expect(hookResult.current.orders).toEqual([
{ ...createEmptyLabOrder(mockTestTypes[1], 'test-provider-uuid'), isOrderIncomplete: true },
]);
});

expect(mockCloseWorkspace).toHaveBeenCalled();
expect(mocklaunchPatientWorkspace).toHaveBeenCalledWith('order-basket');
expect(mockCloseWorkspace).toHaveBeenCalledWith('add-lab-order', {
ignoreChanges: true,
onWorkspaceClose: expect.any(Function),
});
});

test('back to order basket', async () => {
Expand All @@ -172,7 +180,7 @@ describe('AddLabOrder', () => {
expect(back).toBeInTheDocument();
await user.click(back);
expect(mockCloseWorkspace).toHaveBeenCalled();
expect(mocklaunchPatientWorkspace).toHaveBeenCalledWith('order-basket');
expect(mockLaunchPatientWorkspace).toHaveBeenCalledWith('order-basket');
});

test('should display a patient header on tablet', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type LabOrderBasketItem,
launchPatientWorkspace,
} from '@openmrs/esm-patient-common-lib';
import { TestTypeSearch } from './test-type-search';
import { TestTypeSearch } from './test-type-search.component';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to match our naming conventions.

import { LabOrderForm } from './lab-order-form.component';
import styles from './add-lab-order.scss';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
@use '@carbon/styles/scss/type';
@use '@carbon/styles/scss/spacing';
@use '@carbon/type';
@use '@carbon/layout';
@use '@carbon/colors';
@import '@openmrs/esm-styleguide/src/vars';
@import "../../root";

denniskigen marked this conversation as resolved.
Show resolved Hide resolved

.orderForm {
flex-grow: 1;
display: flex;
Expand All @@ -16,15 +15,15 @@
}

:global(.cds--css-grid-column) {
margin: 0 spacing.$spacing-03 !important;
margin: 0 !important;
}
denniskigen marked this conversation as resolved.
Show resolved Hide resolved

:global(.cds--subgrid) {
margin: 0 calc(spacing.$spacing-03 * -1) !important;
margin: 0 calc(layout.$spacing-03 * -1) !important;
}

:global(.cds--number--nosteppers.cds--number input[type=number]) {
padding-right: spacing.$spacing-05;
padding-right: layout.$spacing-05;
}

:global(.cds--number__control-btn) {
Expand All @@ -33,7 +32,7 @@
}

.form {
margin: spacing.$spacing-05;
margin: layout.$spacing-05;
}

.gridRow {
Expand All @@ -45,7 +44,7 @@
}

.field {
margin-bottom: spacing.$spacing-05;
margin-bottom: layout.$spacing-05;
}

.buttonSet {
Expand All @@ -71,12 +70,12 @@
}

.buttonSet {
padding: spacing.$spacing-06 spacing.$spacing-05;
padding: layout.$spacing-06 layout.$spacing-05;
background-color: $ui-02;
}

.errorContainer {
margin: 1rem;
margin-bottom: calc(var(--bottom-nav-height) + 1rem);
}
}
}
Loading
Loading