* 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:
@@ -16,6 +16,9 @@ import { createTestClient, mkEvent, mkStubRoom } from "../../test-utils";
|
||||
import dis from "../../../src/dispatcher/dispatcher";
|
||||
|
||||
jest.mock("../../../src/dispatcher/dispatcher");
|
||||
jest.mock("../../../src/customisations/Media", () => ({
|
||||
mediaFromMxc: jest.fn(() => ({ srcHttp: "https://example.org/_matrix/media/reaction.png" })),
|
||||
}));
|
||||
|
||||
describe("ReactionsRowButtonViewModel", () => {
|
||||
let client: MatrixClient;
|
||||
@@ -91,6 +94,35 @@ describe("ReactionsRowButtonViewModel", () => {
|
||||
expect(getAriaLabel(vm)).toContain("reacted with 👍");
|
||||
});
|
||||
|
||||
it("falls back when no room is available", () => {
|
||||
jest.spyOn(client, "getRoom").mockReturnValue(null);
|
||||
|
||||
const vm = new ReactionsRowButtonViewModel(createProps());
|
||||
|
||||
expect(getAriaLabel(vm)).toBeUndefined();
|
||||
expect(vm.getSnapshot().content).toBe("👍");
|
||||
expect(vm.getSnapshot().count).toBe(2);
|
||||
});
|
||||
|
||||
it("renders custom reaction images with shortcode labels when enabled", () => {
|
||||
const reactionEvent = createReactionEvent("@alice:example.org", "mxc://example.org/reaction");
|
||||
reactionEvent.getContent()["shortcode"] = "party";
|
||||
|
||||
const vm = new ReactionsRowButtonViewModel(
|
||||
createProps({
|
||||
content: "mxc://example.org/reaction",
|
||||
reactionEvents: [reactionEvent],
|
||||
customReactionImagesEnabled: true,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(vm.getSnapshot()).toMatchObject({
|
||||
imageSrc: "https://example.org/_matrix/media/reaction.png",
|
||||
imageAlt: "party",
|
||||
});
|
||||
expect(getAriaLabel(vm)).toContain("reacted with party");
|
||||
});
|
||||
|
||||
it("updates selected state with myReactionEvent without touching tooltip props", () => {
|
||||
const vm = new ReactionsRowButtonViewModel(createProps());
|
||||
const tooltipSetPropsSpy = jest.spyOn(getTooltipVm(vm), "setProps");
|
||||
|
||||
Reference in New Issue
Block a user