Refactor several unit tests to use SettingsStore directly. (#29744)

* Refactor notifications-test.ts

* Refactor other tests to stop mocking SettingsStore
This commit is contained in:
Will Hunt
2025-04-15 09:01:35 +01:00
committed by GitHub
parent bb23a98bc6
commit 23a42e0d54
7 changed files with 146 additions and 66 deletions

View File

@@ -484,6 +484,10 @@ describe("<MatrixChat />", () => {
);
});
afterEach(() => {
SettingsStore.reset();
});
it("should persist login credentials", async () => {
getComponent({ realQueryParams });

View File

@@ -50,6 +50,8 @@ import SettingsStore from "../../../../src/settings/SettingsStore";
import ScrollPanel from "../../../../src/components/structures/ScrollPanel";
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
import { Action } from "../../../../src/dispatcher/actions";
import { SettingLevel } from "../../../../src/settings/SettingLevel";
import MatrixClientBackedController from "../../../../src/settings/controllers/MatrixClientBackedController";
// ScrollPanel calls this, but jsdom doesn't mock it for us
HTMLDivElement.prototype.scrollBy = () => {};
@@ -310,18 +312,14 @@ describe("TimelinePanel", () => {
describe("and sending receipts is disabled", () => {
beforeEach(async () => {
client.isVersionSupported.mockResolvedValue(true);
client.doesServerSupportUnstableFeature.mockResolvedValue(true);
jest.spyOn(SettingsStore, "getValue").mockImplementation((setting: string): any => {
if (setting === "sendReadReceipts") return false;
return undefined;
});
// Ensure this setting is supported, otherwise it will use the default value.
client.isVersionSupported.mockImplementation(async (v) => v === "v1.4");
MatrixClientBackedController.matrixClient = client;
SettingsStore.setValue("sendReadReceipts", null, SettingLevel.DEVICE, false);
});
afterEach(() => {
mocked(SettingsStore.getValue).mockReset();
SettingsStore.reset();
});
it("should send a fully read marker and a private receipt", async () => {