Skip to content

Commit

Permalink
(test) fix failing tests because of new year
Browse files Browse the repository at this point in the history
  • Loading branch information
chibongho committed Jan 2, 2025
1 parent 1689ede commit 3df6812
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { type SearchedPatient } from '../types';
import { configSchema, type PatientSearchConfig } from '../config-schema';
import { PatientSearchContext } from '../patient-search-context';
import CompactPatientBanner from './compact-patient-banner.component';
import dayjs from 'dayjs';

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
Expand Up @@ -5,6 +5,7 @@ import { PatientSearchContext } from '../patient-search-context';
import { configSchema } from '../config-schema';
import { type SearchedPatient } from '../types';
import PatientSearch from './patient-search.component';
import dayjs from 'dayjs';

const defaultProps = {
currentPage: 0,
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
Expand Up @@ -5,6 +5,7 @@ import { type SearchedPatient } from '../types';
import { PatientSearchContext } from '../patient-search-context';
import { configSchema, type PatientSearchConfig } from '../config-schema';
import RecentlySearchedPatients from './recently-searched-patients.component';
import dayjs from 'dayjs';

const defaultProps = {
currentPage: 0,
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

0 comments on commit 3df6812

Please sign in to comment.