-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from trurl-master/more-elements
v1.1
- Loading branch information
Showing
18 changed files
with
226 additions
and
52 deletions.
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import '@testing-library/jest-dom'; | ||
import './src/index'; | ||
import './src/matchers'; |
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,3 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const matchers = require('./dist/matchers'); | ||
module.exports = matchers; |
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
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
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
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,32 @@ | ||
import { render } from '@testing-library/react'; | ||
import { byRole } from '..'; | ||
|
||
describe('datalist', () => { | ||
it('renders correct structure', () => { | ||
const { container } = render( | ||
<> | ||
<label htmlFor="ice-cream-choice">Choose a flavor:</label> | ||
<input | ||
list="ice-cream-flavors" | ||
id="ice-cream-choice" | ||
name="ice-cream-choice" | ||
/> | ||
<datalist id="ice-cream-flavors"> | ||
<option value="Chocolate"></option> | ||
<option value="Coconut"></option> | ||
<option value="Mint"></option> | ||
<option value="Strawberry"></option> | ||
<option value="Vanilla"></option> | ||
</datalist> | ||
</> | ||
); | ||
|
||
expect(container).toHaveA11yTree( | ||
byRole('generic', [ | ||
byRole('LabelText', ['Choose a flavor:']), | ||
byRole('combobox', { name: 'Choose a flavor:' }), | ||
// datalist has display: none by default | ||
]) | ||
); | ||
}); | ||
}); |
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,27 @@ | ||
import { render } from '@testing-library/react'; | ||
import { byRole } from '..'; | ||
|
||
describe('del-ins', () => { | ||
it('renders correct structure', () => { | ||
const { container } = render( | ||
<blockquote> | ||
There is <del>nothing</del> <ins>no code</ins> either good or bad, but | ||
<del>thinking</del> <ins>running it</ins> makes it so. | ||
</blockquote> | ||
); | ||
|
||
expect(container.firstChild).toHaveA11yTree( | ||
byRole('blockquote', [ | ||
'There is ', | ||
byRole('deletion', ['nothing']), | ||
' ', | ||
byRole('insertion', ['no code']), | ||
' either good or bad, but', | ||
byRole('deletion', ['thinking']), | ||
' ', | ||
byRole('insertion', ['running it']), | ||
' makes it so.', | ||
]) | ||
); | ||
}); | ||
}); |
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,38 @@ | ||
import { render } from '@testing-library/react'; | ||
import { byRole } from '..'; | ||
|
||
describe('details', () => { | ||
it('closed by default, content is hidden', () => { | ||
const { container } = render( | ||
<details> | ||
<summary>Details</summary> | ||
<p>Something small enough to escape casual notice.</p> | ||
some simple text | ||
</details> | ||
); | ||
|
||
expect(container.firstChild).toHaveA11yTree( | ||
byRole('group', { expanded: false }, [ | ||
byRole('DisclosureTriangle', ['Details']), | ||
// the details element is not expanded by default | ||
// so the content is not rendered | ||
]) | ||
); | ||
}); | ||
|
||
it('open, content is visible', () => { | ||
const { container } = render( | ||
<details open> | ||
<summary>Details</summary> | ||
Something small enough to escape casual notice. | ||
</details> | ||
); | ||
|
||
expect(container.firstChild).toHaveA11yTree( | ||
byRole('group', { expanded: true }, [ | ||
byRole('DisclosureTriangle', ['Details']), | ||
'Something small enough to escape casual notice.', | ||
]) | ||
); | ||
}); | ||
}); |
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,37 @@ | ||
import { render } from '@testing-library/react'; | ||
import { byRole } from '..'; | ||
|
||
describe('dl-dt-dd', () => { | ||
it('renders correct structure', () => { | ||
const { container } = render( | ||
<> | ||
<p>Cryptids of Cornwall:</p> | ||
|
||
<dl> | ||
<dt>Beast of Bodmin</dt> | ||
<dd>A large feline inhabiting Bodmin Moor.</dd> | ||
|
||
<dt>Morgawr</dt> | ||
<dd>A sea serpent.</dd> | ||
|
||
<dt>Owlman</dt> | ||
<dd>A giant owl-like creature.</dd> | ||
</dl> | ||
</> | ||
); | ||
|
||
expect(container).toHaveA11yTree( | ||
byRole('generic', [ | ||
byRole('paragraph', ['Cryptids of Cornwall:']), | ||
byRole('DescriptionList', [ | ||
byRole('term', ['Beast of Bodmin']), | ||
byRole('definition', ['A large feline inhabiting Bodmin Moor.']), | ||
byRole('term', ['Morgawr']), | ||
byRole('definition', ['A sea serpent.']), | ||
byRole('term', ['Owlman']), | ||
byRole('definition', ['A giant owl-like creature.']), | ||
]), | ||
]) | ||
); | ||
}); | ||
}); |
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
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
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
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
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,13 @@ | ||
import { isDetailsElement } from '../type-guards'; | ||
|
||
// if a descendant of an article, aside, main, nav or section element, or an element with role=article, complementary, main, navigation or region | ||
export const isNonLandmarkRole = (element: HTMLElement, role: string) => | ||
['article', 'aside', 'main', 'nav', 'section'].includes( | ||
element.tagName.toLowerCase() | ||
) || | ||
['aricle', 'complementary', 'main', 'navigation', 'region'].includes(role); | ||
|
||
export const isList = (role: HTMLElement['role']) => role === 'list'; | ||
|
||
export const isClosedDetails = (element: HTMLElement) => | ||
isDetailsElement(element) && !element.open; |
Oops, something went wrong.