|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import React from "react"; |
| 18 | +import { fireEvent, render, RenderResult } from "@testing-library/react"; |
| 19 | +import { EventType, MatrixClient } from "matrix-js-sdk/src/matrix"; |
| 20 | + |
| 21 | +import RolesRoomSettingsTab from "../../../../../../src/components/views/settings/tabs/room/RolesRoomSettingsTab"; |
| 22 | +import { mkStubRoom, stubClient } from "../../../../../test-utils"; |
| 23 | +import { MatrixClientPeg } from "../../../../../../src/MatrixClientPeg"; |
| 24 | +import { VoiceBroadcastInfoEventType } from "../../../../../../src/voice-broadcast"; |
| 25 | + |
| 26 | +describe("RolesRoomSettingsTab", () => { |
| 27 | + const roomId = "!room:example.com"; |
| 28 | + let rolesRoomSettingsTab: RenderResult; |
| 29 | + let cli: MatrixClient; |
| 30 | + |
| 31 | + const getVoiceBroadcastsSelect = () => { |
| 32 | + return rolesRoomSettingsTab.container.querySelector("select[label='Voice broadcasts']"); |
| 33 | + }; |
| 34 | + |
| 35 | + const getVoiceBroadcastsSelectedOption = () => { |
| 36 | + return rolesRoomSettingsTab.container.querySelector("select[label='Voice broadcasts'] option:checked"); |
| 37 | + }; |
| 38 | + |
| 39 | + beforeEach(() => { |
| 40 | + stubClient(); |
| 41 | + cli = MatrixClientPeg.get(); |
| 42 | + rolesRoomSettingsTab = render(<RolesRoomSettingsTab roomId={roomId} />); |
| 43 | + mkStubRoom(roomId, "test room", cli); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should initially show »Moderator« permission for »Voice broadcasts«", () => { |
| 47 | + expect(getVoiceBroadcastsSelectedOption().textContent).toBe("Moderator"); |
| 48 | + }); |
| 49 | + |
| 50 | + describe("when setting »Default« permission for »Voice broadcasts«", () => { |
| 51 | + beforeEach(() => { |
| 52 | + fireEvent.change(getVoiceBroadcastsSelect(), { |
| 53 | + target: { value: 0 }, |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + it("should update the power levels", () => { |
| 58 | + expect(cli.sendStateEvent).toHaveBeenCalledWith( |
| 59 | + roomId, |
| 60 | + EventType.RoomPowerLevels, |
| 61 | + { |
| 62 | + events: { |
| 63 | + [VoiceBroadcastInfoEventType]: 0, |
| 64 | + }, |
| 65 | + }, |
| 66 | + ); |
| 67 | + }); |
| 68 | + }); |
| 69 | +}); |
0 commit comments