Skip to content

Commit

Permalink
Merge branch 'main' into (fix)O3-2197
Browse files Browse the repository at this point in the history
  • Loading branch information
jayasanka-sack authored Aug 8, 2023
2 parents fae03ae + 4c9aca4 commit bb49cf2
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 127 deletions.
45 changes: 27 additions & 18 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ jobs:
testOnPR:
if: ${{ github.event_name == 'pull_request' }}
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
sed -i 's/8080/8180/g' .env
run: cp example.env .env

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

- name: Cache dependencies
id: cache
Expand All @@ -40,12 +39,22 @@ jobs:
- 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: yarn start --sources 'packages/esm-*-app/' --port 8180 & # Refer to O3-1994
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()
Expand All @@ -56,21 +65,19 @@ jobs:

testOnPush:
if: ${{ github.event_name == 'push' }}
timeout-minutes: 60
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
sed -i 's/8080/8180/g' .env
run: cp example.env .env

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

- name: Cache dependencies
id: cache
Expand All @@ -86,20 +93,22 @@ jobs:
- name: Install Playwright Browsers
run: npx playwright install chromium --with-deps

- name: Run db and web containers
run: |
cd e2e/support/github
docker-compose up -d
- name: Wait for OpenMRS instance to start
run: while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:9000/openmrs/login.htm)" != "200" ]]; do sleep 10; done
- name: Build apps
run: yarn turbo run build --color --concurrency=5

- name: Run dev server
run: yarn start --sources 'packages/esm-*-app/' --backend "http://localhost:9000" --port 8180 & # Refer to O3-1994
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()
Expand Down
4 changes: 2 additions & 2 deletions e2e/commands/patient-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export const generateRandomPatient = async (api: APIRequestContext): Promise<Pat
},
],
attributes: [],
birthdate: '2020-2-1',
birthdateEstimated: true,
birthdate: '2020-02-01',
birthdateEstimated: false,
dead: false,
gender: 'M',
names: [
Expand Down
6 changes: 5 additions & 1 deletion e2e/pages/registration-and-edit-page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Locator, Page } from '@playwright/test';
import { Locator, Page, expect } from '@playwright/test';

export type PatientRegistrationSex = 'male' | 'female' | 'other' | 'unknown';

Expand Down Expand Up @@ -40,6 +40,10 @@ export class RegistrationAndEditPage {
await this.page.goto(editPatientUuid ? `patient/${editPatientUuid}/edit` : 'patient-registration');
}

async waitUntilTheFormIsLoaded() {
await expect(this.createPatientButton()).toBeEnabled();
}

