From 0ddc5031176810f2f56b3eaf86fb06700f63ad17 Mon Sep 17 00:00:00 2001 From: Timo K Date: Mon, 4 Mar 2024 15:12:17 +0100 Subject: [PATCH] add tests Signed-off-by: Timo K --- spec/unit/embedded.spec.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/spec/unit/embedded.spec.ts b/spec/unit/embedded.spec.ts index 115e0a419ca..19717df1462 100644 --- a/spec/unit/embedded.spec.ts +++ b/spec/unit/embedded.spec.ts @@ -87,9 +87,12 @@ describe("RoomWidgetClient", () => { client.stopClient(); }); - const makeClient = async (capabilities: ICapabilities): Promise => { + const makeClient = async ( + capabilities: ICapabilities, + sendContentLoaded: boolean | undefined = undefined, + ): Promise => { const baseUrl = "https://example.org"; - client = createRoomWidgetClient(widgetApi, capabilities, "!1:example.org", { baseUrl }); + client = createRoomWidgetClient(widgetApi, capabilities, "!1:example.org", { baseUrl }, sendContentLoaded); expect(widgetApi.start).toHaveBeenCalled(); // needs to have been called early in order to not miss messages widgetApi.emit("ready"); await client.startClient(); @@ -143,7 +146,7 @@ describe("RoomWidgetClient", () => { }); }); - describe("messages", () => { + describe("initialization", () => { it("requests permissions for specific message types", async () => { await makeClient({ sendMessage: [MsgType.Text], receiveMessage: [MsgType.Text] }); expect(widgetApi.requestCapabilityForRoomTimeline).toHaveBeenCalledWith("!1:example.org"); @@ -158,6 +161,15 @@ describe("RoomWidgetClient", () => { expect(widgetApi.requestCapabilityToReceiveMessage).toHaveBeenCalledWith(); }); + it("sends content loaded when configured", async () => { + await makeClient({}, true); + expect(widgetApi.sendContentLoaded).toHaveBeenCalled(); + }); + + it("does not sent content loaded when configured", async () => { + await makeClient({}, false); + expect(widgetApi.sendContentLoaded).not.toHaveBeenCalled(); + }); // No point in testing sending and receiving since it's done exactly the // same way as non-message events }); @@ -305,12 +317,14 @@ describe("RoomWidgetClient", () => { expect(await emittedSync).toEqual(SyncState.Syncing); }); }); + describe("oidc token", () => { it("requests an oidc token", async () => { await makeClient({}); expect(await client.getOpenIdToken()).toStrictEqual(testOIDCToken); }); }); + it("gets TURN servers", async () => { const server1: ITurnServer = { uris: [