Migrate batch of tests to vitest (#34121)
* Migrate batch of tests tro vitest * Iterate * Migrate another test * Migrate batch of tests to vitest * Iterate
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
Copyright 2026 Element Creations Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { ClientEvent, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import AccountSettingsHandler from "../../../../src/settings/handlers/AccountSettingsHandler.ts";
|
||||
import { WatchManager } from "../../../../src/settings/WatchManager.ts";
|
||||
import { stubClient } from "../../../test-utils";
|
||||
|
||||
describe("AccountSettingsHandler", () => {
|
||||
const watchManager = new WatchManager();
|
||||
const handler = new AccountSettingsHandler(watchManager);
|
||||
|
||||
beforeEach(stubClient);
|
||||
|
||||
it("should notify watchers of recent_emoji on account data update", async () => {
|
||||
const fn = jest.fn();
|
||||
handler.watchers.watchSetting("recent_emoji", null, fn);
|
||||
|
||||
const ev = new MatrixEvent({
|
||||
type: "io.element.recent_emoji",
|
||||
content: {
|
||||
recent_emoji: [["🤒", 1]],
|
||||
},
|
||||
});
|
||||
mocked(handler.client.getAccountData).mockImplementation((eventType) =>
|
||||
eventType === "io.element.recent_emoji" ? ev : undefined,
|
||||
);
|
||||
handler.client.emit(ClientEvent.AccountData, ev);
|
||||
|
||||
expect(fn).toHaveBeenCalledWith(null, "account", [{ emoji: "🤒", total: 1 }]);
|
||||
});
|
||||
|
||||
it("should write value to account data correctly", async () => {
|
||||
void handler.setValue("pseudonymousAnalyticsOptIn", null, true);
|
||||
|
||||
expect(handler.client.setAccountData).toHaveBeenCalledWith("im.vector.analytics", {
|
||||
pseudonymousAnalyticsOptIn: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { mocked } from "jest-mock";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import DeviceSettingsHandler from "../../../../src/settings/handlers/DeviceSettingsHandler";
|
||||
import { type CallbackFn, WatchManager } from "../../../../src/settings/WatchManager";
|
||||
import { stubClient } from "../../../test-utils/test-utils";
|
||||
|
||||
describe("DeviceSettingsHandler", () => {
|
||||
const ROOM_ID_IS_UNUSED = "";
|
||||
|
||||
const unknownSettingKey = "unknown_setting";
|
||||
const featureKey = "my_feature";
|
||||
|
||||
let watchers: WatchManager;
|
||||
let handler: DeviceSettingsHandler;
|
||||
let settingListener: CallbackFn;
|
||||
|
||||
beforeEach(() => {
|
||||
watchers = new WatchManager();
|
||||
handler = new DeviceSettingsHandler([featureKey], watchers);
|
||||
settingListener = jest.fn();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
watchers.unwatchSetting(settingListener);
|
||||
});
|
||||
|
||||
it("Returns undefined for an unknown setting", () => {
|
||||
expect(handler.getValue(unknownSettingKey, ROOM_ID_IS_UNUSED)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Returns the value for a disabled feature", () => {
|
||||
handler.setValue(featureKey, ROOM_ID_IS_UNUSED, false);
|
||||
expect(handler.getValue(featureKey, ROOM_ID_IS_UNUSED)).toBe(false);
|
||||
});
|
||||
|
||||
it("Returns the value for an enabled feature", () => {
|
||||
handler.setValue(featureKey, ROOM_ID_IS_UNUSED, true);
|
||||
expect(handler.getValue(featureKey, ROOM_ID_IS_UNUSED)).toBe(true);
|
||||
});
|
||||
|
||||
describe("If I am a guest", () => {
|
||||
let client: MatrixClient;
|
||||
|
||||
beforeEach(() => {
|
||||
client = stubClient();
|
||||
mocked(client.isGuest).mockReturnValue(true);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
MatrixClientPeg.get = () => null;
|
||||
MatrixClientPeg.safeGet = () => new MatrixClient({ baseUrl: "foobar" });
|
||||
});
|
||||
|
||||
it("Returns the value for a disabled feature", () => {
|
||||
handler.setValue(featureKey, ROOM_ID_IS_UNUSED, false);
|
||||
expect(handler.getValue(featureKey, ROOM_ID_IS_UNUSED)).toBe(false);
|
||||
});
|
||||
|
||||
it("Returns the value for an enabled feature", () => {
|
||||
handler.setValue(featureKey, ROOM_ID_IS_UNUSED, true);
|
||||
expect(handler.getValue(featureKey, ROOM_ID_IS_UNUSED)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import RoomDeviceSettingsHandler from "../../../../src/settings/handlers/RoomDeviceSettingsHandler";
|
||||
import { SettingLevel } from "../../../../src/settings/SettingLevel";
|
||||
import { type CallbackFn, WatchManager } from "../../../../src/settings/WatchManager";
|
||||
|
||||
describe("RoomDeviceSettingsHandler", () => {
|
||||
const roomId = "!room:example.com";
|
||||
const value = "test value";
|
||||
const testSettings = [
|
||||
"RightPanel.phases",
|
||||
// special case in RoomDeviceSettingsHandler
|
||||
"blacklistUnverifiedDevices",
|
||||
];
|
||||
let watchers: WatchManager;
|
||||
let handler: RoomDeviceSettingsHandler;
|
||||
let settingListener: CallbackFn;
|
||||
|
||||
beforeEach(() => {
|
||||
watchers = new WatchManager();
|
||||
handler = new RoomDeviceSettingsHandler(watchers);
|
||||
settingListener = jest.fn();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
watchers.unwatchSetting(settingListener);
|
||||
});
|
||||
|
||||
it.each(testSettings)("should write/read/clear the value for »%s«", (setting: string): void => {
|
||||
// initial value should be null
|
||||
watchers.watchSetting(setting, roomId, settingListener);
|
||||
|
||||
expect(handler.getValue(setting, roomId)).toBeNull();
|
||||
|
||||
// set and read value
|
||||
handler.setValue(setting, roomId, value);
|
||||
expect(settingListener).toHaveBeenCalledWith(roomId, SettingLevel.ROOM_DEVICE, value);
|
||||
expect(handler.getValue(setting, roomId)).toEqual(value);
|
||||
|
||||
// clear value
|
||||
handler.setValue(setting, roomId, null);
|
||||
expect(settingListener).toHaveBeenCalledWith(roomId, SettingLevel.ROOM_DEVICE, null);
|
||||
expect(handler.getValue(setting, roomId)).toBeNull();
|
||||
});
|
||||
|
||||
it("canSetValue should return true", () => {
|
||||
expect(handler.canSetValue("test setting", roomId)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user