async fillPatientRegistrationForm(formValues: PatientRegistrationFormValues) {
const tryFill = (locator: Locator, value?: string) => value && locator.fill(value);
formValues.sex && (await this.sexRadioButton(formValues.sex).check());
Expand Down
1 change: 1 addition & 0 deletions e2e/specs/edit-patient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ test('Edit a patient', async ({ page, api }) => {

await test.step("When I visit the registration page to a patient's details", async () => {
await patientEditPage.goto(patient.uuid);
await patientEditPage.waitUntilTheFormIsLoaded();
});

await test.step('And then I click on fill new values into the registration form and then click the `Submit` button', async () => {
Expand Down
1 change: 1 addition & 0 deletions e2e/specs/register-new-patient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test('Register a new patient', async ({ page, api }) => {

await test.step('When I visit the registration page', async () => {
await patientRegistrationPage.goto();
await patientRegistrationPage.waitUntilTheFormIsLoaded();
});

await test.step('And then I click on fill new values into the registration form and then click the `Submit` button', async () => {
Expand Down
34 changes: 34 additions & 0 deletions e2e/support/github/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# syntax=docker/dockerfile:1.3
FROM --platform=$BUILDPLATFORM node:18-alpine as dev

ARG APP_SHELL_VERSION=next

RUN mkdir -p /app
WORKDIR /app

COPY . .

RUN npm_config_legacy_peer_deps=true npm install -g openmrs@${APP_SHELL_VERSION:-next}
ARG CACHE_BUST
RUN npm_config_legacy_peer_deps=true openmrs assemble --manifest --mode config --config spa-assemble-config.json --target ./spa

FROM --platform=$BUILDPLATFORM openmrs/openmrs-reference-application-3-frontend:nightly as frontend
FROM nginx:1.23-alpine

RUN apk update && \
apk upgrade && \
# add more utils for sponge to support our startup script
apk add --no-cache moreutils

# clear any default files installed by nginx
RUN rm -rf /usr/share/nginx/html/*

COPY --from=frontend /etc/nginx/nginx.conf /etc/nginx/nginx.conf
# this assumes that NOTHING in the framework is in a subdirectory
COPY --from=frontend /usr/share/nginx/html/* /usr/share/nginx/html/
COPY --from=frontend /usr/local/bin/startup.sh /usr/local/bin/startup.sh
RUN chmod +x /usr/local/bin/startup.sh

COPY --from=dev /app/spa/ /usr/share/nginx/html/

CMD ["/usr/local/bin/startup.sh"]
14 changes: 12 additions & 2 deletions e2e/support/github/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
version: "3.7"

services:
gateway:
image: openmrs/openmrs-reference-application-3-gateway:${TAG:-nightly}
ports:
- "8080:80"

frontend:
build:
context: .
environment:
SPA_PATH: /openmrs/spa
API_URL: /openmrs

backend:
image: openmrs/openmrs-reference-application-3-backend:${TAG:-nightly}
depends_on:
Expand All @@ -19,8 +31,6 @@ services:
timeout: 5s
volumes:
- openmrs-data:/openmrs/data
ports:
- 9000:8080

# MariaDB
db:
Expand Down
49 changes: 49 additions & 0 deletions e2e/support/github/run-e2e-docker-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash -eu

# get the dir containing the script
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# create a temporary working directory
working_dir=$(mktemp -d "${TMPDIR:-/tmp/}openmrs-e2e-frontends.XXXXXXXXXX")
# get a list of all the apps in this workspace
apps=$(yarn workspaces list --json | jq -r 'if ((.location == ".") or (.location | test("-app") | not)) then halt else .name end')
# this array will hold all of the packed app names
app_names=()

echo "Creating packed archives of apps..."
# for each app
for app in $apps
do
# @openmrs/esm-whatever -> _openmrs_esm_whatever
app_name=$(echo "$app" | tr '[:punct:]' '_');
# add to our array
app_names+=("$app_name.tgz");
# run yarn pack for our app and add it to the working directory
yarn workspace "$app" pack -o "$working_dir/$app_name.tgz" >/dev/null;
done;
echo "Created packed app archives"

echo "Creating dynamic spa-assemble-config.json..."
# dynamically assemble our list of frontend modules, prepending the login app and
# primary navigation apps; apps will all be in the /app directory of the Docker
# container
jq -n \
--arg apps "$apps" \
--arg app_names "$(echo ${app_names[@]})" \
'{"@openmrs/esm-primary-navigation-app": "next", "@openmrs/esm-home-app": "next", "@openmrs/esm-patient-chart-app": "next"} + (
($apps | split("\n")) as $apps | ($app_names | split(" ") | map("/app/" + .)) as $app_files
| [$apps, $app_files]
| transpose
| map({"key": .[0], "value": .[1]})
| from_entries
)' | jq '{"frontendModules": .}' > "$working_dir/spa-assemble-config.json"
echo "Created dynamic spa-assemble-config.json"

echo "Copying Docker configuration..."
cp "$script_dir/Dockerfile" "$working_dir/Dockerfile"
cp "$script_dir/docker-compose.yml" "$working_dir/docker-compose.yml"

cd $working_dir
echo "Starting Docker containers..."
# CACHE_BUST to ensure the assemble step is always run
docker compose build --build-arg CACHE_BUST=$(date +%s) frontend
docker compose up -d
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import EncounterObservations from './encounter-observations.component';

describe('EncounterObservations', () => {
test('renders skeleton text while loading', () => {
render(<EncounterObservations observations={null} />);

expect(screen.queryByText('Temperature')).not.toBeInTheDocument();
});

test('renders "No observations found" message when observations list is empty', () => {
const emptyObservations = [];
render(<EncounterObservations observations={emptyObservations} />);

expect(screen.getByText('No observations found')).toBeInTheDocument();
});

test('renders observations list correctly', () => {
const observations = [
{ display: 'Temperature: 98.6°F' },
{ display: 'Blood Pressure: 120/80 mmHg' },
{ display: 'Heart Rate: 72 bpm' },
];
render(<EncounterObservations observations={observations} />);

expect(screen.getByText('Temperature:')).toBeInTheDocument();
expect(screen.getByText('98.6°F')).toBeInTheDocument();

expect(screen.getByText('Blood Pressure:')).toBeInTheDocument();
expect(screen.getByText('120/80 mmHg')).toBeInTheDocument();

expect(screen.getByText('Heart Rate:')).toBeInTheDocument();
expect(screen.getByText('72 bpm')).toBeInTheDocument();
});
});
Loading

0 comments on commit bb49cf2

Please sign in to comment.