Skip to content

Commit

Permalink
Merge branch 'main' into photo
Browse files Browse the repository at this point in the history
  • Loading branch information
Jexsie authored Sep 24, 2023
2 parents 1d93476 + be46742 commit d1325c7
Show file tree
Hide file tree
Showing 278 changed files with 5,100 additions and 1,118 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/docker/docker-compose.yml

This file was deleted.

57 changes: 1 addition & 56 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ on:
- main

jobs:
testOnPR:
if: ${{ github.event_name == 'pull_request' }}
main:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
Expand Down Expand Up @@ -62,57 +61,3 @@ jobs:
name: playwright-report
path: playwright-report/
retention-days: 30

testOnPush:
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Copy test environment variables
run: cp example.env .env

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Install Playwright Browsers
run: npx playwright install chromium --with-deps

- name: Build apps
run: yarn turbo run build --color --concurrency=5

- name: Run dev server
run: bash e2e/support/github/run-e2e-docker-env.sh

- name: Wait for OpenMRS instance to start
run: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:8080/openmrs/login.htm)" != "200" ]]; do sleep 10; done

- name: Run E2E tests
run: yarn playwright test

- name: Stop dev server
if: "!cancelled()"
run: docker stop $(docker ps -a -q)

- name: Upload report
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This repository contains frontend modules for the OpenMRS SPA. These modules rel

- [Active visits app](packages/esm-active-visits-app/)
- [Appointments app](packages/esm-appointments-app/)
- [Outpatient app](packages/esm-outpatient-app/README.md)
- [Service queues](packages/esm-service-queues-app/README.md)
- [Patient search](packages/esm-patient-search-app)
- [Patient registration](packages/esm-patient-registration-app)
- [Patient list](packages/esm-patient-list-app)
Expand Down Expand Up @@ -71,6 +71,50 @@ Please read our [contributing](http://o3-dev.docs.openmrs.org/#/getting_started/

## Running tests

To run tests for all packages, run:

```bash
yarn turbo test
```

To run tests in `watch` mode, run:

```bash
yarn turbo test:watch
```

To run tests for a specific package, pass the package name to the `--filter` flag. For example, to run tests for `esm-patient-conditions-app`, run:

```bash
yarn turbo test --filter="esm-patient-conditions-app"
```

To run a specific test file, run:

```bash
yarn turbo test -- basic-search
```

The above command will only run tests in the file or files that match the provided string.

You can also run the matching tests from above in watch mode by running:

```bash
yarn turbo test:watch --basic-search
```

To generate a `coverage` report, run:

```bash
yarn turbo coverage
```

By default, `turbo` will cache test runs. This means that re-running tests wihout changing any of the related files will return the cached logs from the last run. To bypass the cache, run tests with the `force` flag, as follows:

```bash
yarn turbo test --force
```

### Unit tests
To run unit tests, use:

Expand Down
33 changes: 4 additions & 29 deletions e2e/support/github/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# This docker compose file is used to create a backend environment for the e2e.yml workflow.
# This docker compose file is used to create a backend environment for the e2e.yml workflow.
# The images are pre-filled with data so that the backend environment can be started within a short time.
version: "3.7"

services:
Expand All @@ -15,35 +16,9 @@ services:
API_URL: /openmrs

backend:
image: openmrs/openmrs-reference-application-3-backend:${TAG:-nightly}
image: openmrs/openmrs-reference-application-3-backend:nightly-with-data
depends_on:
- db
environment:
OMRS_CONFIG_MODULE_WEB_ADMIN: "true"
OMRS_CONFIG_AUTO_UPDATE_DATABASE: "true"
OMRS_CONFIG_CREATE_TABLES: "true"
OMRS_CONFIG_CONNECTION_SERVER: db
OMRS_CONFIG_CONNECTION_DATABASE: openmrs
OMRS_CONFIG_CONNECTION_USERNAME: ${OPENMRS_DB_USER:-openmrs}
OMRS_CONFIG_CONNECTION_PASSWORD: ${OPENMRS_DB_PASSWORD:-openmrs}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/openmrs"]
timeout: 5s
volumes:
- openmrs-data:/openmrs/data

# MariaDB
db:
image: mariadb:10.8.2
command: "mysqld --character-set-server=utf8 --collation-server=utf8_general_ci"
environment:
MYSQL_DATABASE: openmrs
MYSQL_USER: ${OPENMRS_DB_USER:-openmrs}
MYSQL_PASSWORD: ${OPENMRS_DB_PASSWORD:-openmrs}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-openmrs}
volumes:
- db-data:/var/lib/mysql

