Skip to content

Commit 9a31517

Browse files
committed
test: add tests
1 parent 3fddb9d commit 9a31517

File tree

2 files changed

+364
-1
lines changed

2 files changed

+364
-1
lines changed

test/unit-tests/components/views/dialogs/CreateRoomDialog-test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { JoinRule, MatrixError, Preset, Visibility } from "matrix-js-sdk/src/mat
1313
import CreateRoomDialog from "../../../../../src/components/views/dialogs/CreateRoomDialog";
1414
import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../test-utils";
1515
import SettingsStore from "../../../../../src/settings/SettingsStore";
16+
import { UIFeature } from "../../../../../src/settings/UIFeature";
1617

1718
describe("<CreateRoomDialog />", () => {
1819
const userId = "@alice:server.org";
@@ -181,8 +182,9 @@ describe("<CreateRoomDialog />", () => {
181182

182183
it("should create a private room", async () => {
183184
const onFinished = jest.fn();
184-
getComponent({ onFinished });
185+
const { asFragment } = getComponent({ onFinished });
185186
await flushPromises();
187+
expect(asFragment()).toMatchSnapshot();
186188

187189
const roomName = "Test Room Name";
188190
fireEvent.change(screen.getByLabelText("Name"), { target: { value: roomName } });
@@ -199,6 +201,15 @@ describe("<CreateRoomDialog />", () => {
199201
roomType: undefined,
200202
});
201203
});
204+
205+
it("should render not the advanced options when UI.advancedSettings is disabled", async () => {
206+
jest.spyOn(SettingsStore, "getValue").mockImplementation(
207+
(setting) => setting !== UIFeature.AdvancedSettings,
208+
);
209+
const { asFragment } = getComponent();
210+
await flushPromises();
211+
expect(asFragment()).toMatchSnapshot();
212+
});
202213
});
203214

204215
describe("for a knock room", () => {
Lines changed: 352 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,352 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<CreateRoomDialog /> for a private room should create a private room 1`] = `
4+
<DocumentFragment>
5+
<div
6+
data-focus-guard="true"
7+
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
8+
tabindex="0"
9+
/>
10+
<div
11+
aria-labelledby="mx_BaseDialog_title"
12+
class="mx_CreateRoomDialog mx_Dialog_fixedWidth"
13+
data-focus-lock-disabled="false"
14+
role="dialog"
15+
tabindex="-1"
16+
>
17+
<div
18+
class="mx_Dialog_header"
19+
>
20+
<h1
21+
class="mx_Heading_h3 mx_Dialog_title"
22+
id="mx_BaseDialog_title"
23+
>
24+
Create a private room
25+
</h1>
26+
</div>
27+
<form>
28+
<div
29+
class="mx_Dialog_content"
30+
>
31+
<div
32+
class="mx_Field mx_Field_input mx_CreateRoomDialog_name"
33+
>
34+
<input
35+
id="mx_Field_21"
36+
label="Name"
37+
placeholder="Name"
38+
type="text"
39+
value=""
40+
/>
41+
<label
42+
for="mx_Field_21"
43+
>
44+
Name
45+
</label>
46+
</div>
47+
<div
48+
class="mx_Field mx_Field_input mx_CreateRoomDialog_topic"
49+
>
50+
<input
51+
id="mx_Field_22"
52+
label="Topic (optional)"
53+
placeholder="Topic (optional)"
54+
type="text"
55+
value=""
56+
/>
57+
<label
58+
for="mx_Field_22"
59+
>
60+
Topic (optional)
61+
</label>
62+
</div>
63+
<div
64+
class="mx_Dropdown mx_JoinRuleDropdown"
65+
>
66+
<div
67+
aria-describedby="mx_JoinRuleDropdown_value"
68+
aria-expanded="false"
69+
aria-haspopup="listbox"
70+
aria-label="Room visibility"
71+
aria-owns="mx_JoinRuleDropdown_input"
72+
class="mx_AccessibleButton mx_Dropdown_input mx_no_textinput"
73+
role="button"
74+
tabindex="0"
75+
>
76+
<div
77+
class="mx_Dropdown_option"
78+
id="mx_JoinRuleDropdown_value"
79+
>
80+
<div
81+
class="mx_JoinRuleDropdown_invite"
82+
>
83+
Private room (invite only)
84+
</div>
85+
</div>
86+
<span
87+
class="mx_Dropdown_arrow"
88+
/>
89+
</div>
90+
</div>
91+
<p>
92+
Only people invited will be able to find and join this room. You can change this at any time from room settings.
93+
</p>
94+
<div
95+
class="mx_SettingsFlag mx_CreateRoomDialog_e2eSwitch"
96+
>
97+
<span
98+
class="mx_SettingsFlag_label"
99+
>
100+
<div
101+
id="mx_LabelledToggleSwitch_«r4m»"
102+
>
103+
Enable end-to-end encryption
104+
</div>
105+
</span>
106+
<div
107+
aria-checked="true"
108+
aria-disabled="false"
109+
aria-labelledby="mx_LabelledToggleSwitch_«r4m»"
110+
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
111+
role="switch"
112+
tabindex="0"
113+
>
114+
<div
115+
class="mx_ToggleSwitch_ball"
116+
/>
117+
</div>
118+
</div>
119+
<p>
120+
You can't disable this later. Bridges & most bots won't work yet.
121+
</p>
122+
<details
123+
class="mx_CreateRoomDialog_details"
124+
>
125+
<summary
126+
class="mx_CreateRoomDialog_details_summary"
127+
>
128+
Show advanced
129+
</summary>
130+
<div
131+
class="mx_SettingsFlag"
132+
>
133+
<span
134+
class="mx_SettingsFlag_label"
135+
>
136+
<div
137+
id="mx_LabelledToggleSwitch_«r4n»"
138+
>
139+
Block anyone not part of server.org from ever joining this room.
140+
</div>
141+
</span>
142+
<div
143+
aria-checked="false"
144+
aria-disabled="false"
145+
aria-labelledby="mx_LabelledToggleSwitch_«r4n»"
146+
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
147+
role="switch"
148+
tabindex="0"
149+
>
150+
<div
151+
class="mx_ToggleSwitch_ball"
152+
/>
153+
</div>
154+
</div>
155+
<p>
156+
You might enable this if the room will only be used for collaborating with internal teams on your homeserver. This cannot be changed later.
157+
</p>
158+
</details>
159+
</div>
160+
</form>
161+
<div
162+
class="mx_Dialog_buttons"
163+
>
164+
<span
165+
class="mx_Dialog_buttons_row"
166+
>
167+
<button
168+
data-testid="dialog-cancel-button"
169+
type="button"
170+
>
171+
Cancel
172+
</button>
173+
<button
174+
class="mx_Dialog_primary"
175+
data-testid="dialog-primary-button"
176+
type="button"
177+
>
178+
Create room
179+
</button>
180+
</span>
181+
</div>
182+
<div
183+
aria-label="Close dialog"
184+
class="mx_AccessibleButton mx_Dialog_cancelButton"
185+
role="button"
186+
tabindex="0"
187+
/>
188+
</div>
189+
<div
190+
data-focus-guard="true"
191+
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
192+
tabindex="0"
193+
/>
194+
</DocumentFragment>
195+
`;
196+
197+
exports[`<CreateRoomDialog /> for a private room should render not the advanced options when UI.advancedSettings is disabled 1`] = `
198+
<DocumentFragment>
199+
<div
200+
data-focus-guard="true"
201+
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
202+
tabindex="0"
203+
/>
204+
<div
205+
aria-labelledby="mx_BaseDialog_title"
206+
class="mx_CreateRoomDialog mx_Dialog_fixedWidth"
207+
data-focus-lock-disabled="false"
208+
role="dialog"
209+
tabindex="-1"
210+
>
211+
<div
212+
class="mx_Dialog_header"
213+
>
214+
<h1
215+
class="mx_Heading_h3 mx_Dialog_title"
216+
id="mx_BaseDialog_title"
217+
>
218+
Create a private room
219+
</h1>
220+
</div>
221+
<form>
222+
<div
223+
class="mx_Dialog_content"
224+
>
225+
<div
226+
class="mx_Field mx_Field_input mx_CreateRoomDialog_name"
227+
>
228+
<input
229+
id="mx_Field_23"
230+
label="Name"
231+
placeholder="Name"
232+
type="text"
233+
value=""
234+
/>
235+
<label
236+
for="mx_Field_23"
237+
>
238+
Name
239+
</label>
240+
</div>
241+
<div
242+
class="mx_Field mx_Field_input mx_CreateRoomDialog_topic"
243+
>
244+
<input
245+
id="mx_Field_24"
246+
label="Topic (optional)"
247+
placeholder="Topic (optional)"
248+
type="text"
249+
value=""
250+
/>
251+
<label
252+
for="mx_Field_24"
253+
>
254+
Topic (optional)
255+
</label>
256+
</div>
257+
<div
258+
class="mx_Dropdown mx_JoinRuleDropdown"
259+
>
260+
<div
261+
aria-describedby="mx_JoinRuleDropdown_value"
262+
aria-expanded="false"
263+
aria-haspopup="listbox"
264+
aria-label="Room visibility"
265+
aria-owns="mx_JoinRuleDropdown_input"
266+
class="mx_AccessibleButton mx_Dropdown_input mx_no_textinput"
267+
role="button"
268+
tabindex="0"
269+
>
270+
<div
271+
class="mx_Dropdown_option"
272+
id="mx_JoinRuleDropdown_value"
273+
>
274+
<div
275+
class="mx_JoinRuleDropdown_invite"
276+
>
277+
Private room (invite only)
278+
</div>
279+
</div>
280+
<span
281+
class="mx_Dropdown_arrow"
282+
/>
283+
</div>
284+
</div>
285+
<p>
286+
Only people invited will be able to find and join this room. You can change this at any time from room settings.
287+
</p>
288+
<div
289+
class="mx_SettingsFlag mx_CreateRoomDialog_e2eSwitch"
290+
>
291+
<span
292+
class="mx_SettingsFlag_label"
293+
>
294+
<div
295+
id="mx_LabelledToggleSwitch_«r54»"
296+
>
297+
Enable end-to-end encryption
298+
</div>
299+
</span>
300+
<div
301+
aria-checked="true"
302+
aria-disabled="false"
303+
aria-labelledby="mx_LabelledToggleSwitch_«r54»"
304+
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
305+
role="switch"
306+
tabindex="0"
307+
>
308+
<div
309+
class="mx_ToggleSwitch_ball"
310+
/>
311+
</div>
312+
</div>
313+
<p>
314+
You can't disable this later. Bridges & most bots won't work yet.
315+
</p>
316+
</div>
317+
</form>
318+
<div
319+
class="mx_Dialog_buttons"
320+
>
321+
<span
322+
class="mx_Dialog_buttons_row"
323+
>
324+
<button
325+
data-testid="dialog-cancel-button"
326+
type="button"
327+
>
328+
Cancel
329+
</button>
330+
<button
331+
class="mx_Dialog_primary"
332+
data-testid="dialog-primary-button"
333+
type="button"
334+
>
335+
Create room
336+
</button>
337+
</span>
338+
</div>
339+
<div
340+
aria-label="Close dialog"
341+
class="mx_AccessibleButton mx_Dialog_cancelButton"
342+
role="button"
343+
tabindex="0"
344+
/>
345+
</div>
346+
<div
347+
data-focus-guard="true"
348+
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
349+
tabindex="0"
350+
/>
351+
</DocumentFragment>
352+
`;

0 commit comments

Comments
 (0)