2022-07-20 07:26:25 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-07-20 07:26:25 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-07-20 07:26:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
import TypingStore from "../../../src/stores/TypingStore";
|
|
|
|
import { LOCAL_ROOM_ID_PREFIX } from "../../../src/models/LocalRoom";
|
|
|
|
import SettingsStore from "../../../src/settings/SettingsStore";
|
2022-10-19 13:14:14 +00:00
|
|
|
import { TestSdkContext } from "../TestSdkContext";
|
2022-07-20 07:26:25 +00:00
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
jest.mock("../../../src/settings/SettingsStore", () => ({
|
2022-07-20 07:26:25 +00:00
|
|
|
getValue: jest.fn(),
|
2022-10-19 13:14:14 +00:00
|
|
|
monitorSetting: jest.fn(),
|
2022-12-06 09:59:17 +00:00
|
|
|
watchSetting: jest.fn(),
|
2022-07-20 07:26:25 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe("TypingStore", () => {
|
|
|
|
let typingStore: TypingStore;
|
|
|
|
let mockClient: MatrixClient;
|
|
|
|
const roomId = "!test:example.com";
|
|
|
|
const localRoomId = LOCAL_ROOM_ID_PREFIX + "test";
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mockClient = {
|
|
|
|
sendTyping: jest.fn(),
|
|
|
|
} as unknown as MatrixClient;
|
2022-10-19 13:14:14 +00:00
|
|
|
const context = new TestSdkContext();
|
|
|
|
context.client = mockClient;
|
|
|
|
typingStore = new TypingStore(context);
|
2022-12-13 15:09:15 +00:00
|
|
|
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
|
|
|
|
return name === "sendTypingNotifications";
|
2022-07-20 07:26:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("setSelfTyping", () => {
|
|
|
|
it("shouldn't do anything for a local room", () => {
|
|
|
|
typingStore.setSelfTyping(localRoomId, null, true);
|
|
|
|
expect(mockClient.sendTyping).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("in typing state true", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
typingStore.setSelfTyping(roomId, null, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should change to false when setting false", () => {
|
|
|
|
typingStore.setSelfTyping(roomId, null, false);
|
|
|
|
expect(mockClient.sendTyping).toHaveBeenCalledWith(roomId, false, 30000);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should change to true when setting true", () => {
|
|
|
|
typingStore.setSelfTyping(roomId, null, true);
|
|
|
|
expect(mockClient.sendTyping).toHaveBeenCalledWith(roomId, true, 30000);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("in typing state false", () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
typingStore.setSelfTyping(roomId, null, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't change when setting false", () => {
|
|
|
|
typingStore.setSelfTyping(roomId, null, false);
|
|
|
|
expect(mockClient.sendTyping).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should change to true when setting true", () => {
|
|
|
|
typingStore.setSelfTyping(roomId, null, true);
|
|
|
|
expect(mockClient.sendTyping).toHaveBeenCalledWith(roomId, true, 30000);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|