Test RoomHeaderInfo
This commit is contained in:
45
src/Header.test.tsx
Normal file
45
src/Header.test.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { expect, test, vi } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { axe } from "vitest-axe";
|
||||
import { TooltipProvider } from "@vector-im/compound-web";
|
||||
|
||||
import { RoomHeaderInfo } from "./Header";
|
||||
|
||||
global.matchMedia = vi.fn().mockReturnValue({
|
||||
matches: true,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
});
|
||||
|
||||
test("RoomHeaderInfo is accessible", async () => {
|
||||
const { container } = render(
|
||||
<TooltipProvider>
|
||||
<RoomHeaderInfo
|
||||
id="!a:example.org"
|
||||
name="Mission Control"
|
||||
avatarUrl=""
|
||||
encrypted
|
||||
participantCount={11}
|
||||
/>
|
||||
</TooltipProvider>,
|
||||
);
|
||||
expect(await axe(container)).toHaveNoViolations();
|
||||
// Check that the room name acts as a heading
|
||||
screen.getByRole("heading", { name: "Mission Control" });
|
||||
});
|
||||
@@ -15,19 +15,12 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { render, configure } from "@testing-library/react";
|
||||
import { render } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
import { Toast } from "../src/Toast";
|
||||
import { withFakeTimers } from "./utils/test";
|
||||
|
||||
configure({
|
||||
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", () => {
|
||||
test("renders", () => {
|
||||
const { queryByRole } = render(
|
||||
@@ -45,7 +38,7 @@ describe("Toast", () => {
|
||||
});
|
||||
|
||||
test("dismisses when Esc is pressed", async () => {
|
||||
const user = userEvent.setup({ document: window.document });
|
||||
const user = userEvent.setup();
|
||||
const onDismiss = vi.fn();
|
||||
render(
|
||||
<Toast open={true} onDismiss={onDismiss}>
|
||||
@@ -59,7 +52,7 @@ describe("Toast", () => {
|
||||
test("dismisses when background is clicked", async () => {
|
||||
const user = userEvent.setup();
|
||||
const onDismiss = vi.fn();
|
||||
const { getByRole, unmount } = render(
|
||||
const { getByRole } = render(
|
||||
<Toast open={true} onDismiss={onDismiss}>
|
||||
Hello world!
|
||||
</Toast>,
|
||||
@@ -67,7 +60,6 @@ describe("Toast", () => {
|
||||
const background = getByRole("dialog").previousSibling! as Element;
|
||||
await user.click(background);
|
||||
expect(onDismiss).toHaveBeenCalled();
|
||||
unmount();
|
||||
});
|
||||
|
||||
test("dismisses itself after the specified timeout", () => {
|
||||
|
||||
@@ -13,13 +13,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import "global-jsdom/register";
|
||||
import globalJsdom from "global-jsdom";
|
||||
import i18n from "i18next";
|
||||
import posthog from "posthog-js";
|
||||
import { initReactI18next } from "react-i18next";
|
||||
import { afterEach, beforeEach } from "vitest";
|
||||
import { afterEach } from "vitest";
|
||||
import { cleanup } from "@testing-library/react";
|
||||
import "vitest-axe/extend-expect";
|
||||
|
||||
import { Config } from "./config/Config";
|
||||
|
||||
@@ -35,12 +36,4 @@ i18n.use(initReactI18next).init({
|
||||
Config.initDefault();
|
||||
posthog.opt_out_capturing();
|
||||
|
||||
// We need to cleanup the global jsDom
|
||||
// Otherwise we will run into issues with async input test overlapping and throwing.
|
||||
|
||||
let cleanupJsDom: { (): void };
|
||||
beforeEach(() => (cleanupJsDom = globalJsdom()));
|
||||
afterEach(() => {
|
||||
cleanupJsDom();
|
||||
cleanup();
|
||||
});
|
||||
afterEach(cleanup);
|
||||
|
||||
Reference in New Issue
Block a user