forked from element-hq/element-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoomListItemView.test.tsx
More file actions
135 lines (111 loc) · 4.22 KB
/
RoomListItemView.test.tsx
File metadata and controls
135 lines (111 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import React from "react";
import { render, screen } from "@test-utils";
import userEvent from "@testing-library/user-event";
import { composeStories } from "@storybook/react-vite";
import { describe, it, expect } from "vitest";
import * as stories from "./RoomListItemView.stories";
const {
Default,
Selected,
Bold,
WithNotification,
WithMention,
WithVoiceCall,
WithVideoCall,
Invitation,
UnsentMessage,
NoMessagePreview,
WithHoverMenu,
WithoutHoverMenu,
} = composeStories(stories);
describe("<RoomListItemView />", () => {
it("renders Default story", () => {
const { container } = render(<Default />);
expect(container).toMatchSnapshot();
});
it("renders Selected story", () => {
const { container } = render(<Selected />);
expect(container).toMatchSnapshot();
});
it("renders Bold story", () => {
const { container } = render(<Bold />);
expect(container).toMatchSnapshot();
});
it("renders WithNotification story", () => {
const { container } = render(<WithNotification />);
expect(container).toMatchSnapshot();
});
it("renders WithMention story", () => {
const { container } = render(<WithMention />);
expect(container).toMatchSnapshot();
});
it("renders WithVoiceCall story", () => {
const { container } = render(<WithVoiceCall />);
expect(container).toMatchSnapshot();
});
it("renders WithVideoCall story", () => {
const { container } = render(<WithVideoCall />);
expect(container).toMatchSnapshot();
});
it("renders Invitation story", () => {
const { container } = render(<Invitation />);
expect(container).toMatchSnapshot();
});
it("renders UnsentMessage story", () => {
const { container } = render(<UnsentMessage />);
expect(container).toMatchSnapshot();
});
it("renders NoMessagePreview story", () => {
const { container } = render(<NoMessagePreview />);
expect(container).toMatchSnapshot();
});
it("renders WithHoverMenu story", () => {
const { container } = render(<WithHoverMenu />);
expect(container).toMatchSnapshot();
});
it("should call onOpenRoom when clicked", async () => {
const user = userEvent.setup();
render(<Default />);
await user.click(screen.getByRole("option"));
expect(Default.args.onOpenRoom).toHaveBeenCalled();
});
it("should have aria-selected true when selected", () => {
render(<Selected />);
expect(screen.getByRole("option")).toHaveAttribute("aria-selected", "true");
});
it("should have aria-selected false when not selected", () => {
render(<Default />);
expect(screen.getByRole("option")).toHaveAttribute("aria-selected", "false");
});
it("should have tabIndex -1 when not focused", () => {
render(<Default />);
expect(screen.getByRole("option")).toHaveAttribute("tabIndex", "-1");
});
it("should call onFocus when focused", () => {
render(<Default />);
screen.getByRole("option").focus();
expect(Default.args.onFocus).toHaveBeenCalled();
});
it("should display notification decoration when present", () => {
render(<WithNotification />);
expect(screen.getByTestId("notification-decoration")).toBeInTheDocument();
});
it("should hide notification decoration when not present", () => {
render(<Default />);
expect(screen.queryByTestId("notification-decoration")).toBeNull();
});
it("should show hover menu when showMoreOptionsMenu is true", () => {
const { container } = render(<WithHoverMenu />);
expect(container.querySelector('[aria-label="More Options"]')).not.toBeNull();
});
it("should hide hover menu when showMoreOptionsMenu is false", () => {
const { container } = render(<WithoutHoverMenu />);
expect(container.querySelector('[aria-label="More Options"]')).toBeNull();
});
});