|
| 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 { render, RenderResult } from "@testing-library/react"; |
| 19 | +import { MatrixClient } from "matrix-js-sdk/src/client"; |
| 20 | +import userEvent from "@testing-library/user-event"; |
| 21 | + |
| 22 | +import NotificationSettingsTab from "../../../../../../src/components/views/settings/tabs/room/NotificationSettingsTab"; |
| 23 | +import { mkStubRoom, stubClient } from "../../../../../test-utils"; |
| 24 | +import { MatrixClientPeg } from "../../../../../../src/MatrixClientPeg"; |
| 25 | +import { EchoChamber } from "../../../../../../src/stores/local-echo/EchoChamber"; |
| 26 | +import { RoomEchoChamber } from "../../../../../../src/stores/local-echo/RoomEchoChamber"; |
| 27 | + |
| 28 | +describe("NotificatinSettingsTab", () => { |
| 29 | + const roomId = "!room:example.com"; |
| 30 | + let cli: MatrixClient; |
| 31 | + let roomProps: RoomEchoChamber; |
| 32 | + |
| 33 | + const renderTab = (): RenderResult => { |
| 34 | + return render(<NotificationSettingsTab roomId={roomId} closeSettingsFn={() => { }} />); |
| 35 | + }; |
| 36 | + |
| 37 | + beforeEach(() => { |
| 38 | + stubClient(); |
| 39 | + cli = MatrixClientPeg.get(); |
| 40 | + const room = mkStubRoom(roomId, "test room", cli); |
| 41 | + roomProps = EchoChamber.forRoom(room); |
| 42 | + |
| 43 | + NotificationSettingsTab.contextType = React.createContext(cli); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should prevent »Settings« link click from bubbling up to radio buttons", async () => { |
| 47 | + const tab = renderTab(); |
| 48 | + |
| 49 | + // settings link of mentions_only volume |
| 50 | + const settingsLink = tab.container.querySelector( |
| 51 | + "label.mx_NotificationSettingsTab_mentionsKeywordsEntry div.mx_AccessibleButton"); |
| 52 | + if (!settingsLink) throw new Error("settings link does not exist."); |
| 53 | + |
| 54 | + await userEvent.click(settingsLink); |
| 55 | + |
| 56 | + expect(roomProps.notificationVolume).not.toBe("mentions_only"); |
| 57 | + }); |
| 58 | +}); |
0 commit comments