Repository navigation
Tests: Cover user role changes and user search in admin E2E - #15779
shail-mehta wants to merge 4 commits into
Conversation
Add coverage for editing another user's role, blocking self-demotion to subscriber, and searching for existing and missing users.
There was a problem hiding this comment.
🟡 Changes recommended
The test can fail when the administrator is beyond the first page and, if the self-demotion guard regresses, can demote the shared administrator, breaking cleanup and other tests.
2 open issues
What changed in this PR
Extends the admin Users end-to-end tests to cover role management and user search, addressing remaining Users scenarios from Trac #52895.
Changes:
- Tests role changes through the edit screen, checking persistence in the UI and REST API.
- Checks that administrators cannot demote themselves through profile or bulk role controls.
- Covers searches for existing and missing users, including the empty-state message.
| File | Description |
|---|---|
tests/e2e/specs/users.test.js |
Adds four role-management and user-search tests using existing fixture and cleanup helpers. |
Review effort: Balanced
Run the own-role change check as a disposable administrator in an isolated browser context, and filter the Users list by username before selecting the row.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
lancewillett
left a comment
There was a problem hiding this comment.
Thanks. Two of these four are worth keeping, and two I'd drop. CI is green at 06eec79 with no retries (parallel 41, serial 72, both jobs).
Keep:
- Self-demotion via bulk Change role. The guard in
wp-admin/users.php(theerr_admin_rolebranch of thepromoteaction) has no other test.Tests_User::test_edit_user_role_update()coversedit_user(), not this bulk path. If the guard goes, the role changes and the "Changed roles." notice appears, so this fails. Locating the bulk controls and notice by ID is fine. - Empty search for a missing user. With a non-matching user present, it fails if
sis ignored.
Drop:
- Changing another user's role from the edit screen.
Tests_User::test_edit_user_role_update()(#42564) already promotes a user throughedit_user(), which is what this form posts to. - Searching for an existing user. If search is ignored, the row still appears, since the test site has far fewer than a page of users. So this can't catch a search regression; the empty-result test does that.
One small thing in the self-demotion test: await expect( usernameField ).toBeFocused(); checks login autofocus, which isn't what the test is about. I'd remove it so the test can only fail on the role guard.
AI review · claude-opus-5-5
Drop edit-screen role change and existing-user search cases already covered elsewhere, and remove the unrelated login autofocus assert from the self-demotion test.
|
Thanks! Addressed in b891c75 kept the self-demotion bulk Change role and empty missing-user search tests, dropped the edit-screen role change and existing-user search cases, and removed the login autofocus assert from the self-demotion test. |
lancewillett
left a comment
There was a problem hiding this comment.
Thanks, this is what I was after. Re-checked at b891c75: the PR now adds just the self-demotion and empty-search tests, Prettier passes, and it applies cleanly to trunk.
CI is green (parallel 45, serial 74). One parallel job retried general-settings-invalid-timezone.test.js (the "" case), a known retry that this PR doesn't touch.
Ready to land.
AI review · claude-opus-5-5
Log in as a second administrator and try to change their own role to Subscriber with the bulk Change role control on the Users screen. Check for the error notice and that the role is unchanged. Search users for a missing name and check for the empty result, with another user present so the test fails if search is ignored. Developed in: #15779 Props shailu25. See #52895. git-svn-id: https://develop.svn.wordpress.org/trunk@65334 602fd350-edb4-49c9-b593-d223f7449a82
|
PR #15779 landed in https://core.trac.wordpress.org/changeset/65334 |
Log in as a second administrator and try to change their own role to Subscriber with the bulk Change role control on the Users screen. Check for the error notice and that the role is unchanged. Search users for a missing name and check for the empty result, with another user present so the test fails if search is ignored. Developed in: WordPress/wordpress-develop#15779 Props shailu25. See #52895. Built from https://develop.svn.wordpress.org/trunk@65334 git-svn-id: http://core.svn.wordpress.org/trunk@64474 1a063a9b-81f0-0310-95a4-ce76da25c4cd


Trac ticket: #52895
Adds remaining Users e2e coverage from ticket #52895.
What
Why
Ticket #52895 lists Users coverage for changing roles, preventing an admin from demoting itself, and searching for users. Existing users e2e covered create/login and bulk delete, but not these cases.
How
Extends
tests/e2e/specs/users.test.jsusing the same create/cleanup helpers. Role is found by label; top bulk role controls keep their IDs because top/bottom share an accessible name (r65275).Testing instructions
npm run env:startnpm run test:e2e -- tests/e2e/specs/users.test.jsUse of AI Tools