-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Move room name, avatar, and topic to IOpts. #30981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 3 commits
2c19ea6
640d343
6a455ac
499ad9e
1cc0224
2190957
5c3a6b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,10 @@ | |
|
||
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,57 @@ | |
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( | ||
Check failure on line 76 in test/unit-tests/components/views/dialogs/CreateRoomDialog-test.tsx
|
||
true, | ||
expect.objectContaining({ | ||
createOpts: 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( | ||
Check failure on line 99 in test/unit-tests/components/views/dialogs/CreateRoomDialog-test.tsx
|
||
true, | ||
expect.objectContaining({ | ||
createOpts: expect.objectContaining({ | ||
name: "NoFederate Room", | ||
creation_content: expect.objectContaining({ | ||
"m.federate": false, | ||
}), | ||
}), | ||
}), | ||
); | ||
}); | ||
|
||
describe("for a private room", () => { | ||
// default behaviour is a private room | ||
|
||
|
@@ -189,7 +240,7 @@ | |
const onFinished = jest.fn(); | ||
const { asFragment } = getComponent({ onFinished }); | ||
await flushPromises(); | ||
expect(asFragment()).toMatchSnapshot(); | ||
Check failure on line 243 in test/unit-tests/components/views/dialogs/CreateRoomDialog-test.tsx
|
||
|
||
const roomName = "Test Room Name"; | ||
fireEvent.change(screen.getByLabelText("Name"), { target: { value: roomName } }); | ||
|
@@ -198,9 +249,8 @@ | |
await flushPromises(); | ||
|
||
expect(onFinished).toHaveBeenCalledWith(true, { | ||
createOpts: { | ||
name: roomName, | ||
}, | ||
createOpts: {}, | ||
name: roomName, | ||
encryption: true, | ||
parentSpace: undefined, | ||
roomType: undefined, | ||
|
@@ -213,7 +263,7 @@ | |
); | ||
const { asFragment } = getComponent(); | ||
await flushPromises(); | ||
expect(asFragment()).toMatchSnapshot(); | ||
Check failure on line 266 in test/unit-tests/components/views/dialogs/CreateRoomDialog-test.tsx
|
||
}); | ||
}); | ||
|
||
|
@@ -259,9 +309,9 @@ | |
await flushPromises(); | ||
expect(onFinished).toHaveBeenCalledWith(true, { | ||
createOpts: { | ||
name: roomName, | ||
visibility: Visibility.Private, | ||
}, | ||
name: roomName, | ||
encryption: true, | ||
joinRule: JoinRule.Knock, | ||
parentSpace: undefined, | ||
|
@@ -277,9 +327,9 @@ | |
await flushPromises(); | ||
expect(onFinished).toHaveBeenCalledWith(true, { | ||
createOpts: { | ||
name: roomName, | ||
visibility: Visibility.Public, | ||
}, | ||
name: roomName, | ||
encryption: true, | ||
joinRule: JoinRule.Knock, | ||
parentSpace: undefined, | ||
|
@@ -349,15 +399,115 @@ | |
|
||
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( | ||
Check failure on line 433 in test/unit-tests/components/views/dialogs/CreateRoomDialog-test.tsx
|
||
true, | ||
expect.objectContaining({ | ||
createOpts: 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( | ||
Check failure on line 459 in test/unit-tests/components/views/dialogs/CreateRoomDialog-test.tsx
|
||
true, | ||
expect.objectContaining({ | ||
createOpts: expect.objectContaining({ | ||
name: "Public Room", | ||
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( | ||
Check failure on line 487 in test/unit-tests/components/views/dialogs/CreateRoomDialog-test.tsx
|
||
true, | ||
expect.objectContaining({ | ||
createOpts: 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); | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.