|
| 1 | +/* |
| 2 | +Copyright 2023 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 { isManagedHybridWidgetEnabled } from "../../src/widgets/ManagedHybrid"; |
| 18 | +import DMRoomMap from "../../src/utils/DMRoomMap"; |
| 19 | +import { stubClient } from "../test-utils"; |
| 20 | +import SdkConfig from "../../src/SdkConfig"; |
| 21 | + |
| 22 | +describe("isManagedHybridWidgetEnabled", () => { |
| 23 | + let dmRoomMap: DMRoomMap; |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + stubClient(); |
| 27 | + dmRoomMap = { |
| 28 | + getUserIdForRoomId: jest.fn().mockReturnValue("@user:server"), |
| 29 | + } as unknown as DMRoomMap; |
| 30 | + DMRoomMap.setShared(dmRoomMap); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should return false if widget_build_url is unset", () => { |
| 34 | + expect(isManagedHybridWidgetEnabled("!room:server")).toBeFalsy(); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should return true for DMs when widget_build_url_ignore_dm is unset", () => { |
| 38 | + SdkConfig.put({ |
| 39 | + widget_build_url: "https://url", |
| 40 | + }); |
| 41 | + expect(isManagedHybridWidgetEnabled("!room:server")).toBeTruthy(); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should return false for DMs when widget_build_url_ignore_dm is true", () => { |
| 45 | + SdkConfig.put({ |
| 46 | + widget_build_url: "https://url", |
| 47 | + widget_build_url_ignore_dm: true, |
| 48 | + }); |
| 49 | + expect(isManagedHybridWidgetEnabled("!room:server")).toBeFalsy(); |
| 50 | + }); |
| 51 | +}); |
0 commit comments