Move room name, avatar, and topic to IOpts. (#30981)
This commit is contained in:
@@ -8,10 +8,10 @@ Please see LICENSE files in the repository root for full details.
|
||||
|
||||
import React from "react";
|
||||
import { fireEvent, render, screen, within } from "jest-matrix-react";
|
||||
import { JoinRule, MatrixError, Preset, Visibility } from "matrix-js-sdk/src/matrix";
|
||||
import { type Room, JoinRule, MatrixError, Preset, Visibility } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import CreateRoomDialog from "../../../../../src/components/views/dialogs/CreateRoomDialog";
|
||||
import { flushPromises, getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../../test-utils";
|
||||
import { flushPromises, getMockClientWithEventEmitter, mkSpace, mockClientMethodsUser } from "../../../../test-utils";
|
||||
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
||||
import { UIFeature } from "../../../../../src/settings/UIFeature";
|
||||
|
||||
@@ -58,6 +58,55 @@ describe("<CreateRoomDialog />", () => {
|
||||
expect(screen.getByLabelText("Name")).toHaveDisplayValue(defaultName);
|
||||
});
|
||||
|
||||
it("should include topic in room creation options", async () => {
|
||||
const onFinished = jest.fn();
|
||||
render(<CreateRoomDialog onFinished={onFinished} />);
|
||||
await flushPromises();
|
||||
|
||||
const topic = "This is a test topic";
|
||||
|
||||
// Set room name and topic.
|
||||
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "Room with topic" } });
|
||||
fireEvent.change(screen.getByLabelText("Topic (optional)"), { target: { value: topic } });
|
||||
|
||||
// Create the room.
|
||||
fireEvent.click(screen.getByText("Create room"));
|
||||
await flushPromises();
|
||||
|
||||
expect(onFinished).toHaveBeenCalledWith(
|
||||
true,
|
||||
expect.objectContaining({
|
||||
name: "Room with topic",
|
||||
topic,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("should include no federate option in room creation options when enabled", async () => {
|
||||
const onFinished = jest.fn();
|
||||
render(<CreateRoomDialog onFinished={onFinished} />);
|
||||
await flushPromises();
|
||||
|
||||
// Set room name, and disable federation.
|
||||
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "NoFederate Room" } });
|
||||
fireEvent.click(screen.getByLabelText("Block anyone not part of server.org from ever joining this room."));
|
||||
|
||||
fireEvent.click(screen.getByText("Create room"));
|
||||
await flushPromises();
|
||||
|
||||
expect(onFinished).toHaveBeenCalledWith(
|
||||
true,
|
||||
expect.objectContaining({
|
||||
name: "NoFederate Room",
|
||||
createOpts: expect.objectContaining({
|
||||
creation_content: expect.objectContaining({
|
||||
"m.federate": false,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
describe("for a private room", () => {
|
||||
// default behaviour is a private room
|
||||
|
||||
@@ -198,9 +247,8 @@ describe("<CreateRoomDialog />", () => {
|
||||
await flushPromises();
|
||||
|
||||
expect(onFinished).toHaveBeenCalledWith(true, {
|
||||
createOpts: {
|
||||
name: roomName,
|
||||
},
|
||||
createOpts: {},
|
||||
name: roomName,
|
||||
encryption: true,
|
||||
parentSpace: undefined,
|
||||
roomType: undefined,
|
||||
@@ -259,9 +307,9 @@ describe("<CreateRoomDialog />", () => {
|
||||
await flushPromises();
|
||||
expect(onFinished).toHaveBeenCalledWith(true, {
|
||||
createOpts: {
|
||||
name: roomName,
|
||||
visibility: Visibility.Private,
|
||||
},
|
||||
name: roomName,
|
||||
encryption: true,
|
||||
joinRule: JoinRule.Knock,
|
||||
parentSpace: undefined,
|
||||
@@ -277,9 +325,9 @@ describe("<CreateRoomDialog />", () => {
|
||||
await flushPromises();
|
||||
expect(onFinished).toHaveBeenCalledWith(true, {
|
||||
createOpts: {
|
||||
name: roomName,
|
||||
visibility: Visibility.Public,
|
||||
},
|
||||
name: roomName,
|
||||
encryption: true,
|
||||
joinRule: JoinRule.Knock,
|
||||
parentSpace: undefined,
|
||||
@@ -349,15 +397,111 @@ describe("<CreateRoomDialog />", () => {
|
||||
|
||||
expect(onFinished).toHaveBeenCalledWith(true, {
|
||||
createOpts: {
|
||||
name: roomName,
|
||||
preset: Preset.PublicChat,
|
||||
room_alias_name: roomAlias,
|
||||
visibility: Visibility.Public,
|
||||
},
|
||||
name: roomName,
|
||||
guestAccess: false,
|
||||
parentSpace: undefined,
|
||||
roomType: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("for a room in a space", () => {
|
||||
let parentSpace: Room;
|
||||
beforeEach(() => {
|
||||
parentSpace = mkSpace(mockClient, "!space:server") as unknown as Room;
|
||||
});
|
||||
|
||||
it("should create a room with restricted join rule when selected", async () => {
|
||||
const onFinished = jest.fn();
|
||||
render(<CreateRoomDialog parentSpace={parentSpace} onFinished={onFinished} />);
|
||||
await flushPromises();
|
||||
|
||||
// Set room name and visibility.
|
||||
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "Restricted Room" } });
|
||||
fireEvent.click(screen.getByLabelText("Room visibility"));
|
||||
fireEvent.click(screen.getByRole("option", { name: "Visible to space members" }));
|
||||
|
||||
fireEvent.click(screen.getByText("Create room"));
|
||||
await flushPromises();
|
||||
|
||||
expect(onFinished).toHaveBeenCalledWith(
|
||||
true,
|
||||
expect.objectContaining({
|
||||
name: "Restricted Room",
|
||||
joinRule: JoinRule.Restricted,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("should create a room with public join rule when selected", async () => {
|
||||
const onFinished = jest.fn();
|
||||
render(<CreateRoomDialog parentSpace={parentSpace} onFinished={onFinished} />);
|
||||
await flushPromises();
|
||||
|
||||
// Set room name and visibility. Rooms in spaces also need an address.
|
||||
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "Public Room" } });
|
||||
fireEvent.click(screen.getByLabelText("Room visibility"));
|
||||
fireEvent.click(screen.getByRole("option", { name: "Public room" }));
|
||||
fireEvent.change(screen.getByLabelText("Room address"), { target: { value: "testroom" } });
|
||||
|
||||
// Create the room.
|
||||
fireEvent.click(screen.getByText("Create room"));
|
||||
await flushPromises();
|
||||
|
||||
expect(onFinished).toHaveBeenCalledWith(
|
||||
true,
|
||||
expect.objectContaining({
|
||||
name: "Public Room",
|
||||
createOpts: expect.objectContaining({
|
||||
room_alias_name: "testroom",
|
||||
visibility: Visibility.Public,
|
||||
preset: Preset.PublicChat,
|
||||
}),
|
||||
guestAccess: false,
|
||||
roomType: undefined,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("keyboard shortcuts", () => {
|
||||
it("should submit the form when Enter is pressed", async () => {
|
||||
const onFinished = jest.fn();
|
||||
render(<CreateRoomDialog onFinished={onFinished} />);
|
||||
await flushPromises();
|
||||
|
||||
// Simulate pressing the Enter key.
|
||||
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "Keyboard Room" } });
|
||||
fireEvent.keyDown(screen.getByLabelText("Name"), { key: "Enter", code: "Enter", charCode: 13 });
|
||||
|
||||
await flushPromises();
|
||||
|
||||
expect(onFinished).toHaveBeenCalledWith(
|
||||
true,
|
||||
expect.objectContaining({
|
||||
name: "Keyboard Room",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("should cancel the dialog when Escape is pressed", async () => {
|
||||
const onFinished = jest.fn();
|
||||
render(<CreateRoomDialog onFinished={onFinished} />);
|
||||
await flushPromises();
|
||||
|
||||
// Simulate pressing the Escape key.
|
||||
fireEvent.keyDown(screen.getByLabelText("Name"), { key: "Escape", code: "Escape", charCode: 27 });
|
||||
|
||||
await flushPromises();
|
||||
|
||||
// BaseDialog passes no arguments, but DialogButtons pass false - might not be desirable?
|
||||
expect(onFinished).toHaveBeenCalled();
|
||||
const callArgs = onFinished.mock.calls[0];
|
||||
expect(callArgs.length === 0 || callArgs[0] === false).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,14 +32,14 @@ exports[`<CreateRoomDialog /> for a private room should create a private room 1`
|
||||
class="mx_Field mx_Field_input mx_CreateRoomDialog_name"
|
||||
>
|
||||
<input
|
||||
id="mx_Field_21"
|
||||
id="mx_Field_25"
|
||||
label="Name"
|
||||
placeholder="Name"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
<label
|
||||
for="mx_Field_21"
|
||||
for="mx_Field_25"
|
||||
>
|
||||
Name
|
||||
</label>
|
||||
@@ -48,14 +48,14 @@ exports[`<CreateRoomDialog /> for a private room should create a private room 1`
|
||||
class="mx_Field mx_Field_input mx_CreateRoomDialog_topic"
|
||||
>
|
||||
<input
|
||||
id="mx_Field_22"
|
||||
id="mx_Field_26"
|
||||
label="Topic (optional)"
|
||||
placeholder="Topic (optional)"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
<label
|
||||
for="mx_Field_22"
|
||||
for="mx_Field_26"
|
||||
>
|
||||
Topic (optional)
|
||||
</label>
|
||||
@@ -98,7 +98,7 @@ exports[`<CreateRoomDialog /> for a private room should create a private room 1`
|
||||
class="mx_SettingsFlag_label"
|
||||
>
|
||||
<div
|
||||
id="mx_LabelledToggleSwitch__r_4m_"
|
||||
id="mx_LabelledToggleSwitch__r_5i_"
|
||||
>
|
||||
Enable end-to-end encryption
|
||||
</div>
|
||||
@@ -106,7 +106,7 @@ exports[`<CreateRoomDialog /> for a private room should create a private room 1`
|
||||
<div
|
||||
aria-checked="true"
|
||||
aria-disabled="false"
|
||||
aria-labelledby="mx_LabelledToggleSwitch__r_4m_"
|
||||
aria-labelledby="mx_LabelledToggleSwitch__r_5i_"
|
||||
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
|
||||
role="switch"
|
||||
tabindex="0"
|
||||
@@ -134,7 +134,7 @@ exports[`<CreateRoomDialog /> for a private room should create a private room 1`
|
||||
class="mx_SettingsFlag_label"
|
||||
>
|
||||
<div
|
||||
id="mx_LabelledToggleSwitch__r_4n_"
|
||||
id="mx_LabelledToggleSwitch__r_5j_"
|
||||
>
|
||||
Block anyone not part of server.org from ever joining this room.
|
||||
</div>
|
||||
@@ -142,7 +142,7 @@ exports[`<CreateRoomDialog /> for a private room should create a private room 1`
|
||||
<div
|
||||
aria-checked="false"
|
||||
aria-disabled="false"
|
||||
aria-labelledby="mx_LabelledToggleSwitch__r_4n_"
|
||||
aria-labelledby="mx_LabelledToggleSwitch__r_5j_"
|
||||
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
|
||||
role="switch"
|
||||
tabindex="0"
|
||||
@@ -226,14 +226,14 @@ exports[`<CreateRoomDialog /> for a private room should render not the advanced
|
||||
class="mx_Field mx_Field_input mx_CreateRoomDialog_name"
|
||||
>
|
||||
<input
|
||||
id="mx_Field_23"
|
||||
id="mx_Field_27"
|
||||
label="Name"
|
||||
placeholder="Name"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
<label
|
||||
for="mx_Field_23"
|
||||
for="mx_Field_27"
|
||||
>
|
||||
Name
|
||||
</label>
|
||||
@@ -242,14 +242,14 @@ exports[`<CreateRoomDialog /> for a private room should render not the advanced
|
||||
class="mx_Field mx_Field_input mx_CreateRoomDialog_topic"
|
||||
>
|
||||
<input
|
||||
id="mx_Field_24"
|
||||
id="mx_Field_28"
|
||||
label="Topic (optional)"
|
||||
placeholder="Topic (optional)"
|
||||
type="text"
|
||||
value=""
|
||||
/>
|
||||
<label
|
||||
for="mx_Field_24"
|
||||
for="mx_Field_28"
|
||||
>
|
||||
Topic (optional)
|
||||
</label>
|
||||
@@ -292,7 +292,7 @@ exports[`<CreateRoomDialog /> for a private room should render not the advanced
|
||||
class="mx_SettingsFlag_label"
|
||||
>
|
||||
<div
|
||||
id="mx_LabelledToggleSwitch__r_54_"
|
||||
id="mx_LabelledToggleSwitch__r_60_"
|
||||
>
|
||||
Enable end-to-end encryption
|
||||
</div>
|
||||
@@ -300,7 +300,7 @@ exports[`<CreateRoomDialog /> for a private room should render not the advanced
|
||||
<div
|
||||
aria-checked="true"
|
||||
aria-disabled="false"
|
||||
aria-labelledby="mx_LabelledToggleSwitch__r_54_"
|
||||
aria-labelledby="mx_LabelledToggleSwitch__r_60_"
|
||||
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_on mx_ToggleSwitch_enabled"
|
||||
role="switch"
|
||||
tabindex="0"
|
||||
|
||||
Reference in New Issue
Block a user