-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7962d34
commit 4d62f99
Showing
4 changed files
with
118 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as React from "react"; | ||
import { axe } from "jest-axe"; | ||
import { click, render } from "reakit-test-utils"; | ||
|
||
import { AriaLink } from ".."; | ||
|
||
const AriaLinkComp = () => { | ||
return ( | ||
<div> | ||
<AriaLink | ||
href="https://adobe.com" | ||
target="_blank" | ||
style={{ | ||
color: "blue", | ||
textDecoration: "underline", | ||
cursor: "pointer", | ||
}} | ||
> | ||
Adobe | ||
</AriaLink> | ||
</div> | ||
); | ||
}; | ||
|
||
describe("AriaLink", () => { | ||
it("should render correctly", () => { | ||
const { baseElement } = render(<AriaLinkComp />); | ||
|
||
expect(baseElement).toMatchInlineSnapshot(` | ||
<body> | ||
<div> | ||
<div> | ||
<a | ||
href="https://adobe.com" | ||
style="color: blue; text-decoration: underline; cursor: pointer;" | ||
target="_blank" | ||
> | ||
Adobe | ||
</a> | ||
</div> | ||
</div> | ||
</body> | ||
`); | ||
}); | ||
|
||
[true, false].forEach(state => { | ||
const should = state ? "should" : "should not"; | ||
test(`onPress ${should} fire when isDisabled prop is "${state}"`, () => { | ||
const alertFn = jest.fn(); | ||
const { getByText: text } = render( | ||
<AriaLink | ||
href="#" | ||
style={{ | ||
color: "blue", | ||
textDecoration: "underline", | ||
cursor: "pointer", | ||
}} | ||
onPress={alertFn} | ||
isDisabled={state} | ||
> | ||
Adobe | ||
</AriaLink>, | ||
); | ||
|
||
click(text("Adobe")); | ||
expect(alertFn).toBeCalledTimes(state ? 0 : 1); | ||
}); | ||
}); | ||
|
||
test("Link renders with no a11y violations", async () => { | ||
const { container } = render(<AriaLinkComp />); | ||
const results = await axe(container); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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,39 @@ | ||
import * as React from "react"; | ||
import { axe } from "jest-axe"; | ||
import { render } from "reakit-test-utils"; | ||
|
||
import { Link } from ".."; | ||
|
||
describe("ReakitLink", () => { | ||
it("should render correctly", () => { | ||
const { baseElement } = render( | ||
<Link href="#" isExternal disabled> | ||
link | ||
</Link>, | ||
); | ||
|
||
expect(baseElement).toMatchInlineSnapshot(` | ||
<body> | ||
<div> | ||
<a | ||
aria-disabled="true" | ||
disabled="" | ||
href="#" | ||
rel="noopener noreferrer" | ||
style="pointer-events: none;" | ||
target="_blank" | ||
> | ||
link | ||
</a> | ||
</div> | ||
</body> | ||
`); | ||
}); | ||
|
||
test("Link renders with no a11y violations", async () => { | ||
const { container } = render(<Link href="#">link</Link>); | ||
const results = await axe(container); | ||
|
||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
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