Skip to content

test(e2e): Add medication tests#9152

Open
sepidehdehghani992 wants to merge 1 commit intomainfrom
test/add-test-medication
Open

test(e2e): Add medication tests#9152
sepidehdehghani992 wants to merge 1 commit intomainfrom
test/add-test-medication

Conversation

@sepidehdehghani992
Copy link
Copy Markdown
Contributor

@sepidehdehghani992 sepidehdehghani992 commented Feb 11, 2026

Changes

15 basic medication tests

Deploys

  • Deploy to Tamanu Internal

Tests

  • Run E2E Tests

Remember to...

  • ...write or update tests
  • ...add UI screenshots and testing notes to the Linear issue
  • ...add any manual upgrade steps to the Linear issue
  • ...update the config reference, settings reference, or any relevant runbook(s)
  • ...call out additions or changes to config files for the deployment team to take note of

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @sepidehdehghani992, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the E2E test coverage for medication-related functionalities. It introduces new page objects for medication requests and prescription modals, centralizing element locators and interaction logic. This foundational work enables the addition of a comprehensive set of tests that validate various aspects of medication prescription and display within the application, ensuring a more robust and reliable user experience.

Highlights

  • New Page Object: MedicationRequestsPage: A new Playwright page object has been implemented for the Medication Requests page, including locators for key elements and a dedicated method to wait for the page to load, improving test reliability and maintainability.
  • New Page Object: NewPrescriptionModal: A comprehensive Playwright page object has been added for the New Prescription modal, encapsulating all form fields, checkboxes, select elements, and action buttons, along with methods for interacting with them and handling modal lifecycle.
  • EncounterMedicationPane Enhancements: The EncounterMedicationPane page object has been updated to integrate the new NewPrescriptionModal, add locators for medication table rows, and include a robust method to open the prescription modal, which intelligently handles an intermediate 'Prescription Type' modal if present.
  • Medication Requests E2E Tests: Initial end-to-end tests have been added for the active medication requests page, verifying successful navigation and the visibility of the search section.
  • Comprehensive Prescription E2E Tests: A suite of detailed E2E tests has been introduced for creating prescriptions within patient encounters, covering scenarios such as filling required fields, filling all fields, validating incomplete forms, cancelling creation, prescribing multiple medications, and verifying table headers and prescriber information.
  • Patient Medication Tab E2E Tests: Existing patient medication tab tests have been expanded to include verification of navigation, table header display, and the functionality of opening the new prescription modal.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/e2e-tests/pages/medication/MedicationRequestsPage.ts
    • Added Playwright Locator properties for page container, content pane, search title, and page heading.
    • Implemented a waitForPageToLoad method to ensure the page is fully visible and network idle.
    • Updated the constructor to initialize locators using getByTestId and set the base URL for the page.
  • packages/e2e-tests/pages/patients/MedicationsPage/modals/NewPrescriptionModal.ts
    • Created a new page object NewPrescriptionModal to represent the medication prescription modal.
    • Defined numerous Locator properties for all interactive elements within the modal, including input fields, checkboxes, select dropdowns, and action buttons.
    • Added methods for modal lifecycle management (waitForModalToLoad, waitForModalToClose).
    • Implemented helper methods for selecting options in autocomplete and standard select fields (selectMedication, selectFrequency, selectUnits, selectRoute).
    • Provided methods for filling various input fields (fillDoseAmount, fillIndication, fillNotes, fillDuration, fillDischargeQuantity).
    • Included convenience methods fillRequiredFields and fillAndFinalise for common test flows.
  • packages/e2e-tests/pages/patients/MedicationsPage/panes/EncounterMedicationPane.ts
    • Imported the new NewPrescriptionModal page object.
    • Added a medicationRows Locator to target rows within the medication table.
    • Introduced a private instance of NewPrescriptionModal for lazy initialization.
    • Added waitForMedicationRowsToEqual to wait for a specific number of medication rows to appear.
    • Implemented getNewPrescriptionModal to retrieve or create the modal page object instance.
    • Added openNewPrescriptionModal to click the 'New prescription' button and handle the conditional appearance of a 'Prescription Type' modal before opening the main prescription modal.
  • packages/e2e-tests/tests/medication/medication.spec.ts
    • Refactored the test suite description to 'Medication Requests'.
    • Added a test to verify successful navigation to the active medication requests page.
    • Added a test to confirm the visibility of the search section and its title on the medication requests page.
  • packages/e2e-tests/tests/patients/history/encounter/medication.spec.ts
    • Renamed the test suite to 'Encounter Medication Tests'.
    • Implemented a beforeEach hook to set up a new patient and navigate to the medication tab for each test.
    • Added tests to verify the display of an empty medication table for new encounters.
    • Included tests for prescribing a medication using only required fields and verifying its appearance.
    • Added a test for prescribing a medication with all available fields.
    • Developed a test to ensure that prescription creation is prevented without filling required fields.
    • Created a test to confirm that cancelling prescription creation correctly closes the modal and leaves no medication entry.
    • Added a test to verify the ability to prescribe multiple medications sequentially.
    • Included tests to assert the correct display of medication table headers.
    • Added a test to confirm that the prescriber's name is displayed correctly after a medication is prescribed.
  • packages/e2e-tests/tests/patients/medication.spec.ts
    • Renamed the test suite to 'Medication Tab'.
    • Implemented a beforeEach hook to navigate to a new patient's details page.
    • Added a test to verify navigation to the medication tab within an encounter and the visibility of key elements.
    • Included a test to check the display of medication table headers.
    • Added a test to confirm the 'New prescription' button is visible and enabled.
    • Developed a test to verify that clicking 'New prescription' successfully opens the modal and displays its key action buttons.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a comprehensive set of E2E tests for medication-related features, including medication requests and prescribing medication within an encounter. The page object model is well-utilized, and the tests cover various scenarios, including positive and negative paths. My feedback focuses on improving test stability by addressing the use of potentially brittle test IDs and enhancing code maintainability by improving encapsulation and reducing redundancy.

