forked from reach/reach-ui
-
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.
- Loading branch information
Showing
17 changed files
with
429 additions
and
102 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
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 |
---|---|---|
@@ -1,7 +1,88 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`rendering does not render children when not open 1`] = ` | ||
<div | ||
lang="gr" | ||
/> | ||
exports[`<Dialog /> closes the dialog 1`] = ` | ||
<body> | ||
<div | ||
aria-hidden="true" | ||
> | ||
<div> | ||
<button> | ||
Show Dialog | ||
</button> | ||
</div> | ||
</div> | ||
<reach-portal> | ||
<div | ||
data-focus-guard="true" | ||
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" | ||
tabindex="0" | ||
/> | ||
<div | ||
data-focus-guard="true" | ||
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" | ||
tabindex="1" | ||
/> | ||
<div | ||
data-focus-lock-disabled="false" | ||
> | ||
<div> | ||
<div | ||
data-reach-dialog-overlay="" | ||
> | ||
<div | ||
aria-label="Announcement" | ||
aria-modal="true" | ||
data-reach-dialog-content="" | ||
role="dialog" | ||
tabindex="-1" | ||
> | ||
<div | ||
data-testid="inner" | ||
> | ||
<button> | ||
Close Dialog | ||
</button> | ||
<input | ||
data-testid="text" | ||
type="text" | ||
/> | ||
<button | ||
data-testid="useless-button" | ||
> | ||
Ayyyyyy | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div | ||
data-focus-guard="true" | ||
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" | ||
tabindex="0" | ||
/> | ||
</reach-portal> | ||
</body> | ||
`; | ||
|
||
exports[`<Dialog /> closes the dialog 2`] = ` | ||
<body> | ||
<div> | ||
<div> | ||
<button> | ||
Show Dialog | ||
</button> | ||
</div> | ||
</div> | ||
</body> | ||
`; | ||
|
||
exports[`<Dialog /> does not render children when not open 1`] = ` | ||
<body> | ||
<div> | ||
<div | ||
data-testid="root" | ||
/> | ||
</div> | ||
</body> | ||
`; |
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,18 +1,62 @@ | ||
import React from "react"; | ||
import renderer from "react-test-renderer"; | ||
/* eslint-disable no-unused-vars */ | ||
import React, { useState } from "react"; | ||
import { useFakeTimers, SinonFakeTimers } from "sinon"; | ||
import { fireEvent, render } from "$test/utils"; | ||
import { Dialog } from "./index"; | ||
|
||
describe("rendering", () => { | ||
function getOverlay(container: Element) { | ||
return container.querySelector("[data-reach-dialog-overlay]"); | ||
} | ||
|
||
describe("<Dialog />", () => { | ||
let clock: SinonFakeTimers; | ||
beforeEach(() => { | ||
clock = useFakeTimers(); | ||
}); | ||
afterEach(() => { | ||
clock.restore(); | ||
}); | ||
|
||
it("does not render children when not open", () => { | ||
let wrapper = renderer.create( | ||
<div lang="gr"> | ||
const { baseElement, queryByTestId } = render( | ||
<div data-testid="root"> | ||
<Dialog isOpen={false} aria-label="cool dialog"> | ||
<div lang="en" /> | ||
<div data-testid="inner" /> | ||
</Dialog> | ||
</div> | ||
); | ||
expect(wrapper.root.findAllByProps({ lang: "gr" })).toHaveLength(1); | ||
expect(wrapper.root.findAllByProps({ lang: "en" })).toHaveLength(0); | ||
expect(wrapper.toJSON()).toMatchSnapshot(); | ||
expect(queryByTestId("root")).toBeTruthy(); | ||
expect(queryByTestId("inner")).toBeNull(); | ||
expect(baseElement).toMatchSnapshot(); | ||
}); | ||
|
||
it("closes the dialog", () => { | ||
const { baseElement, getByText, queryByTestId } = render( | ||
<BasicOpenDialog /> | ||
); | ||
expect(baseElement).toMatchSnapshot(); | ||
expect(queryByTestId("inner")).toBeTruthy(); | ||
fireEvent.click(getByText("Close Dialog")); | ||
// Not sure why clicking the overlay doesn't work in test env, works IRL 🤷♂️ | ||
// fireEvent.click(getOverlay(baseElement)!) | ||
clock.tick(10); | ||
expect(baseElement).toMatchSnapshot(); | ||
expect(queryByTestId("inner")).toBeNull(); | ||
}); | ||
}); | ||
|
||
function BasicOpenDialog() { | ||
const [showDialog, setShowDialog] = useState(true); | ||
return ( | ||
<div> | ||
<button onClick={() => setShowDialog(true)}>Show Dialog</button> | ||
<Dialog aria-label="Announcement" isOpen={showDialog}> | ||
<div data-testid="inner"> | ||
<button onClick={() => setShowDialog(false)}>Close Dialog</button> | ||
<input data-testid="text" type="text" /> | ||
<button data-testid="useless-button">Ayyyyyy</button> | ||
</div> | ||
</Dialog> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.