Support dynamic room predecessors in OwnBeaconStore (#10339)

* Support dynamic room predecessors in OwnBeaconStore

* Fix type of dynamicWatcherRef

* Mock a function missing from client
This commit is contained in:
Andy Balaam 2023-03-10 09:15:54 +00:00 committed by GitHub
parent 50229abf1e
commit b646250c90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 1 deletions

View file

@ -44,6 +44,7 @@ describe("<RoomLiveShareWarning />", () => {
getUserId: jest.fn().mockReturnValue(aliceId),
unstable_setLiveBeacon: jest.fn().mockResolvedValue({ event_id: "1" }),
sendEvent: jest.fn(),
isGuest: jest.fn().mockReturnValue(false),
});
// 14.03.2022 16:15

View file

@ -38,6 +38,7 @@ import {
} from "../test-utils";
import { makeBeaconInfoEvent, mockGeolocation, watchPositionMockImplementation } from "../test-utils/beacon";
import { getMockClientWithEventEmitter } from "../test-utils/client";
import SettingsStore from "../../src/settings/SettingsStore";
// modern fake timers and lodash.debounce are a faff
// short circuit it
@ -62,6 +63,7 @@ describe("OwnBeaconStore", () => {
unstable_setLiveBeacon: jest.fn().mockResolvedValue({ event_id: "1" }),
sendEvent: jest.fn().mockResolvedValue({ event_id: "1" }),
unstable_createLiveBeacon: jest.fn().mockResolvedValue({ event_id: "1" }),
isGuest: jest.fn().mockReturnValue(false),
});
const room1Id = "$room1:server.org";
const room2Id = "$room2:server.org";
@ -1204,4 +1206,41 @@ describe("OwnBeaconStore", () => {
expect(mockClient.unstable_createLiveBeacon).toHaveBeenCalledWith(room1Id, content);
});
});
describe("If the feature_dynamic_room_predecessors is not enabled", () => {
beforeEach(() => {
jest.spyOn(SettingsStore, "getValue").mockReturnValue(false);
});
it("Passes through the dynamic predecessor setting", async () => {
mockClient.getVisibleRooms.mockReset();
mockClient.getVisibleRooms.mockReturnValue([]);
await makeOwnBeaconStore();
expect(mockClient.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 through the dynamic predecessor setting", async () => {
mockClient.getVisibleRooms.mockReset();
mockClient.getVisibleRooms.mockReturnValue([]);
await makeOwnBeaconStore();
expect(mockClient.getVisibleRooms).toHaveBeenCalledWith(true);
});
it("Passes through the dynamic predecessor when reinitialised", async () => {
const store = await makeOwnBeaconStore();
mockClient.getVisibleRooms.mockReset();
mockClient.getVisibleRooms.mockReturnValue([]);
store.reinitialiseBeaconState();
expect(mockClient.getVisibleRooms).toHaveBeenCalledWith(true);
});
});
});