mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-27 00:48:06 +08:00
9a5afb11f6
- replace jest references with vitest
106 lines
2.9 KiB
TypeScript
106 lines
2.9 KiB
TypeScript
/*
|
|
Copyright 2023 New Vector Ltd
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import { vi } from "vitest";
|
|
|
|
import { getRoomIdentifierFromUrl } from "../src/UrlParams";
|
|
import { Config } from "../src/config/Config";
|
|
|
|
const ROOM_NAME = "roomNameHere";
|
|
const ROOM_ID = "!d45f138fsd";
|
|
const ORIGIN = "https://call.element.io";
|
|
const HOMESERVER = "call.ems.host";
|
|
|
|
vi.mock("../src/config/Config");
|
|
|
|
describe("UrlParams", () => {
|
|
beforeAll(() => {
|
|
vi.mocked(Config.defaultServerName).mockReturnValue("call.ems.host");
|
|
});
|
|
|
|
describe("handles URL with /room/", () => {
|
|
it("and nothing else", () => {
|
|
expect(
|
|
getRoomIdentifierFromUrl(`/room/${ROOM_NAME}`, "", "").roomAlias,
|
|
).toBe(`#${ROOM_NAME}:${HOMESERVER}`);
|
|
});
|
|
|
|
it("and #", () => {
|
|
expect(
|
|
getRoomIdentifierFromUrl("", `${ORIGIN}/room/`, `#${ROOM_NAME}`)
|
|
.roomAlias,
|
|
).toBe(`#${ROOM_NAME}:${HOMESERVER}`);
|
|
});
|
|
|
|
it("and # and server part", () => {
|
|
expect(
|
|
getRoomIdentifierFromUrl("", `/room/`, `#${ROOM_NAME}:${HOMESERVER}`)
|
|
.roomAlias,
|
|
).toBe(`#${ROOM_NAME}:${HOMESERVER}`);
|
|
});
|
|
|
|
it("and server part", () => {
|
|
expect(
|
|
getRoomIdentifierFromUrl(`/room/${ROOM_NAME}:${HOMESERVER}`, "", "")
|
|
.roomAlias,
|
|
).toBe(`#${ROOM_NAME}:${HOMESERVER}`);
|
|
});
|
|
});
|
|
|
|
describe("handles URL without /room/", () => {
|
|
it("and nothing else", () => {
|
|
expect(getRoomIdentifierFromUrl(`/${ROOM_NAME}`, "", "").roomAlias).toBe(
|
|
`#${ROOM_NAME}:${HOMESERVER}`,
|
|
);
|
|
});
|
|
|
|
it("and with #", () => {
|
|
expect(getRoomIdentifierFromUrl("", "", `#${ROOM_NAME}`).roomAlias).toBe(
|
|
`#${ROOM_NAME}:${HOMESERVER}`,
|
|
);
|
|
});
|
|
|
|
it("and with # and server part", () => {
|
|
expect(
|
|
getRoomIdentifierFromUrl("", "", `#${ROOM_NAME}:${HOMESERVER}`)
|
|
.roomAlias,
|
|
).toBe(`#${ROOM_NAME}:${HOMESERVER}`);
|
|
});
|
|
|
|
it("and with server part", () => {
|
|
expect(
|
|
getRoomIdentifierFromUrl(`/${ROOM_NAME}:${HOMESERVER}`, "", "")
|
|
.roomAlias,
|
|
).toBe(`#${ROOM_NAME}:${HOMESERVER}`);
|
|
});
|
|
});
|
|
|
|
describe("handles search params", () => {
|
|
it("(roomId)", () => {
|
|
expect(
|
|
getRoomIdentifierFromUrl("", `?roomId=${ROOM_ID}`, "").roomId,
|
|
).toBe(ROOM_ID);
|
|
});
|
|
});
|
|
|
|
it("ignores room alias", () => {
|
|
expect(
|
|
getRoomIdentifierFromUrl("", `/room/${ROOM_NAME}:${HOMESERVER}`, "")
|
|
.roomAlias,
|
|
).toBeFalsy();
|
|
});
|
|
});
|