(this as any)[key] = page.getByTestId(id);
}

this.pageHeading = page.getByTestId('topbarheading-go4f');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The test ID 'topbarheading-go4f' appears to have a generated suffix, which makes it brittle and prone to breaking if the component's rendering changes. For better test stability, please use a static, meaningful data-testid. Additionally, for consistency, this locator should be defined within the testIds object along with the others.

Comment on lines +48 to +68
const testIds = {
medicationInput: 'medication-field-medicationId-8k3m-input',
isOngoingCheckbox: 'medication-field-isOngoing-7j2p-controlcheck',
isPrnCheckbox: 'medication-field-isPrn-9n4q-controlcheck',
isVariableDoseCheckbox: 'medication-field-isVariableDose-5h8x-controlcheck',
isPhoneOrderCheckbox: 'medication-field-isPhoneOrder-2e4r-controlcheck',
doseAmountInput: 'medication-field-doseAmount-3t6w',
unitsSelect: 'medication-field-units-2r9v-select',
frequencyInput: 'medication-field-frequency-4c7z-input',
routeSelect: 'medication-field-route-6d1b-select',
prescriptionDateInput: 'medication-field-date-8m5k',
startDateTimeInput: 'medication-field-startDate-1a9s',
durationValueInput: 'medication-field-durationValue-7p2n',
durationUnitSelect: 'medication-field-durationUnit-4q8f-select',
prescriberInput: 'medication-field-prescriberId-3x5h-input',
indicationInput: 'medication-field-indication-9w6y',
notesInput: 'medication-field-notes-5b3t',
dischargeQuantityInput: 'medication-field-quantity-6j9m',
finaliseAndPrintButton: 'medication-button-finaliseAndPrint-8v2q',
finaliseButton: 'medication-button-finalise-7x3d',
} as const;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The test IDs used in this page object contain suffixes that appear to be auto-generated (e.g., -8k3m, -7j2p, -3t6w). These IDs are likely to be unstable and may change with unrelated code modifications, leading to brittle tests that are difficult to maintain. It is strongly recommended to work with the development team to establish stable, meaningful data-testid attributes for key elements. This will significantly improve the long-term stability and reliability of the test suite. This concern applies to other page objects in this PR as well.


// Check if the PrescriptionTypeModal appeared (has "Continue" button)
const continueButton = this.page.getByRole('button', { name: 'Continue', exact: true });
const finaliseButton = this.page.getByTestId('medication-button-finalise-7x3d');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line hardcodes the test ID 'medication-button-finalise-7x3d', which is an implementation detail of NewPrescriptionModal. This breaks encapsulation and makes the code harder to maintain. If the test ID in NewPrescriptionModal changes, this will also need to be updated, and it's easy to miss. A better approach would be to avoid duplicating this information. For example, you could expose it as a static property on NewPrescriptionModal.

Comment on lines +32 to +34
const values = await modal.fillRequiredFields();
await modal.finaliseButton.click();
await modal.waitForModalToClose();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code duplicates the logic found in the modal.fillAndFinalise() method. Leveraging the existing abstraction will make the test more concise and easier to read.

Suggested change
const values = await modal.fillRequiredFields();
await modal.finaliseButton.click();
await modal.waitForModalToClose();
const values = await modal.fillAndFinalise();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant