Skip to content

[UEPR-483] Action Menu Tests#452

Merged
kbangelov merged 6 commits intoscratchfoundation:release/UEPR-297-accessibility-improvementsfrom
kbangelov:task/uepr-483-action-menu-tests
Mar 23, 2026
Merged

[UEPR-483] Action Menu Tests#452
kbangelov merged 6 commits intoscratchfoundation:release/UEPR-297-accessibility-improvementsfrom
kbangelov:task/uepr-483-action-menu-tests

Conversation

@kbangelov
Copy link
Contributor

@kbangelov kbangelov commented Feb 20, 2026

Resolves

Part of https://scratchfoundation.atlassian.net/browse/UEPR-483

Proposed Changes

3 Unit tests to test keyboard navigation.

Reason for Changes

Part of Accessibility initiative for Scratch.

@kbangelov kbangelov requested a review from a team as a code owner February 20, 2026 10:39
expect(document.activeElement).toBe(mainButton);
});

test('tab closes menu and focuses next element', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add a test for shift + tab as well

Copy link
Contributor Author

@kbangelov kbangelov Feb 25, 2026

Choose a reason for hiding this comment

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

Though I did add one, it kept failing if I entered the menu before shift + tab-ing and I couldn't figure out why. Perhaps it's some difference between the user testing library and the real thing. Not sure if it's ok to leave it like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that you ended up adding a test for that. Did it start working consistently?

Copy link
Contributor Author

@kbangelov kbangelov Feb 27, 2026

Choose a reason for hiding this comment

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

The one I left, yes. If we add arrow_down to get inside the menu it doesn't perform correctly. Since there were some changes to the base branch since then, I will wait for that one to get merged first and then try again with this test (and check the other ones too).

@kbangelov kbangelov requested a review from KManolov3 February 25, 2026 09:42
@kbangelov kbangelov requested a review from KManolov3 March 9, 2026 07:54
Comment on lines +33 to +39
test('focus + arrow_down opens menu and arrow_up cycles to last', () => {
render(<ActionMenu {...defaultProps} />);
const mainButton = screen.getByRole('button', {name: 'Main Button'});

act(() => {
mainButton.focus();
fireEvent.keyDown(mainButton, {key: KEY.ARROW_DOWN});
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I think the this test case in the way that it's described and written is a bit misleading. Maybe we could do something like:

  • Focus opens menu and select the last element by default
  • Arrow down on last element cycles to the first
  • Arrow up on the first element cycles to the last


act(() => {
mainButton.focus();
fireEvent.keyDown(mainButton, {key: KEY.ARROW_DOWN});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need ARROW_DOWN to open the menu? Is it just so that we'd go to the first element? I wonder if that's relevant to the current test case, maybe it'd make more sense to keep it simple and avoid doing extra navigations? Same question for the other test cases where we do it.

Comment on lines +97 to +99
act(() => {
user.tab();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what's the difference between calling tab() on a user event and firing KEY.TAB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fireEvent.keyDown practically seemed to apply some .preventDefault() behavior.

<>
<button>Before Menu</button>
<ActionMenu {...defaultProps} />
<button>After Menu</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably don't need the after menu in this layout, since we never use it?

@kbangelov kbangelov requested a review from adzhindzhi March 20, 2026 08:09
Copy link
Contributor

@KManolov3 KManolov3 left a comment

Choose a reason for hiding this comment

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

Minor comments, but overall looks good 🙌

});

test('escape closes menu and returns focus to main button', () => {
test('arrow_up from first item cycles to last, arrow_down from last cycles to first', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: naming -  ActionMenu keyboard navigation + arrow_up from first item cycle to last, ... can become ActionMenu keyboard navigation + cycles to last when arrow_up pressed from first item, ...

Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: also ideally those would be separate testcases as they don't require that much setup/teardown to justify them being combined, but don't mind it staying that way

@kbangelov kbangelov merged commit e54d895 into scratchfoundation:release/UEPR-297-accessibility-improvements Mar 23, 2026
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants