From 12b5676b682d593f99a8758d13008f64c19491ea Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 9 Mar 2023 09:57:06 +0000 Subject: [PATCH] Support dynamic room predecessors in StopGapWidgetDriver --- src/stores/widgets/StopGapWidgetDriver.ts | 3 +- .../widgets/StopGapWidgetDriver-test.ts | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index d38dc552889..dfd1ae50b80 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -61,6 +61,7 @@ import { ElementWidgetCapabilities } from "./ElementWidgetCapabilities"; import { navigateToPermalink } from "../../utils/permalinks/navigator"; import { SdkContextClass } from "../../contexts/SDKContext"; import { ModuleRunner } from "../../modules/ModuleRunner"; +import SettingsStore from "../../settings/SettingsStore"; // TODO: Purge this from the universe @@ -311,7 +312,7 @@ export class StopGapWidgetDriver extends WidgetDriver { const targetRooms = roomIds ? roomIds.includes(Symbols.AnyRoom) - ? client.getVisibleRooms() + ? client.getVisibleRooms(SettingsStore.getValue("feature_dynamic_room_predecessors")) : roomIds.map((r) => client.getRoom(r)) : [client.getRoom(SdkContextClass.instance.roomViewStore.getRoomId()!)]; return targetRooms.filter((r) => !!r) as Room[]; diff --git a/test/stores/widgets/StopGapWidgetDriver-test.ts b/test/stores/widgets/StopGapWidgetDriver-test.ts index 8d1e067d307..6bb82a065e9 100644 --- a/test/stores/widgets/StopGapWidgetDriver-test.ts +++ b/test/stores/widgets/StopGapWidgetDriver-test.ts @@ -40,6 +40,7 @@ import { StopGapWidgetDriver } from "../../../src/stores/widgets/StopGapWidgetDr import { stubClient } from "../../test-utils"; import { ModuleRunner } from "../../../src/modules/ModuleRunner"; import dis from "../../../src/dispatcher/dispatcher"; +import SettingsStore from "../../../src/settings/SettingsStore"; describe("StopGapWidgetDriver", () => { let client: MockedObject; @@ -366,4 +367,31 @@ describe("StopGapWidgetDriver", () => { expect(dis.dispatch).not.toHaveBeenCalled(); }); }); + + describe("If the feature_dynamic_room_predecessors feature is not enabled", () => { + beforeEach(() => { + jest.spyOn(SettingsStore, "getValue").mockReturnValue(false); + }); + + it("passes the flag through to getVisibleRooms", () => { + const driver = mkDefaultDriver(); + driver.readRoomEvents(EventType.CallAnswer, "", 0, ["*"]); + expect(client.getVisibleRooms).toHaveBeenCalledWith(false); + }); + }); + + describe("If the feature_dynamic_room_predecessors is enabled", () => { + beforeEach(() => { + // Turn on feature_dynamic_room_predecessors setting + jest.spyOn(SettingsStore, "getValue").mockImplementation( + (settingName) => settingName === "feature_dynamic_room_predecessors", + ); + }); + + it("passes the flag through to getVisibleRooms", () => { + const driver = mkDefaultDriver(); + driver.readRoomEvents(EventType.CallAnswer, "", 0, ["*"]); + expect(client.getVisibleRooms).toHaveBeenCalledWith(true); + }); + }); });