volumes:
openmrs-data: ~
db-data: ~
image: openmrs/openmrs-reference-application-3-db:nightly-with-data
4 changes: 2 additions & 2 deletions packages/esm-active-visits-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"build": "webpack --mode production",
"analyze": "webpack --mode=production --env.analyze=true",
"lint": "cross-env TIMING=1 eslint src --ext ts,tsx",
"test": "cross-env TZ=UTC jest --config jest.config.js --verbose false --passWithNoTests",
"test:watch": "cross-env TZ=UTC jest --watch --config jest.config.js",
"test": "cross-env TZ=UTC jest --config jest.config.js --verbose false --passWithNoTests --color",
"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'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,21 @@ const ActiveVisitsTable = () => {
{rows.map((row, index) => {
const visit = activeVisits.find((visit) => visit.id === row.id);

if (!visit) {
return null;
}

const patientLink = `$\{openmrsSpaBase}/patient/${visit.patientUuid}/chart/Patient%20Summary`;

return (
<React.Fragment key={index}>
<TableExpandRow {...getRowProps({ row })} data-testid={`activeVisitRow${visit.patientUuid}`}>
<TableExpandRow
{...getRowProps({ row })}
data-testid={`activeVisitRow${visit.patientUuid || 'unknown'}`}>
{row.cells.map((cell) => (
<TableCell key={cell.id} data-testid={cell.id}>
{cell.info.header === 'name' ? (
<PatientNameLink
from={fromPage}
to={`\${openmrsSpaBase}/patient/${visit.patientUuid}/chart/Patient%20Summary`}>
{cell.info.header === 'name' && visit.patientUuid ? (
<PatientNameLink from={fromPage} to={patientLink}>
{cell.value}
</PatientNameLink>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
.tabletHeading {
text-align: left;
text-transform: capitalize;
margin-bottom: spacing.$spacing-05;

h4 {
@include type.type-style('heading-compact-02');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import React from 'react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import ActiveVisitsTable from './active-visits.component';
import { useConfig, usePagination } from '@openmrs/esm-framework';
import { useActiveVisits } from './active-visits.resource';

const mockedUsePagination = usePagination as jest.Mock;
const mockActiveVisits = useActiveVisits as jest.Mock;

const mockActiveVisitsData = [{ id: '1', name: 'John Doe', visitType: 'Checkup', patientUuid: 'uuid1' }];
jest.mock('./active-visits.resource', () => ({
...jest.requireActual('./active-visits.resource'),
useActiveVisits: jest.fn(() => ({
activeVisits: mockActiveVisitsData,
isLoading: false,
isValidating: false,
error: null,
})),
}));

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
useConfig: jest.fn(() => ({ activeVisits: { pageSizes: [10, 20, 30, 40, 50], pageSize: 10 } })),
usePagination: jest.fn().mockImplementation((data) => ({
currentPage: 1,
goTo: () => {},
results: data,
paginated: false,
})),
}));

describe('ActiveVisitsTable', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('renders data table with active visits', () => {
render(<ActiveVisitsTable />);

expect(screen.getByText('Visit Time')).toBeInTheDocument();
expect(screen.getByText('ID Number')).toBeInTheDocument();
const expectedColumnHeaders = [/Visit Time/, /ID Number/, /Name/, /Gender/, /Age/, /Visit Type/];
expectedColumnHeaders.forEach((header) => {
expect(screen.getByRole('columnheader', { name: new RegExp(header, 'i') })).toBeInTheDocument();
});

const patientNameLink = screen.getByText('John Doe');
expect(patientNameLink).toBeInTheDocument();
expect(patientNameLink.tagName).toBe('A');
});

it.skip('filters active visits based on search input', () => {
mockActiveVisits.mockImplementationOnce(() => ({
activeVisits: [
{ id: '1', name: 'John Doe', visitType: 'Checkup', patientUuid: 'uuid1' },
{ id: '2', name: 'Some One', visitType: 'Checkup', patientUuid: 'uuid2' },
],
isLoading: false,
isValidating: false,
error: null,
}));
render(<ActiveVisitsTable />);

const searchInput = screen.getByPlaceholderText('Filter table');
fireEvent.change(searchInput, { target: { value: 'John' } });

expect(screen.getByText('John Doe')).toBeInTheDocument();
expect(screen.queryByText('Some One')).toBeNull();
});

it('displays empty state when there are no active visits', () => {
mockActiveVisits.mockImplementationOnce(() => ({
activeVisits: [],
isLoading: false,
isValidating: false,
error: null,
}));

render(<ActiveVisitsTable />);

expect(screen.getByText('There are no active visits to display for this location.')).toBeInTheDocument();
});

it('should not display the table when the data is loading', () => {
mockActiveVisits.mockImplementationOnce(() => ({
activeVisits: undefined,
isLoading: true,
isValidating: false,
error: null,
}));

render(<ActiveVisitsTable />);

const expectedColumnHeaders = [/Visit Time/, /ID Number/, /Name/, /Gender/, /Age/, /Visit Type/];
expectedColumnHeaders.forEach((header) => {
expect(screen.queryByRole('columnheader', { name: new RegExp(header, 'i') })).not.toBeInTheDocument();
});
});

it('should display the Error when there is error', () => {
mockActiveVisits.mockImplementationOnce(() => ({
activeVisits: undefined,
isLoading: false,
isValidating: false,
error: 'Error in fetching data',
}));

render(<ActiveVisitsTable />);

const expectedColumnHeaders = [/Visit Time/, /ID Number/, /Name/, /Gender/, /Age/, /Visit Type/];
expectedColumnHeaders.forEach((header) => {
expect(screen.queryByRole('columnheader', { name: new RegExp(header, 'i') })).toBeInTheDocument();
});
});

it('should display the pagination when pagination is true', () => {
mockActiveVisits.mockImplementationOnce(() => ({
activeVisits: [
{ id: '1', name: 'John Doe', visitType: 'Checkup' },
{ id: '2', name: 'Some One', visitType: 'Checkup' },
],
isLoading: false,
isValidating: false,
error: null,
}));
mockedUsePagination.mockImplementationOnce((data) => ({
currentPage: 1,
goTo: () => {},
results: data,
paginated: true,
}));
render(<ActiveVisitsTable />);

expect(screen.getByText(/Next Page/i)).toBeInTheDocument();
});
});
Loading

0 comments on commit d1325c7

Please sign in to comment.