Refactor EventTile using the MVVM pattern - #2 (#33489)

* Improve coverage

* Add view model unit tests to improve coverage

* Extract initial pure EventTile derived state helpers

* Extract EventTile derived state helpers

* Extract EventTile class state derivation

* Extract EventTile line class derivation

* Extract EventTile sender profile state

* Extract EventTile avatar member selection

* Extract EventTile avatar clickability state

* Extract EventTile sender profile mode

* Extract EventTile action bar visibility

* Extract EventTile timestamp visibility

* Extract EventTile timestamp selection

* Extract EventTile timestamp display state

* Extract ReplyChain timestamp visibility

* Extract EventTile footer display state

* Fix sonar issue
This commit is contained in:
rbondesson
2026-05-18 05:36:13 +00:00
committed by GitHub
parent 1922266ba7
commit 7fe8cdafe0
7 changed files with 1011 additions and 153 deletions
@@ -0,0 +1,57 @@
/*
* 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 { ActionBarAction } from "@element-hq/web-shared-components";
import { ThreadListActionBarViewModel } from "../../../src/viewmodels/room/ThreadListActionBarViewModel";
describe("ThreadListActionBarViewModel", () => {
it("builds the thread-list action bar snapshot", () => {
const vm = new ThreadListActionBarViewModel({});
expect(vm.getSnapshot()).toMatchObject({
actions: [ActionBarAction.ViewInRoom, ActionBarAction.CopyLink],
presentation: "icon",
isDownloadEncrypted: false,
isDownloadLoading: false,
isPinned: false,
isQuoteExpanded: false,
isThreadReplyAllowed: true,
});
});
it("forwards actions to the configured handlers", () => {
const onViewInRoomClick = jest.fn();
const onCopyLinkClick = jest.fn();
const vm = new ThreadListActionBarViewModel({
onViewInRoomClick,
onCopyLinkClick,
});
const anchor = document.createElement("button");
vm.onViewInRoomClick(anchor);
vm.onCopyLinkClick(anchor);
expect(onViewInRoomClick).toHaveBeenCalledWith(anchor);
expect(onCopyLinkClick).toHaveBeenCalledWith(anchor);
});
it("uses updated handlers after setProps", () => {
const initialOnViewInRoomClick = jest.fn();
const nextOnViewInRoomClick = jest.fn();
const vm = new ThreadListActionBarViewModel({
onViewInRoomClick: initialOnViewInRoomClick,
});
const anchor = document.createElement("button");
vm.setProps({ onViewInRoomClick: nextOnViewInRoomClick });
vm.onViewInRoomClick(anchor);
expect(initialOnViewInRoomClick).not.toHaveBeenCalled();
expect(nextOnViewInRoomClick).toHaveBeenCalledWith(anchor);
});
});