Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Dec 16, 2024
2 parents bd4e5dc + 3554f5c commit 12d5ba0
Show file tree
Hide file tree
Showing 263 changed files with 5,626 additions and 1,801 deletions.
20 changes: 14 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
"env": {
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest-dom/recommended",
"plugin:testing-library/react"
],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:jest-dom/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "import", "jest-dom", "react-hooks", "testing-library"],
"overrides": [
{
"files": ["**/*.test.tsx"],
"extends": ["plugin:testing-library/react"]
},
{
"files": ["e2e/**/*.spec.ts"],
"extends": ["plugin:playwright/recommended"],
"rules": {
"testing-library/prefer-screen-queries": "off"
}
}
],
"rules": {
"react-hooks/exhaustive-deps": "warn",
"react-hooks/rules-of-hooks": "error",
Expand Down
9 changes: 1 addition & 8 deletions __mocks__/conditions.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,6 @@ export const mockFhirConditionsResponse = {
export const searchedCondition = [
{
display: 'Headache',
concept: {
uuid: '139084AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
display: 'Headache',
},
conceptName: {
uuid: '38867BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB',
display: 'Headache',
},
uuid: '139084AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
];
2 changes: 2 additions & 0 deletions __mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export * from './location.mock';
export * from './medication.mock';
export * from './mockBasePanel.mock';
export * from './mockDeceasedPatient';
export * from './order-stock-data.mock';
export * from './order-price-data.mock';
export * from './patient-flags.mock';
export * from './programs.mock';
export * from './relationships.mock';
Expand Down
40 changes: 40 additions & 0 deletions __mocks__/order-price-data.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { OrderPriceData } from '@openmrs/esm-patient-orders-app/src/types/order';

export const mockOrderPriceData: OrderPriceData = {
resourceType: 'Bundle',
id: 'test-id',
meta: {
lastUpdated: '2024-01-01T00:00:00Z',
},
type: 'searchset',
link: [
{
relation: 'self',
url: 'test-url',
},
],
entry: [
{
resource: {
resourceType: 'ChargeItemDefinition',
id: 'test-resource-id',
name: 'Test Item',
status: 'active',
date: '2024-01-01',
propertyGroup: [
{
priceComponent: [
{
type: 'base',
amount: {
value: 99.99,
currency: 'USD',
},
},
],
},
],
},
},
],
};
46 changes: 46 additions & 0 deletions __mocks__/order-stock-data.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export const mockOrderStockData = {
resourceType: 'Bundle',
id: 'test-id',
meta: {
lastUpdated: '2024-01-01T00:00:00Z',
},
type: 'searchset',
link: [
{
relation: 'self',
url: 'test-url',
},
],
entry: [
{
resource: {
resourceType: 'InventoryItem',
id: 'test-resource-id',
meta: {
profile: ['test-profile'],
},
status: 'active',
code: [
{
coding: [
{
system: 'test-system',
code: 'test-code',
display: 'Test Item',
},
],
},
],
name: [
{
name: 'Test Item',
},
],
netContent: {
value: 10,
unit: 'units',
},
},
},
],
};
2 changes: 1 addition & 1 deletion __mocks__/react-i18next.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const renderNodes = (reactNodes) => {

const useMock = [(key) => key, {}];
useMock.t = (key, defaultValue, options = {}) => {
let translatedString = defaultValue;
let translatedString = defaultValue ? defaultValue : key;
Object.keys(options).forEach((key) => {
translatedString = defaultValue.replace(`{{${key}}}`, `${options[key]}`);
});
Expand Down
1 change: 1 addition & 0 deletions __mocks__/vitals-and-biometrics.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6002,6 +6002,7 @@ export const mockVitalsConfig = {
systolicBloodPressureUuid: '5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
temperatureUuid: '5088AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
weightUuid: '5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
vitalSignsConceptSetUuid: '1114AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
vitals: {
encounterTypeUuid: '67a71486-1a54-468f-ac3e-7091a9a79584',
Expand Down
12 changes: 6 additions & 6 deletions e2e/commands/visit-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export const startVisit = async (api: APIRequestContext, patientId: string): Pro
},
});

await expect(visitRes.ok()).toBeTruthy();
expect(visitRes.ok()).toBeTruthy();
return await visitRes.json();
};

export const endVisit = async (api: APIRequestContext, uuid: string) => {
const visitRes = await api.post(`visit/${uuid}`, {
export const endVisit = async (api: APIRequestContext, visit: Visit) => {
const visitRes = await api.post(`visit/${visit.uuid}`, {
data: {
location: process.env.E2E_LOGIN_DEFAULT_LOCATION_UUID,
startDatetime: dayjs().subtract(1, 'D').format('YYYY-MM-DDTHH:mm:ss.SSSZZ'),
visitType: '7b0f5697-27e3-40c4-8bae-f4049abfb4ed',
location: visit.location.uuid,
startDatetime: visit.startDatetime,
visitType: visit.visitType.uuid,
stopDatetime: dayjs().format('YYYY-MM-DDTHH:mm:ss.SSSZZ'),
},
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/specs/biometrics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ test('Record biometrics', async ({ page }) => {
});

test.afterEach(async ({ api }) => {
await endVisit(api, visit.uuid);
await endVisit(api, visit);
await deletePatient(api, patient.uuid);
});
2 changes: 1 addition & 1 deletion e2e/specs/clinical-forms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,6 @@ test('Form state is retained when minimizing a form in the workspace', async ({
});

test.afterEach(async ({ api }) => {
await endVisit(api, visit.uuid);
await endVisit(api, visit);
await deletePatient(api, patient.uuid);
});
2 changes: 1 addition & 1 deletion e2e/specs/drug-orders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,6 @@ test('Record, edit and discontinue a drug order', async ({ page }) => {
});

test.afterEach(async ({ api }) => {
await endVisit(api, visit.uuid);
await endVisit(api, visit);
await deletePatient(api, patient.uuid);
});
18 changes: 10 additions & 8 deletions e2e/specs/lab-orders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ test.describe.serial('Running laboratory order tests sequentially', () => {
});

await test.step('When I fill in the fields in the form for the Blood urea nitrogen test and submit the form', async () => {
await page.getByLabel(/lab reference number/i).fill(' 20240419-1234');
await page.getByLabel(/reference number/i).fill(' 20240419-1234');
await page.getByLabel(/additional instructions/i).fill(' N/A');
});

await test.step('Add I save the lab order form', async () => {
await test.step('And I save the lab order form', async () => {
await page.getByRole('button', { name: /save order/i }).click();
});

await test.step('And I click the `Sign and close` button', async () => {
await expect(page.getByRole('status', { name: /new/i })).toBeVisible();
await page.getByRole('button', { name: /sign and close/i }).click();
});

Expand All @@ -70,7 +74,6 @@ test.describe.serial('Running laboratory order tests sequentially', () => {

test('Modify a lab order', async ({ page }) => {
const ordersPage = new OrdersPage(page);
const orderBasket = page.locator('[data-extension-slot-name="order-basket-slot"]');

await test.step('When I visit the orders page', async () => {
await ordersPage.goTo(patient.uuid);
Expand Down Expand Up @@ -101,8 +104,8 @@ test.describe.serial('Running laboratory order tests sequentially', () => {
});

await test.step('Then the order status should be changed to `Modify`', async () => {
await expect(orderBasket.getByText(/new/i)).not.toBeVisible();
await expect(orderBasket.getByText(/modify/i)).toBeVisible();
await expect(page.getByRole('status', { name: /new/i })).not.toBeVisible();
await expect(page.getByRole('status', { name: /modify/i })).toBeVisible();
});

await test.step('When I click on the `Sign and close` button', async () => {
Expand All @@ -116,7 +119,6 @@ test.describe.serial('Running laboratory order tests sequentially', () => {

test('Discontinue a lab order', async ({ page }) => {
const ordersPage = new OrdersPage(page);
const orderBasket = page.locator('[data-extension-slot-name="order-basket-slot"]');

await test.step('When I visit the orders page', async () => {
await ordersPage.goTo(patient.uuid);
Expand All @@ -138,7 +140,7 @@ test.describe.serial('Running laboratory order tests sequentially', () => {
});

await test.step('Then the order status should be changed to `Discontinue`', async () => {
await expect(orderBasket.getByText(/discontinue/i)).toBeVisible();
await expect(page.getByRole('status', { name: /discontinue/i })).toBeVisible();
});

await test.step('And I click on the `Sign and close` button', async () => {
Expand All @@ -156,6 +158,6 @@ test.describe.serial('Running laboratory order tests sequentially', () => {
});

test.afterAll(async ({ api }) => {
await endVisit(api, visit.uuid);
await endVisit(api, visit);
await deletePatient(api, patient.uuid);
});
23 changes: 15 additions & 8 deletions e2e/specs/results-viewer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable playwright/no-nested-step */
import { expect } from '@playwright/test';
import { type Visit } from '@openmrs/esm-framework';
import { generateRandomPatient, type Patient, startVisit, endVisit, deletePatient } from '../commands';
import { test } from '../core';
import { ResultsViewerPage, VisitsPage } from '../pages';
import { ChartPage, ResultsViewerPage, VisitsPage } from '../pages';

let patient: Patient;
let visit: Visit;
Expand All @@ -13,6 +14,7 @@ test.beforeEach(async ({ api }) => {
});

test('Record and edit test results', async ({ page }) => {
const chartPage = new ChartPage(page);
const resultsViewerPage = new ResultsViewerPage(page);
const visitsPage = new VisitsPage(page);
const form = page.locator('[data-extension-slot-name="form-widget-slot"]');
Expand Down Expand Up @@ -209,12 +211,12 @@ test('Record and edit test results', async ({ page }) => {
},
];

await test.step('When I visit the results viewer page', async () => {
await resultsViewerPage.goTo(patient.uuid);
await test.step('When I visit the chart summary page', async () => {
await chartPage.goTo(patient.uuid);
});

await test.step('And I click on the `Clinical forms` button on the siderail', async () => {
await page.getByLabel(/clinical forms/i).click();
await test.step('And I click the `Clinical forms` button on the siderail', async () => {
await page.getByLabel(/clinical forms/i, { exact: true }).click();
});

await test.step('Then I should see the clinical forms workspace', async () => {
Expand All @@ -226,11 +228,15 @@ test('Record and edit test results', async ({ page }) => {
await expect(page.getByRole('cell', { name: /laboratory test results/i })).toBeVisible();
});

await test.step('When I launch the `Laboratory Test Results` form', async () => {
await test.step('When I click the `Laboratory Test Results` link to launch the form', async () => {
await page.getByText(/laboratory test results/i).click();
});

await test.step('And I fill the "Complete Blood Count" section', async () => {
await test.step('Then I should see the `Laboratory Test Results` form launch in the workspace', async () => {
await expect(page.getByText(/laboratory test results/i)).toBeVisible();
});

await test.step('When I fill the "Complete Blood Count" section', async () => {
for (const { label, value } of completeBloodCountData) {
await test.step(label, async () => {
await form.getByLabel(label, { exact: true }).fill(value);
Expand Down Expand Up @@ -276,6 +282,7 @@ test('Record and edit test results', async ({ page }) => {
});
}
});

for (const { resultsPageReference, value } of chemistryResultsData) {
await test.step(resultsPageReference, async () => {
const row = page.locator(`tr:has-text("${resultsPageReference}"):has(td:has-text("${value}"))`).first();
Expand Down Expand Up @@ -364,6 +371,6 @@ test('Record and edit test results', async ({ page }) => {
});

test.afterEach(async ({ api }) => {
await endVisit(api, visit.uuid);
await endVisit(api, visit);
await deletePatient(api, patient.uuid);
});
2 changes: 1 addition & 1 deletion e2e/specs/visit-note.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ test('Add and delete a visit note', async ({ page }) => {
});

test.afterEach(async ({ api }) => {
await endVisit(api, visit.uuid);
await endVisit(api, visit);
await deletePatient(api, patient.uuid);
});
2 changes: 1 addition & 1 deletion e2e/specs/vitals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ test('Record vital signs', async ({ page }) => {
});

test.afterEach(async ({ api }) => {
await endVisit(api, visit.uuid);
await endVisit(api, visit);
await deletePatient(api, patient.uuid);
});
4 changes: 2 additions & 2 deletions packages/esm-form-engine-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test:watch": "cross-env TZ=UTC jest --watch --config jest.config.js --color",
"coverage": "yarn test --coverage",
"typescript": "tsc",
"extract-translations": "i18next 'src/**/*.component.tsx' 'src/**/*.modal.tsx' 'src/index.ts' --config ../../tools/i18next-parser.config.js"
"extract-translations": "i18next 'src/**/*.component.tsx' 'src/**/*.modal.tsx' 'src/**/*.extension.tsx' 'src/**/*.workspace.tsx' 'src/**/*.hook.tsx' 'src/index.ts' --config ../../tools/i18next-parser.config.js"
},
"browserslist": [
"extends browserslist-config-openmrs"
Expand All @@ -43,7 +43,7 @@
"react-error-boundary": "^4.0.13"
},
"peerDependencies": {
"@openmrs/esm-framework": "5.x",
"@openmrs/esm-framework": "6.x",
"@openmrs/esm-patient-common-lib": "8.x",
"dayjs": "1.x",
"react": "18.x",
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-form-entry-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"zone.js": "~0.14.8"
},
"peerDependencies": {
"@openmrs/esm-framework": "5.x",
"@openmrs/esm-framework": "6.x",
"single-spa": "6.x"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/esm-form-entry-app/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"errorLoadingForm": "Erro ao carregar o formulário",
"errorWithForm": "Houve um erro com este formulário",
"fix": "Corrigir",
"formSubmissionFailed": "Ocorreu um erro ao enviar o formulário. Erro: {error}",
"formSubmissionFailed": "Ocorreu um erro ao enviar o formulário. Por favor informe ao Administrador do Sistema Erro: {error}",
"formSubmittedSuccessfully": "O formulário foi enviado com sucesso.",
"from": "De",
"futureDateRestriction": "Data futura não permitida!",
Expand Down Expand Up @@ -52,7 +52,7 @@
"patientIdentifierDuplicationDescription": "A identificação fornecida já está associada a um paciente existente. Por favor, verifique a identificação e tente novamente.",
"orderNumber": "Número do pedido",
"previous": "Anterior",
"previous21Years": "Anos anteriores 21",
"previous21Years": "21 anos anteriores",
"previousMonth": "Mês anterior",
"previousValue": "Valor anterior",
"previousYear": "Ano anterior",
Expand Down
Loading

0 comments on commit 12d5ba0

Please sign in to comment.