1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import (
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9)
10
11func TestIssueFieldAccessibility(t *testing.T) {
12 for _, field := range []string{"title", "body", "author"} {
13 t.Run(field, func(t *testing.T) {
14 html := renderToString(t, IssueForm(Layout{}, IssueFormPage{ErrorField: field, Error: "Too long"}))
15 assert.Contains(t, html, `id="issue-`+field+`" aria-describedby="issue-`+field+`-count issue-`+field+`-error" aria-invalid="true"`)
16 assert.Contains(t, html, `<p id="issue-`+field+`-error" class="f-error" role="alert">Too long</p>`)
17 for _, f := range []string{"title", "body", "author"} {
18 assert.Contains(t, html, `<output id="issue-`+f+`-count" aria-live="off"`)
19 }
20 })
21 }
22}
23
24func TestHintAccessibility(t *testing.T) {
25 html := renderToString(t, Hint(Layout{Live: true, LiveURL: "/events"}))
26 assert.Contains(t, html, `<div class="hint"><span aria-hidden="true" class="hint-nav"`)
27 assert.Contains(t, html, `<span role="status" aria-live="polite"><span class="hint-sel"`)
28 assert.Contains(t, html, `</span></span><span class="hint-live" role="status"`)
29}
30
31func TestPaletteAccessibilityWithoutNavigationItems(t *testing.T) {
32 html := renderToString(t, OverlayCmd(nil))
33 // The shortcut preference action is always present, even with no targets.
34 assert.Contains(t, html, `aria-expanded="true"`)
35 assert.Contains(t, html, `aria-activedescendant="cmd-o0"`)
36 assert.Contains(t, html, `id="cmd-o0" role="option" aria-selected="true" data-cursor`)
37 assert.Contains(t, html, `<a role="presentation" data-fire="keys">`)
38 assert.Contains(t, html, `aria-label="Close (esc)"`)
39 assert.NotContains(t, html, ` href=`)
40 assert.NotContains(t, html, `tabindex="-1"`)
41}
42
43func TestFinderStatusOutsideHiddenResults(t *testing.T) {
44 html := renderToString(t, Tree(Layout{}, TreePage{}))
45 assert.Contains(t, html, `<p id="finder-status" class="dim" role="status"></p><div id="finder" class="tree-card" hidden>`)
46}
47
48func TestPaletteNavigationOptionsAccessibility(t *testing.T) {
49 html := renderToString(t, OverlayCmd([]CmdItem{{Kind: "section", Label: "Files", Href: "/files"}}))
50 assert.Contains(t, html, `<a role="presentation" data-href="/files">`)
51 assert.NotContains(t, html, ` href=`)
52 assert.NotContains(t, html, `tabindex="-1"`)
53}