Skip to content
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

shell: Fix and test skip links #20561

Merged
merged 2 commits into from
Jun 7, 2024
Merged

Conversation

martinpitt
Copy link
Member

We don't want the skiplinks to actually change the URL -- they will go
from e.g. /system to /cockpit/@localhost/shell/index.html#content.
This causes a page reload, breaks the focusing, and is also not an URL
which we actually want to expose. Fix this by stopping event
progression.

Also remove the return false -- event handlers don't return anything.

Introduce a TestMenu.testKeyboardNavigation -- skip links and tabbing
was previously not tested at all.

[1] https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback


Preparation for #20553 -- let's first test skiplinks before we change them.

The existing `key_press()` is named and implemented poorly, is hard to
use for non-letter characters and requires Chromium/Firefox specific
implementations.

Introduce a new `key()` function which takes a *single* key name. This
is portable across browsers, and something like "Enter" is much easier
to read than "\r". TestHostSwitching.testEdit already used it that way.
@martinpitt martinpitt requested review from jelly and marusak June 7, 2024 08:44
@martinpitt
Copy link
Member Author

@marusak As you introduced the skip links, I'd appreciate your review. My interactive test seems quite reasonable now (no reloads and focusing works), but I'd like to make sure it's what you had in mind.

@jelly You recently dabbled with the keyboard test API -- please let me know if b.key() works for you or you had something different in mind.

# FIXME: This should be key_press(), and key_press() should be something else
def key(self, name: str) -> None:
self.cdp.invoke("Input.dispatchKeyEvent", type="keyDown", key=name)
self.cdp.invoke("Input.dispatchKeyEvent", type="keyUp", key=name)
Copy link
Member

Choose a reason for hiding this comment

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

key sounds like a good compromise, breaking key_press is imo a no-go at this moment as everyone uses it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I thought about .key() and .input_text(), moving everything over to these two, and eventually dropping .key_press()

We don't want the skiplinks to *actually* change the URL -- they will go
from e.g. `/system` to `/cockpit/@localhost/shell/index.html#content`.
This causes a page reload, breaks the focusing, and is also not an URL
which we actually want to expose. Fix this by stopping event
progression.

Also remove the `return false` -- event handlers don't return anything [1].

Introduce a `TestMenu.testKeyboardNavigation` -- skip links and tabbing
was previously not tested at all.

[1] https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback
Copy link
Member

@marusak marusak left a comment

Choose a reason for hiding this comment

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

Works for me, thanks!

@martinpitt martinpitt merged commit 4bd95dc into cockpit-project:main Jun 7, 2024
79 of 81 checks passed
@martinpitt martinpitt deleted the skiplink branch June 7, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants