mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-04 23:05:50 +00:00
add back toast tests
This commit is contained in:
@@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import { describe, expect, test, vi } from "vitest";
|
import { describe, expect, test, vi } from "vitest";
|
||||||
import { render, configure } from "@testing-library/react";
|
import { render, configure } from "@testing-library/react";
|
||||||
|
import userEvent from "@testing-library/user-event";
|
||||||
|
|
||||||
import { Toast } from "../src/Toast";
|
import { Toast } from "../src/Toast";
|
||||||
import { withFakeTimers } from "./utils/test";
|
import { withFakeTimers } from "./utils/test";
|
||||||
@@ -24,6 +25,9 @@ configure({
|
|||||||
defaultHidden: true,
|
defaultHidden: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test Explanation:
|
||||||
|
// This test the toast. We need to use { document: window.document } because the toast listens
|
||||||
|
// for user input on `window`.
|
||||||
describe("Toast", () => {
|
describe("Toast", () => {
|
||||||
test("renders", () => {
|
test("renders", () => {
|
||||||
const { queryByRole } = render(
|
const { queryByRole } = render(
|
||||||
@@ -40,6 +44,33 @@ describe("Toast", () => {
|
|||||||
expect(getByRole("dialog")).toMatchSnapshot();
|
expect(getByRole("dialog")).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("dismisses when Esc is pressed", async () => {
|
||||||
|
const user = userEvent.setup({ document: window.document });
|
||||||
|
const onDismiss = vi.fn();
|
||||||
|
const { debug } = render(
|
||||||
|
<Toast open={true} onDismiss={onDismiss}>
|
||||||
|
Hello world!
|
||||||
|
</Toast>,
|
||||||
|
);
|
||||||
|
debug();
|
||||||
|
await user.keyboard("[Escape]");
|
||||||
|
expect(onDismiss).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("dismisses when background is clicked", async () => {
|
||||||
|
const user = userEvent.setup();
|
||||||
|
const onDismiss = vi.fn();
|
||||||
|
const { getByRole, unmount } = render(
|
||||||
|
<Toast open={true} onDismiss={onDismiss}>
|
||||||
|
Hello world!
|
||||||
|
</Toast>,
|
||||||
|
);
|
||||||
|
const background = getByRole("dialog").previousSibling! as Element;
|
||||||
|
await user.click(background);
|
||||||
|
expect(onDismiss).toHaveBeenCalled();
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
test("dismisses itself after the specified timeout", () => {
|
test("dismisses itself after the specified timeout", () => {
|
||||||
withFakeTimers(() => {
|
withFakeTimers(() => {
|
||||||
const onDismiss = vi.fn();
|
const onDismiss = vi.fn();
|
||||||
|
|||||||
Reference in New Issue
Block a user