Files
rbondessonandGitHub 82b313828a Move EventTile to shared components - #3a (#34458)
* Refactor Mjolnir body to use render-only view model actions

* Extracted isMjolnirBodyAllowed from MessageEvent

* Converted the new test file to vitest
2026-07-30 14:50:57 +00:00

50 lines
1.4 KiB
TypeScript

/*
* 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 { MjolnirBodyViewModel } from "../../../src/viewmodels/room/timeline/event-tile/body/MjolnirBodyViewModel";
describe("MjolnirBodyViewModel", () => {
it("has an empty snapshot", () => {
const vm = new MjolnirBodyViewModel({ onAllow: jest.fn() });
expect(vm.getSnapshot()).toEqual({});
});
it("forwards the allow action", () => {
const onAllow = jest.fn();
const vm = new MjolnirBodyViewModel({ onAllow });
vm.onAllow();
expect(onAllow).toHaveBeenCalledTimes(1);
});
it("uses the updated action", () => {
const oldAction = jest.fn();
const newAction = jest.fn();
const vm = new MjolnirBodyViewModel({ onAllow: oldAction });
vm.setProps({ onAllow: newAction });
vm.onAllow();
expect(oldAction).not.toHaveBeenCalled();
expect(newAction).toHaveBeenCalledTimes(1);
});
it("does not emit snapshot updates for unchanged action inputs", () => {
const props = { onAllow: jest.fn() };
const listener = jest.fn();
const vm = new MjolnirBodyViewModel(props);
vm.subscribe(listener);
vm.setProps(props);
expect(listener).not.toHaveBeenCalled();
});
});