Skip to content

#1410 Add manage-users (Assign Roles/Districts) e2e coverage - #1425

Merged
brijesh-amin merged 3 commits into
devfrom
feature/1410-manage-users-e2e
Sep 29, 2026
Merged

brijesh-amin merged 3 commits into
devfrom
feature/1410-manage-users-e2e

Conversation

@brijesh-amin

Copy link
Copy Markdown
Collaborator

Summary

Implements e2e coverage for the "manage user" functionality (Assign Roles and Districts page), tracked by #1410 and its sub-issues #1421-#1424, following the same pattern already established for Manage Clients (#1409).

What was implemented

  • playwright/e2e/support/manageUsersRuntime.ts — seed a user with role_id NULL, ensure/revoke role_permissions for permission id 11 ("Assign users a role"), look up the ref_district "TST" fixture by code, UI selectors, and API verification helpers.
  • playwright/e2e/assign-roles-and-districts.spec.ts:
    • nav-link permission gate (grant/revoke permission 11, re-login, assert visibility)
    • empty states (before user selection; a freshly seeded no-role user)
    • assign role + district(s) round trip, verified via GET /v1/user/:id and /v1/user/:id/districts, then updated to a different role/district combination
    • Range Agreement Holder + districts is blocked in the UI (disabled Assign button + inline error) — also documents the current server-side response (500) when the guard is bypassed directly via the API
    • a forced-failure error state (via route interception) asserts the assigningError message renders

Bug fix found and fixed along the way

All three MUI Autocomplete fields on assignRolesAndDistrictsPage/index.tsx shared the same hardcoded id="user-autocomplete-select", which corrupted each field's accessible name (labels bled across fields, making the fields impossible to target reliably by role/label — a real, pre-existing accessibility bug, not just a test issue). Fixed by giving each field a unique id (assign-roles-select-user, assign-roles-select-role, assign-roles-select-districts).

Verification

  • Ran npx playwright test playwright/e2e/assign-roles-and-districts.spec.ts twice back-to-back against a local dev API/DB/web stack: 5/5 passing both times.
  • Confirmed no residual seed rows (user_account, user_districts) after each run.
  • npx eslint / npx prettier --check pass on all changed/added files.
  • No new env vars or CI config changes needed — .github/workflows/e2e.yml's PLAYWRIGHT_TEST_SPEC defaults to running all specs, and the existing PLAYWRIGHT_TEST_DISTRICT_CODE/PLAYWRIGHT_DB_* vars are reused.

Follow-up

Closes #1410.
Closes #1421.
Closes #1422.
Closes #1423.

- New playwright/e2e/support/manageUsersRuntime.ts: seed user (role_id NULL),
  ensure/revoke role_permissions for permission id 11 ("Assign users a role"),
  district lookup by code, UI selectors, and API verification helpers, mirroring
  manageClientsRuntime.ts conventions.
- New playwright/e2e/assign-roles-and-districts.spec.ts covering:
  - nav-link permission gate (grant/revoke permission 11)
  - empty states (before user selection, and a no-role seeded user)
  - assign role + districts round trip, verified via GET /v1/user/:id and
    /v1/user/:id/districts, then updated to a different role/district combo
  - Range Agreement Holder + districts is blocked in the UI (disabled button +
    error text) and documents the current server-side 500 response when the
    guard is bypassed directly via the API
  - a forced-failure error state renders the assigningError message
- Fixed a real accessibility bug found while wiring up selectors: all three MUI
  Autocomplete fields on the Assign Roles/Districts page shared the same
  hardcoded id="user-autocomplete-select", corrupting each field's accessible
  name. Gave each field a unique id.

Verified twice in a row against a local dev API/DB/web stack (5/5 passing, no
DB residue). Tracked via #1410, with sub-issues #1421-#1424 documenting
preconditions, implementation, and verification status.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

The suite leaves a permission grant behind and does not fully verify district-row replacement.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds end-to-end coverage for managing user roles and districts, plus unique accessible identifiers for the page’s autocomplete fields.

Changes:

  • Adds database, API, and UI helpers for manage-users tests.
  • Covers permission gating, assignment workflows, edge cases, and errors.
  • Assigns unique IDs to autocomplete controls.
File Description
src/​components/​assignRolesAndDistrictsPage/​index.tsx Adds unique autocomplete IDs.
playwright/​e2e/​support/​manageUsersRuntime.ts Adds manage-users test helpers.
playwright/​e2e/​assign-roles-and-districts.spec.ts Adds end-to-end workflow coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread playwright/e2e/assign-roles-and-districts.spec.ts Outdated
Comment thread playwright/e2e/assign-roles-and-districts.spec.ts Outdated

Copilot AI left a comment

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.

Copilot review overview

🔵 Needs a closer look

The Agreement Holder test has a district-fetch race that can make its assertions flaky.

Review effort: Balanced
Findings: None

Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Await district request before selecting TST

playwright/​e2e/​assign-roles-and-districts.spec.ts:246

Wait for the selected user's district request here before choosing TST. pullRoleAndDistrict asynchronously replaces selectedDistricts when /v1/district/:userId resolves, so the current sequence can clear the just-selected district and make the disabled-button/error assertions flaky. The round-trip test already uses this synchronization option.

@brijesh-amin
brijesh-amin requested a balanced review from Copilot September 29, 2026 00:18
@brijesh-amin
brijesh-amin merged commit cfaccf6 into dev Sep 29, 2026
4 checks passed

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

The required OpenShift verification remains incomplete despite the PR closing #1410.

Review effort: Balanced
Findings: 1 Low severity

Open (1)

});
};

test.describe('Assign Roles and Districts', () => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants