Skip to content

Commit

Permalink
Keyboard Navigation acceptance tests (#13893)
Browse files Browse the repository at this point in the history
* Acceptance tests for keyboard modal

* a11y audit fix and localStorage clear

* Bind/rebind/localStorage tests

* Keyboard tests for dynamic nav and tables

* Rebinder and assert expectation

* Second percy snapshot showing hints no longer relevant
  • Loading branch information
philrenaud authored Jul 22, 2022
1 parent ee19f85 commit 02083a5
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 16 deletions.
12 changes: 7 additions & 5 deletions ui/app/components/keyboard-shortcuts-modal.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class="button is-borderless dismiss"
type="button"
{{on "click" (toggle "keyboard.shortcutsVisible" this)}}
aria-label="Dismiss"
>
{{x-icon "cancel"}}
</button>
Expand All @@ -19,7 +20,7 @@
</header>
<ul class="commands-list">
{{#each this.commands as |command|}}
<li>
<li data-test-command-label={{command.label}}>
<strong>{{command.label}}</strong>
<span class="keys">
{{#if command.recording}}
Expand All @@ -30,7 +31,7 @@
{{/if}}
{{/if}}

<button disabled={{or (not command.rebindable) command.recording}} type="button" {{on "click" (action this.keyboard.rebindCommand command)}}>
<button data-test-rebinder disabled={{or (not command.rebindable) command.recording}} type="button" {{on "click" (action this.keyboard.rebindCommand command)}}>
{{#each command.pattern as |key|}}
<span>{{clean-keycommand key}}</span>
{{/each}}
Expand All @@ -42,7 +43,7 @@
<footer>
<strong>Keyboard shortcuts {{#if this.keyboard.enabled}}enabled{{else}}disabled{{/if}}</strong>
<Toggle
data-test-cpu-toggle
data-test-enable-shortcuts-toggle
@isActive={{this.keyboard.enabled}}
@onToggle={{this.toggleListener}}
title="{{if this.keyboard.enabled "enable" "disable"}} keyboard shortcuts"
Expand All @@ -54,8 +55,9 @@
{{#if (and this.keyboard.enabled this.keyboard.displayHints)}}
{{#each this.hints as |hint|}}
<span
{{did-insert this.tetherToElement element=hint.element hint=hint}}
{{will-destroy this.untetherFromElement element=hint.element hint=hint}}
{{did-insert (fn this.tetherToElement hint.element hint)}}
{{will-destroy (fn this.untetherFromElement hint)}}
data-test-keyboard-hint
data-shortcut={{hint.pattern}}
class="{{if hint.menuLevel "menu-level"}}"
aria-hidden="true"
Expand Down
30 changes: 19 additions & 11 deletions ui/app/components/keyboard-shortcuts-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Tether from 'tether';

export default class KeyboardShortcutsModalComponent extends Component {
@service keyboard;
@service config;

escapeCommand = {
label: 'Hide Keyboard Shortcuts',
Expand Down Expand Up @@ -42,18 +43,25 @@ export default class KeyboardShortcutsModalComponent extends Component {
}
}

tetherToElement(self, _, { element, hint }) {
let binder = new Tether({
element: self,
target: element,
attachment: 'top left',
targetAttachment: 'top left',
targetModifier: 'visible',
});
hint.binder = binder;
@action
tetherToElement(element, hint, self) {
if (!this.config.isTest) {
let binder = new Tether({
element: self,
target: element,
attachment: 'top left',
targetAttachment: 'top left',
targetModifier: 'visible',
});
hint.binder = binder;
}
}
untetherFromElement(self, _, { hint }) {
hint.binder.destroy();

@action
untetherFromElement(hint) {
if (!this.config.isTest) {
hint.binder.destroy();
}
}

@action toggleListener() {
Expand Down
Loading

0 comments on commit 02083a5

Please sign in to comment.