Skip to content

Commit 3325356

Browse files
committed
More tests for space creation
1 parent cd3a42f commit 3325356

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

test/unit-tests/components/structures/SpaceRoomView-test.tsx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Please see LICENSE files in the repository root for full details.
88
import React from "react";
99
import { mocked, type MockedObject } from "jest-mock";
1010
import { type MatrixClient, MatrixEvent, Preset, Room } from "matrix-js-sdk/src/matrix";
11-
import { render, cleanup, screen, fireEvent, waitFor } from "jest-matrix-react";
11+
import { render, cleanup, screen, fireEvent, waitFor, act } from "jest-matrix-react";
1212

1313
import { stubClient, mockPlatformPeg, unmockPlatformPeg, withClientContextRenderOptions } from "../../../test-utils";
1414
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases";
@@ -239,4 +239,52 @@ describe("SpaceRoomView", () => {
239239
expect(button).toHaveValue("Creating rooms…"); // Note the ellipsis
240240
});
241241
});
242+
243+
describe("Spaces: creating a new private space", () => {
244+
it("creates rooms inside a private space for a team", async () => {
245+
cli.createRoom.mockResolvedValueOnce({ room_id: "room1" }).mockResolvedValueOnce({ room_id: "room2" });
246+
SpaceStore.instance.addRoomToSpace = jest.fn();
247+
248+
// When I create a private space
249+
const view = await renderSpaceRoomView({
250+
createOpts: { preset: Preset.PrivateChat },
251+
name: "Private space",
252+
topic: "a private space for team A",
253+
});
254+
255+
// Then I am asked whether it's individual or team
256+
expect(view.getByRole("heading", { name: "Who are you working with?" })).toBeInTheDocument();
257+
258+
// And when I say team
259+
act(() =>
260+
view
261+
.getByRole("button", {
262+
name: "Me and my teammates A private space for you and your teammates",
263+
})
264+
.click(),
265+
);
266+
267+
// Then I am asked what rooms to create
268+
expect(view.getByRole("heading", { name: "What projects are your team working on?" })).toBeInTheDocument();
269+
270+
expect(view.getByPlaceholderText(/general/i)).toBeInTheDocument();
271+
expect(view.getByPlaceholderText(/random/i)).toBeInTheDocument();
272+
expect(view.getByPlaceholderText(/support/i)).toBeInTheDocument();
273+
274+
// And when I enter some room names
275+
const input1 = view.getAllByRole("textbox")[0];
276+
const input2 = view.getAllByRole("textbox")[1];
277+
fireEvent.change(input1, { target: { value: "Room 1" } });
278+
fireEvent.change(input2, { target: { value: "Room 2" } });
279+
280+
// And click "Continue"
281+
const button = view.getByRole("button", { name: "Continue" });
282+
fireEvent.click(button);
283+
284+
// Then the rooms are created
285+
await waitFor(() => {
286+
expect(cli.createRoom).toHaveBeenCalledTimes(2);
287+
});
288+
});
289+
});
242290
});

0 commit comments

Comments
 (0)