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

(test) fix failing tests because of new year #1424

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ env:
jobs:
main:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: 📥 Checkout repo
uses: actions/checkout@v4
Expand Down
14 changes: 9 additions & 5 deletions __mocks__/patient.mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { type Patient, type PersonAddress } from '@openmrs/esm-framework';
import type { Patient, PersonAddress } from '@openmrs/esm-framework';
import { mockAddress } from './address.mock';
import dayjs from 'dayjs';

const birthdate = '2000-01-01T00:00:00.000+0000';
const age = dayjs().diff(birthdate, 'years');

/* Patients as returned by `usePatient` and the service queues endpoints */
export const mockPatientAlice: Patient = {
Expand All @@ -10,8 +14,8 @@ export const mockPatientAlice: Patient = {
uuid: '00000000-0001-0000-0000-000000000000',
display: 'Alice Johnson',
gender: 'F',
age: 24,
birthdate: '2000-01-01T00:00:00.000+0000',
age: age,
birthdate: birthdate,
birthdateEstimated: false,
dead: false,
deathDate: null,
Expand Down Expand Up @@ -40,8 +44,8 @@ export const mockPatientBrian: Patient = {
uuid: '00000000-0001-0000-0000-000000000000',
display: 'Brian Johnson',
gender: 'M',
age: 24,
birthdate: '2000-01-01T00:00:00.000+0000',
age: age,
birthdate: birthdate,
birthdateEstimated: false,
dead: false,
deathDate: null,
Expand Down
8 changes: 5 additions & 3 deletions e2e/specs/register-new-patient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ test('Register an unknown patient', async ({ api, page }) => {
await page.getByRole('tab', { name: /no/i }).nth(1).click();
});

await test.step('And then I fill in 25 as the estimated age in years', async () => {
const estimatedAge = 25;
await test.step(`And then I fill in ${estimatedAge} as the estimated age in years`, async () => {
const estimatedAgeField = page.getByLabel(/estimated age in years/i);
await estimatedAgeField.clear();
await estimatedAgeField.fill('25');
await estimatedAgeField.fill('' + estimatedAge);
});

await test.step('And I click on the submit button', async () => {
Expand All @@ -123,12 +124,13 @@ test('Register an unknown patient', async ({ api, page }) => {

await test.step("And I should see the newly registered patient's details displayed in the patient banner", async () => {
const patientBanner = page.locator('header[aria-label="patient banner"]');
const expectedBirthYear = new Date().getFullYear() - estimatedAge;

await expect(patientBanner).toBeVisible();
await expect(patientBanner.getByText('Unknown Unknown')).toBeVisible();
await expect(patientBanner.getByText(/female/i)).toBeVisible();
await expect(patientBanner.getByText(/25 yrs/i)).toBeVisible();
await expect(patientBanner.getByText(/01-Jan-1999/i)).toBeVisible();
await expect(patientBanner.getByText(new RegExp(`01-Jan-${expectedBirthYear}`, 'i'))).toBeVisible();
await expect(patientBanner.getByText(/OpenMRS ID/i)).toBeVisible();
});
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/support/github/run-e2e-docker-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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')
apps=$(yarn workspaces list --json | jq -r 'if .location | test("-app$") then .name else empty end')
# this array will hold all of the packed app names
app_names=()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import dayjs from 'dayjs';
import { render, screen } from '@testing-library/react';
import { getDefaultsFromConfigSchema, restBaseUrl, useConfig } from '@openmrs/esm-framework';
import { type SearchedPatient } from '../types';
Expand All @@ -8,6 +9,8 @@ import CompactPatientBanner from './compact-patient-banner.component';

const mockUseConfig = jest.mocked(useConfig<PatientSearchConfig>);

const birthdate = '1990-01-01T00:00:00.000+0000';
const age = dayjs().diff(birthdate, 'years');
const patients: Array<SearchedPatient> = [
{
attributes: [],
Expand Down Expand Up @@ -35,9 +38,9 @@ const patients: Array<SearchedPatient> = [
},
],
person: {
age: 34,
age,
addresses: [],
birthdate: '1990-01-01',
birthdate,
dead: false,
deathDate: null,
gender: 'M',
Expand All @@ -63,7 +66,7 @@ describe('CompactPatientBanner', () => {
);

expect(
screen.getByRole('link', { name: /Smith, John Doe Male · 34 yrs · OpenMRS ID 1000NLY/i }),
screen.getByRole('link', { name: new RegExp(`Smith, John Doe Male · ${age} yrs · OpenMRS ID 1000NLY`, 'i') }),
).toBeInTheDocument();
expect(screen.getByRole('link')).toHaveAttribute('href', `/openmrs/spa/patient/${patients[0].uuid}/chart/`);
expect(screen.getByRole('img')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import dayjs from 'dayjs';
import { render, screen } from '@testing-library/react';
import { getDefaultsFromConfigSchema, restBaseUrl, useConfig } from '@openmrs/esm-framework';
import { PatientSearchContext } from '../patient-search-context';
Expand Down Expand Up @@ -62,6 +63,8 @@ describe('PatientSearch', () => {
});

it('renders a list of recently searched patients', () => {
const birthdate = '1990-01-01T00:00:00.000+0000';
const age = dayjs().diff(birthdate, 'years');
const mockSearchResults: Array<SearchedPatient> = [
{
attributes: [],
Expand Down Expand Up @@ -89,9 +92,9 @@ describe('PatientSearch', () => {
},
],
person: {
age: 34,
age: age,
addresses: [],
birthdate: '1990-01-01',
birthdate: birthdate,
dead: false,
deathDate: null,
gender: 'M',
Expand All @@ -114,7 +117,7 @@ describe('PatientSearch', () => {
});

expect(
screen.getByRole('link', { name: /Smith, John Doe Male · 34 yrs · OpenMRS ID 1000NLY/i }),
screen.getByRole('link', { name: new RegExp(`Smith, John Doe Male · ${age} yrs · OpenMRS ID 1000NLY`, 'i') }),
).toBeInTheDocument();
expect(screen.getByRole('link')).toHaveAttribute(
'href',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import dayjs from 'dayjs';
import { render, screen } from '@testing-library/react';
import { getDefaultsFromConfigSchema, restBaseUrl, useConfig } from '@openmrs/esm-framework';
import { type SearchedPatient } from '../types';
Expand All @@ -20,6 +21,8 @@ const defaultProps = {
const mockUseConfig = jest.mocked(useConfig<PatientSearchConfig>);

describe('RecentlySearchedPatients', () => {
const birthdate = '1990-01-01T00:00:00.000+0000';
const age = dayjs().diff(birthdate, 'years');
const mockSearchResults: Array<SearchedPatient> = [
{
attributes: [],
Expand Down Expand Up @@ -47,9 +50,9 @@ describe('RecentlySearchedPatients', () => {
},
],
person: {
age: 34,
age,
addresses: [],
birthdate: '1990-01-01',
birthdate,
dead: false,
deathDate: null,
gender: 'M',
Expand Down Expand Up @@ -114,7 +117,7 @@ describe('RecentlySearchedPatients', () => {
});

expect(
screen.getByRole('link', { name: /Smith, John Doe Male · 34 yrs · OpenMRS ID 1000NLY/i }),
screen.getByRole('link', { name: new RegExp(`Smith, John Doe Male · ${age} yrs · OpenMRS ID 1000NLY`, 'i') }),
).toBeInTheDocument();
expect(screen.getByRole('link')).toHaveAttribute(
'href',
Expand Down
Loading