mirror of
https://github.com/vector-im/element-web.git
synced 2025-12-07 18:31:33 +01:00
* Introduce snapshot class to track snapshot updates This avoids the hassle of having to manually call emit. * Better viewmodel ergonomics - Rename `SubscriptionViewModel` to `BaseViewModel`. I feel this is appropriate since that class does more than just manage subscriptions. - `getSnapshot` is no longer an abstract method. It's simply a method that returns the current snapshot state. This ensures that getSnapshot result is cached by default which is required by `useSyncExternalStore`. - `props` are a property of the base vm class so that actual VMs don't have to keep creating this property. * Update `TextualEventViewModel` * Fix test * Rename `TextualEvent` to `TextualEventView` * Fix snapshot object not being merged * Rename directory to `EventTileView` * Fix broken snapshot * Add test for snapshot class
36 lines
1007 B
TypeScript
36 lines
1007 B
TypeScript
/*
|
|
Copyright 2025 New Vector 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 { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { TextualEventViewModel } from "../../../src/viewmodels/event-tiles/TextualEventViewModel";
|
|
import { stubClient } from "../../test-utils";
|
|
|
|
jest.mock("../../../src/TextForEvent.tsx", () => ({
|
|
textForEvent: jest.fn().mockReturnValue("Test Message"),
|
|
}));
|
|
|
|
describe("TextualEventViewModel", () => {
|
|
it("should update when the sentinel updates", () => {
|
|
const fakeEvent = new MatrixEvent({});
|
|
stubClient();
|
|
|
|
const vm = new TextualEventViewModel({
|
|
showHiddenEvents: false,
|
|
mxEvent: fakeEvent,
|
|
});
|
|
|
|
const cb = jest.fn();
|
|
|
|
vm.subscribe(cb);
|
|
|
|
fakeEvent.emit(MatrixEventEvent.SentinelUpdated);
|
|
|
|
expect(cb).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|