-
Notifications
You must be signed in to change notification settings - Fork 350
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
[SR][SR Tree] Add screen reader tree to interactive graph editor #2062
Merged
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
24752b0
[SR][SR Tree] Add SR Tree to editor
nishasy c060a21
add tests
nishasy fc32554
docs(changeset): [SR][SR Tree] Add screen reader tree to interactive …
nishasy 5028e4d
add dependency to wonder-blocks-pill
nishasy f50b20b
add more comments
nishasy 47dabcf
Update tests
nishasy d850a02
remove container.container from tests
nishasy 8be9dda
fetchAriaLabels --> getAccessibilityAttributes
nishasy 7eb574f
Remove unnecessary loop
nishasy eff7fa4
support multiple spaces in description, add test
nishasy dcafc88
ariaString --> aria
nishasy b3e2e88
Add comment for textContent and test (test doesn't work)
nishasy 71797fa
Add toggle for roles/tags. Show class names
nishasy 619145c
rename role to roleOrTag
nishasy c909bc2
add more tests
nishasy bd3dd67
Merge branch 'main' into sr-tree-experiment
nishasy 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 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,6 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
"@khanacademy/perseus-editor": patch | ||
--- | ||
|
||
[SR][sr tree] Add screen reader tree to interactive graph editor |
This file contains 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
290 changes: 290 additions & 0 deletions
290
...editor/src/widgets/interactive-graph-editor/components/interactive-graph-sr-tree.test.tsx
This file contains 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,290 @@ | ||
import {render} from "@testing-library/react"; | ||
import * as React from "react"; | ||
|
||
import {getAccessibilityAttributes} from "./interactive-graph-sr-tree"; | ||
|
||
describe("fetchAriaLabels", () => { | ||
test("should return an empty array if the container is null", () => { | ||
// Arrange | ||
const container = undefined; | ||
const expected = []; | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
test("should return an array of labels", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div aria-label="label1" /> | ||
<div aria-label="label2" /> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([ | ||
{ | ||
role: "div", | ||
attributes: [{name: "label", value: "label1"}], | ||
}, | ||
{ | ||
role: "div", | ||
attributes: [{name: "label", value: "label2"}], | ||
}, | ||
]); | ||
}); | ||
|
||
test("should return an array with given roles", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div role="button" aria-label="aria-label1" /> | ||
<div role="button" aria-label="aria-label2" /> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([ | ||
{ | ||
role: "button", | ||
attributes: [{name: "label", value: "aria-label1"}], | ||
}, | ||
{ | ||
role: "button", | ||
attributes: [{name: "label", value: "aria-label2"}], | ||
}, | ||
]); | ||
}); | ||
|
||
test("should return an array with descriptions", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div aria-describedby="description1">label1</div> | ||
<div aria-describedby="description2">label2</div> | ||
<div id="description1">description1 content</div> | ||
<div id="description2">description2 content</div> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([ | ||
{ | ||
role: "div", | ||
attributes: [ | ||
{name: "description", value: "description1 content"}, | ||
], | ||
}, | ||
{ | ||
role: "div", | ||
attributes: [ | ||
{name: "description", value: "description2 content"}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
test("should return an array for element with multiple descriptions", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div aria-describedby="description1 description2">label1</div> | ||
<div id="description1">description1 content</div> | ||
<div id="description2">description2 content</div> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([ | ||
{ | ||
role: "div", | ||
attributes: [ | ||
{name: "description", value: "description1 content"}, | ||
{name: "description", value: "description2 content"}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
test("should return an array for element with multiple descriptions with multiple spaces", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div aria-describedby="description1 description2"> | ||
label1 | ||
</div> | ||
<div id="description1">description1 content</div> | ||
<div id="description2">description2 content</div> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([ | ||
{ | ||
role: "div", | ||
attributes: [ | ||
{name: "description", value: "description1 content"}, | ||
{name: "description", value: "description2 content"}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
test("should include hidden descriptions", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div aria-describedby="description1 description2">label1</div> | ||
<div id="description1">description1 content</div> | ||
<div id="description2" style={{display: "hidden"}}> | ||
description2 content | ||
</div> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([ | ||
{ | ||
role: "div", | ||
attributes: [ | ||
{name: "description", value: "description1 content"}, | ||
{name: "description", value: "description2 content"}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
test("should not include descriptions that are not found", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div aria-describedby="description1 description2">label1</div> | ||
<div id="description1">description1 content</div> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([ | ||
{ | ||
role: "div", | ||
attributes: [ | ||
{name: "description", value: "description1 content"}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
test("should build attributes array with a variety of attributes", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div aria-label="label-only" /> | ||
<div aria-describedby="description-only" /> | ||
<div role="img" aria-label="label with role" /> | ||
<div | ||
role="button" | ||
aria-label="aria-label1" | ||
aria-describedby="description1" | ||
/> | ||
<div | ||
role="button" | ||
aria-label="aria-label2" | ||
aria-describedby="description2" | ||
/> | ||
<div id="description-only">description-only content </div> | ||
<div id="description1">description1 content</div> | ||
<div id="description2">description2 content</div> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([ | ||
{ | ||
role: "div", | ||
attributes: [{name: "label", value: "label-only"}], | ||
}, | ||
{ | ||
role: "div", | ||
attributes: [ | ||
{name: "description", value: "description-only content "}, | ||
], | ||
}, | ||
{ | ||
role: "img", | ||
attributes: [{name: "label", value: "label with role"}], | ||
}, | ||
{ | ||
role: "button", | ||
attributes: [ | ||
{name: "label", value: "aria-label1"}, | ||
{name: "description", value: "description1 content"}, | ||
], | ||
}, | ||
{ | ||
role: "button", | ||
attributes: [ | ||
{name: "label", value: "aria-label2"}, | ||
{name: "description", value: "description2 content"}, | ||
], | ||
}, | ||
]); | ||
}); | ||
|
||
test("should not add element if descriptions are not found", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div aria-describedby="description1 description2">label1</div> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
test("should not add element if aria attributes are not found", () => { | ||
// Arrange | ||
const {container} = render( | ||
<div> | ||
<div /> | ||
</div>, | ||
); | ||
|
||
// Act | ||
const result = getAccessibilityAttributes(container); | ||
|
||
// Assert | ||
expect(result).toEqual([]); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
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 test still passes if I change the code to use
innerText
instead oftextContent
, which is super weird. That's not how it behaves in practice. Not sure what I'm doing wrong. 🤔