Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Timo K <[email protected]>
  • Loading branch information
toger5 committed Mar 4, 2024
1 parent 8c8d62f commit 0ddc503
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions spec/unit/embedded.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ describe("RoomWidgetClient", () => {
client.stopClient();
});

const makeClient = async (capabilities: ICapabilities): Promise<void> => {
const makeClient = async (
capabilities: ICapabilities,
sendContentLoaded: boolean | undefined = undefined,
): Promise<void> => {
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();
Expand Down Expand Up @@ -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");
Expand All @@ -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
});
Expand Down Expand Up @@ -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: [
Expand Down

0 comments on commit 0ddc503

Please sign in to comment.