[QA-214] Fix flaky device service history edit flow test - #16572
[QA-214] Fix flaky device service history edit flow test#16572nihal467 wants to merge 9 commits into
Conversation
Wait for the Add Service Record sheet to fully close before opening the edit sheet. Previously the test clicked edit while the Add sheet was still animating out, so two Service Date popover-triggers were present and the locator hit a strict-mode violation. Ref: QA-214
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughChangesService record edit tests
Prescription creation tests
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Deploying care-preview with
|
| Latest commit: |
221c36d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5cc89f63.care-preview-a7w.pages.dev |
| Branch Preview URL: | https://fix-device-service-history-e.care-preview-a7w.pages.dev |
There was a problem hiding this comment.
Pull request overview
Fixes Playwright E2E flakiness in the device service history edit-flow tests by ensuring the “Add Service Record” sheet has fully closed before interacting with the edit sheet (preventing overlapping UI elements that trigger strict-mode locator violations).
Changes:
- Added an assertion to wait for the “Save” button (from the Add sheet) to become hidden before opening the edit sheet.
- Applied the same wait to both edit-flow tests in
deviceServiceHistory.spec.ts.
Greptile SummaryThis PR fixes three distinct sources of intermittent Playwright E2E test flakiness, each caused by insufficient isolation between overlapping UI state, shared test data, or shared browser resources.
Confidence Score: 5/5All three changes are scoped exclusively to E2E test files with no effect on production code; the fixes are targeted and well-reasoned. The changes address real, reproducible race conditions and shared-state collisions in Playwright tests. Each fix is minimal and directly tied to the described failure mode. The try/finally cleanup in patientFiles.spec.ts is a strict improvement over the original. No production logic is touched. No files require special attention. Important Files Changed
Reviews (9): Last reviewed commit: "test: drop hardcoded timeouts, rely on g..." | Re-trigger Greptile |
🎭 Playwright Test ResultsStatus: ✅ Passed
📊 Detailed results are available in the playwright-final-report artifact. Run: #10281 |
|
@copilot fix the playwright test failure in the ci/cd and make sure its fully passes |
…ation Co-authored-by: nihal467 <57055998+nihal467@users.noreply.github.com>
The previous Fixed in commit |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/facility/settings/devices/deviceServiceHistory.spec.ts`:
- Around line 82-87: In both affected tests, wait for the Add sheet’s Save
button to become hidden immediately after saving and before clicking the Edit
trigger. Keep the existing editSheet dialog scoping and visibility assertion
unchanged, and apply this synchronization to both occurrences identified around
the edit flow.
- Around line 84-87: Update both dialog locators around editSheet and the
corresponding locator to avoid hard-coded "Edit Service Record"; resolve the
dialog name through the existing test i18n helper or use the dialog’s stable
data-slot selector so the tests work under every active locale.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 43785f93-6908-41f4-a49b-371bdf22e29c
📒 Files selected for processing (1)
tests/facility/settings/devices/deviceServiceHistory.spec.ts
Address review feedback: assert the Add Service Record sheet's Save button is hidden before opening the edit sheet (fixes the close-animation race at its source), and scope to the sole remaining dialog instead of the locale-dependent 'Edit Service Record' title. Ref: QA-214
Reword to avoid overclaiming full locale independence; the tests still use English accessible names. The point is scoping to the active sheet instead of a hard-coded dialog title. Ref: QA-214
The highlighted (non-unit) and unit prescription tests run serially against the same encounter and picked a medicine at random from a 5-item list. A 1-in-5 collision made the unit test match the other test's highlighted row, failing toHaveCount(0) intermittently. Allocate two distinct medicines so their rows never overlap.
The test picked the first "View" button on a patient whose file list is shared across tests. That could land on an archived file, whose viewer is a different dialog with two "Close" buttons (strict-mode violation), and the nurse-side "Close" locator was unscoped. Target the specific uploaded file's row by a unique name, assert the File Preview dialog opens, and scope the close button to that dialog.
Address Copilot review feedback on PR #16572: getByRole("dialog") can match multiple dialogs while a previous sheet is still unmounting. - deviceServiceHistory: target the edit sheet via .last() - patientFiles: filter the preview dialog by its "File Preview" title
|
|
||
| // With the Add sheet closed, the edit sheet is the only open dialog. Use | ||
| // .last() to target the most recently opened dialog so a still-unmounting | ||
| // sheet can't reintroduce a strict-mode match. |
There was a problem hiding this comment.
Would this still be present since you have added the check on line 78? Not a big deal either ways, but still.
Proposed Changes
Fixes flaky Playwright E2E tests. Originally scoped to the device service history edit flow, this PR was expanded to fold in two additional flakiness fixes surfaced while validating the same CI shards.
1. Device service history edit flow (
deviceServiceHistory.spec.ts)Failure: The "Edit an existing service record and verify changes" test intermittently failed with a Playwright strict-mode violation:
Root cause: After saving a new record, the test clicked the edit button before the "Add Service Record" sheet finished its close animation/unmount. Both the Add sheet and the Edit sheet momentarily rendered a Service Date popover-trigger, so the locator matched 2 elements.
Fix: Wait for the Add sheet to fully close (its
Savebutton to become hidden) before opening the edit sheet, scope all edit interactions to the edit dialog, and target the most recently opened dialog via.last(). Applied to both edit-flow tests in the file.2. Prescription unit-dose highlight (
prescriptionCreate.spec.ts)Root cause: Two serial tests share one encounter/medication table, but both picked a medicine via
faker.helpers.arrayElement(medicineNames). From a 5-item list they occasionally picked the same medicine, so the unit-dose test's row filter matched the highlighted (non-unit) test's row and the.bg-yellow-100count assertion failed.Fix: Allocate two distinct medicines at describe scope via
faker.helpers.arrayElements(medicineNames, 2).3. Patient files cross-user access (
patientFiles.spec.ts)Root cause: The "file accessible to another user" test clicked the first
/view/ibutton on a shared patient whose first row could be an archived file, opening theArchivedFileDialog(which has two "Close" buttons) and triggering a strict-mode violation.Fix: Upload a uniquely named file, target that specific row by name, use an exact "View", assert the "File Preview" dialog (filtered by title), and scope the Close to that dialog. Repeated for the nurse context.
@ohcnetwork/care-fe-code-reviewers
Summary by CodeRabbit