-
Notifications
You must be signed in to change notification settings - Fork 806
fix: prevent check/uncheck from hanging on hidden checkbox elements #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
liuxiaopai-ai
wants to merge
1
commit into
vercel-labs:main
Choose a base branch
from
liuxiaopai-ai:fix/check-hidden-checkbox-hang
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import { safeCheckAction } from './actions.js'; | ||
|
|
||
| /** | ||
| * Tests for safeCheckAction - fix for issue #335 | ||
| * Ensures check/uncheck does not hang on hidden checkbox elements | ||
| * (common in Element UI, Ant Design, Vuetify, etc.) | ||
| */ | ||
| describe('safeCheckAction', () => { | ||
| it('should call check() normally when element is visible', async () => { | ||
| const locator = { | ||
| check: vi.fn().mockResolvedValue(undefined), | ||
| uncheck: vi.fn().mockResolvedValue(undefined), | ||
| } as any; | ||
|
|
||
| await safeCheckAction(locator, 'check'); | ||
| expect(locator.check).toHaveBeenCalledWith({ timeout: 5000 }); | ||
| }); | ||
|
|
||
| it('should call uncheck() normally when element is visible', async () => { | ||
| const locator = { | ||
| check: vi.fn().mockResolvedValue(undefined), | ||
| uncheck: vi.fn().mockResolvedValue(undefined), | ||
| } as any; | ||
|
|
||
| await safeCheckAction(locator, 'uncheck'); | ||
| expect(locator.uncheck).toHaveBeenCalledWith({ timeout: 5000 }); | ||
| }); | ||
|
|
||
| it('should retry with force:true when element is not visible (check)', async () => { | ||
| const locator = { | ||
| check: vi | ||
| .fn() | ||
| .mockRejectedValueOnce(new Error('Element is not visible')) | ||
| .mockResolvedValueOnce(undefined), | ||
| uncheck: vi.fn(), | ||
| } as any; | ||
|
|
||
| await safeCheckAction(locator, 'check'); | ||
| expect(locator.check).toHaveBeenCalledTimes(2); | ||
| expect(locator.check).toHaveBeenLastCalledWith({ force: true }); | ||
| }); | ||
|
|
||
| it('should retry with force:true when element is not visible (uncheck)', async () => { | ||
| const locator = { | ||
| check: vi.fn(), | ||
| uncheck: vi | ||
| .fn() | ||
| .mockRejectedValueOnce(new Error('Element is not visible')) | ||
| .mockResolvedValueOnce(undefined), | ||
| } as any; | ||
|
|
||
| await safeCheckAction(locator, 'uncheck'); | ||
| expect(locator.uncheck).toHaveBeenCalledTimes(2); | ||
| expect(locator.uncheck).toHaveBeenLastCalledWith({ force: true }); | ||
| }); | ||
|
|
||
| it('should retry with force:true on timeout (hidden checkbox)', async () => { | ||
| const locator = { | ||
| check: vi | ||
| .fn() | ||
| .mockRejectedValueOnce(new Error('Timeout 5000ms exceeded waiting for element')) | ||
| .mockResolvedValueOnce(undefined), | ||
| uncheck: vi.fn(), | ||
| } as any; | ||
|
|
||
| await safeCheckAction(locator, 'check'); | ||
| expect(locator.check).toHaveBeenCalledTimes(2); | ||
| expect(locator.check).toHaveBeenLastCalledWith({ force: true }); | ||
| }); | ||
|
|
||
| it('should retry with force:true when element is hidden', async () => { | ||
| const locator = { | ||
| check: vi | ||
| .fn() | ||
| .mockRejectedValueOnce(new Error('element is hidden')) | ||
| .mockResolvedValueOnce(undefined), | ||
| uncheck: vi.fn(), | ||
| } as any; | ||
|
|
||
| await safeCheckAction(locator, 'check'); | ||
| expect(locator.check).toHaveBeenCalledTimes(2); | ||
| expect(locator.check).toHaveBeenLastCalledWith({ force: true }); | ||
| }); | ||
|
|
||
| it('should retry with force:true on "waiting for" error', async () => { | ||
| const locator = { | ||
| check: vi | ||
| .fn() | ||
| .mockRejectedValueOnce(new Error('waiting for locator to be visible')) | ||
| .mockResolvedValueOnce(undefined), | ||
| uncheck: vi.fn(), | ||
| } as any; | ||
|
|
||
| await safeCheckAction(locator, 'check'); | ||
| expect(locator.check).toHaveBeenCalledTimes(2); | ||
| expect(locator.check).toHaveBeenLastCalledWith({ force: true }); | ||
| }); | ||
|
|
||
| it('should rethrow non-visibility errors', async () => { | ||
| const locator = { | ||
| check: vi.fn().mockRejectedValue(new Error('strict mode violation')), | ||
| uncheck: vi.fn(), | ||
| } as any; | ||
|
|
||
| await expect(safeCheckAction(locator, 'check')).rejects.toThrow('strict mode violation'); | ||
| expect(locator.check).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should rethrow unknown errors for uncheck', async () => { | ||
| const locator = { | ||
| check: vi.fn(), | ||
| uncheck: vi.fn().mockRejectedValue(new Error('some other error')), | ||
| } as any; | ||
|
|
||
| await expect(safeCheckAction(locator, 'uncheck')).rejects.toThrow('some other error'); | ||
| expect(locator.uncheck).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This retry condition treats any error containing
Timeoutorwaiting foras a hidden-element case, sosafeCheckActionwill force a secondcheck/uncheckeven when the first failure was due to other actionability problems (for example, an overlay intercepting pointer events or a control still disabled). In those cases the forced retry bypasses normal actionability checks and can report success instead of surfacing the real blocked-state error, which changes command semantics and can mask real UI issues. Please narrow the fallback trigger to explicit visibility/hidden signals rather than generic timeout text.Useful? React with 👍 / 👎.