Test InviteModal
This commit is contained in:
@@ -14,19 +14,13 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { expect, test, vi } from "vitest";
|
||||
import { expect, test } 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>
|
||||
|
||||
@@ -98,6 +98,7 @@ export const Modal: FC<Props> = ({
|
||||
styles.drawer,
|
||||
{ [styles.tabbed]: tabbed },
|
||||
)}
|
||||
aria-describedby={undefined}
|
||||
{...rest}
|
||||
>
|
||||
<div className={styles.content}>
|
||||
@@ -120,7 +121,7 @@ export const Modal: FC<Props> = ({
|
||||
<DialogOverlay
|
||||
className={classNames(overlayStyles.bg, overlayStyles.animate)}
|
||||
/>
|
||||
<DialogContent asChild {...rest}>
|
||||
<DialogContent asChild aria-describedby={undefined} {...rest}>
|
||||
<Glass
|
||||
className={classNames(
|
||||
className,
|
||||
|
||||
44
src/room/InviteModal.test.tsx
Normal file
44
src/room/InviteModal.test.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
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 { render, screen } from "@testing-library/react";
|
||||
import { expect, test, vi } from "vitest";
|
||||
import { Room } from "matrix-js-sdk/src/matrix";
|
||||
import { axe } from "vitest-axe";
|
||||
import { BrowserRouter } from "react-router-dom";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
|
||||
import { InviteModal } from "./InviteModal";
|
||||
|
||||
// Used by copy-to-clipboard
|
||||
window.prompt = (): null => null;
|
||||
|
||||
test("InviteModal is accessible", async () => {
|
||||
const user = userEvent.setup();
|
||||
const room = {
|
||||
roomId: "!a:example.org",
|
||||
name: "Mission Control",
|
||||
} as unknown as Room;
|
||||
const onDismiss = vi.fn();
|
||||
const { container } = render(
|
||||
<InviteModal room={room} open={true} onDismiss={onDismiss} />,
|
||||
{ wrapper: BrowserRouter },
|
||||
);
|
||||
|
||||
expect(await axe(container)).toHaveNoViolations();
|
||||
await user.click(screen.getByRole("button", { name: "action.copy_link" }));
|
||||
expect(onDismiss).toBeCalled();
|
||||
});
|
||||
@@ -37,3 +37,11 @@ Config.initDefault();
|
||||
posthog.opt_out_capturing();
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
// Used by a lot of components
|
||||
window.matchMedia = global.matchMedia = (): MediaQueryList =>
|
||||
({
|
||||
matches: false,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
}) as Partial<MediaQueryList> as MediaQueryList;
|
||||
|
||||
Reference in New Issue
Block a user