Skip to content

Commit

Permalink
(fix) Additional fixes supporting #1338
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen committed Oct 22, 2024
1 parent 9a5d067 commit 686e3b8
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@
align-items: center;
}

.arrowRightIcon {
fill: currentColor !important;
}

.configureIdentifiersButton {
display: flex;
align-items: center;
margin: 0 0 layout.$spacing-05 layout.$spacing-05;

svg {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const Identifiers: React.FC = () => {
className={styles.configureIdentifiersButton}
onClick={() => setShowIdentifierOverlay(true)}
size={isDesktop(layout) ? 'sm' : 'md'}>
{t('configure', 'Configure')} <ArrowRight size={16} />
{t('configure', 'Configure')} <ArrowRight className={styles.arrowRightIcon} size={16} />
</Button>
</div>
</UserHasAccess>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework';
import React from 'react';
import { Form, Formik } from 'formik';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Form, Formik } from 'formik';
import React from 'react';
import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework';
import { type AddressTemplate, type IdentifierSource } from '../../patient-registration.types';
import { mockIdentifierTypes, mockOpenmrsId, mockPatient, mockSession } from '__mocks__';
import { esmPatientRegistrationSchema, type RegistrationConfig } from '../../../config-schema';
import { ResourcesContext, type Resources } from '../../../offline.resources';
import { PatientRegistrationContext, type PatientRegistrationContextProps } from '../../patient-registration-context';
import { type IdentifierSource } from '../../patient-registration.types';
import { Identifiers, setIdentifierSource } from './id-field.component';

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

const mockResourcesContextValue = {
addressTemplate: null,
addressTemplate: null as unknown as AddressTemplate,
currentSession: mockSession.data,
identifierTypes: [],
relationshipTypes: [],
Expand Down Expand Up @@ -53,7 +53,7 @@ const mockContextValues: PatientRegistrationContextProps = {
setInitialFormValues: jest.fn(),
validationSchema: null,
values: mockInitialFormValues,
};
} as unknown as PatientRegistrationContextProps;

describe('Identifiers', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('FormManager', () => {
},
]);
});

it('should generate identifier if it has autoGeneration and manual entry disabled', async () => {
formValues.identifiers.foo.autoGeneration = true;
formValues.identifiers.foo.selectedSource.autoGenerationOption.manualEntryEnabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export class FormManager {
: await (
await generateIdentifier(selectedSource.uuid)
).data.identifier;

const identifierToCreate = {
uuid: identifierUuid,
identifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const IdentifierInput: React.FC<IdentifierInputProps> = ({ patientIdentifier, fi
)}
</div>
)}
<div style={{ marginBottom: '1rem' }}>
<div className={styles.actionButtonContainer}>
{showEditButton && (
<UserHasAccess privilege="Edit Patient Identifiers">
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
PatientRegistrationContext,
type PatientRegistrationContextProps,
} from '../../../patient-registration-context';
import type { AddressTemplate, FormValues, PatientIdentifierValue } from '../../../patient-registration.types';
import type {
AddressTemplate,
FormValues,
IdentifierSource,
PatientIdentifierValue,
} from '../../../patient-registration.types';
import IdentifierInput from './identifier-input.component';
import userEvent from '@testing-library/user-event';

Expand Down Expand Up @@ -79,11 +84,11 @@ describe('identifier input', () => {
manualEntryEnabled: false,
automaticGenerationEnabled: true,
},
},
} as IdentifierSource,
autoGeneration: false,
preferred: true,
required: true,
};
} as PatientIdentifierValue;

const setupIdentifierInput = (patientIdentifier: PatientIdentifierValue, initialValues = {}) => {
render(
Expand All @@ -101,7 +106,7 @@ describe('identifier input', () => {

it('shows the identifier input', () => {
openmrsID.autoGeneration = false;
setupIdentifierInput(openmrsID);
setupIdentifierInput(openmrsID as PatientIdentifierValue);
expect(screen.getByLabelText(openmrsID.identifierName)).toBeInTheDocument();
});

Expand All @@ -112,7 +117,7 @@ describe('identifier input', () => {
openmrsID.initialValue = '1002UU9';
openmrsID.identifierValue = '1002UU9';
// replay
setupIdentifierInput(openmrsID);
setupIdentifierInput(openmrsID as PatientIdentifierValue);
expect(screen.getByText('Edit')).toBeInTheDocument();
});

Expand All @@ -139,7 +144,7 @@ describe('identifier input', () => {
it('hides the input when the identifier is auto-generated', () => {
openmrsID.autoGeneration = true;
setupIdentifierInput(openmrsID);
expect(screen.getByTestId('identifier-input').type).toBe('hidden');
expect(screen.getByTestId('identifier-input')).toHaveAttribute('type', 'hidden');
});

it("displays 'Auto-Generated' when the indentifier has auto generation", () => {
Expand All @@ -154,7 +159,7 @@ describe('identifier input', () => {
autoGenerationOption: {
manualEntryEnabled: true,
},
};
} as IdentifierSource;

it('shows the edit button', () => {
openmrsID.autoGeneration = true;
Expand All @@ -171,11 +176,11 @@ describe('identifier input', () => {
autoGenerationOption: {
manualEntryEnabled: true,
},
};
} as IdentifierSource;
setupIdentifierInput(openmrsID);
const editButton = screen.getByTestId('edit-button');
await user.click(editButton);
expect(screen.getByLabelText(new RegExp(`${openmrsID.identifierName}`)).value).toBe('');
expect(screen.getByLabelText(new RegExp(`${openmrsID.identifierName}`))).toHaveValue('');
});

it('displays an input field with the identifier value if it exists', async () => {
Expand All @@ -186,11 +191,11 @@ describe('identifier input', () => {
autoGenerationOption: {
manualEntryEnabled: true,
},
};
} as IdentifierSource;
setupIdentifierInput(openmrsID, { identifiers: { [fieldName]: { identifierValue: '10001V' } } });
const editButton = screen.getByTestId('edit-button');
await user.click(editButton);
expect(screen.getByLabelText(new RegExp(`${openmrsID.identifierName}`)).value).toBe('10001V');
expect(screen.getByLabelText(new RegExp(`${openmrsID.identifierName}`))).toHaveValue('10001V');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,8 @@
margin: 0;
padding-left: layout.$spacing-05;
}

.actionButtonContainer {
margin-left: layout.$spacing-05;
margin-bottom: layout.$spacing-05;
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const MotherChildBedShareDivider = () => {
return (
<div className={maternalWardPatientCardStyles.motherChildBedDivider}>
<div className={maternalWardPatientCardStyles.motherChildBedDividerLine}></div>
<Tag type="purple">{t('motherChildbedShare', 'Mother / Child')}</Tag>
<Tag type="purple">{t('motherChildBedShare', 'Mother / Child')}</Tag>
<div className={maternalWardPatientCardStyles.motherChildBedDividerLine}></div>
</div>
);
Expand Down
9 changes: 8 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@
"^typescript"
]
},
"test": {},
"test": {
"dependsOn": [
"^test"
]
},
"test:watch": {
"dependsOn": [
"^test:watch"
],
"cache": false,
"persistent": true
}
Expand Down

0 comments on commit 686e3b8

Please sign in to comment.