mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-12-06 12:39:01 +00:00
Refactor RoomAvatar to MVVM pattern (#33937)
* Refactor RoomAvatar to MVVM pattern * Fix OXFMT failing passes * Fix stories build issue * add snapshot images + fix props issue * Fix Eslint error * Fix RoomAvatarViewModel test client setup * Remove dead code left over from RoomAvatar refactor * Update snapshot * Fix RoomHeader avatar label and update RoomView snapshots * Update snapshots * Update snapshots * Update Snapshots * Update snapshots * Update snapshot * Fix room avatar component naming * Simplify room avatar view model updates * Update decorated room avatar view tests * Document room avatar view model props * Fix Oxlint error * Fix image (correct image now) * Fix mistake * Use VM disposables for room avatar listeners * Move room avatar view attrs into snapshot * Update image * Fix room avatar oxlint filename errors * Format room avatar MVVM files * Update room avatar VM test setter * Update snapshot * Use scoped room avatar listener disposables * Use VM disposables * Restore scoped disposables
This commit is contained in:
@@ -10,7 +10,6 @@ exports[`RoomView for a local room in state CREATING should match the snapshot 1
|
||||
style="--mx-flex-display: flex; --mx-flex-direction: row; --mx-flex-align: center; --mx-flex-justify: start; --mx-flex-gap: var(--cpd-space-3x); --mx-flex-wrap: nowrap;"
|
||||
>
|
||||
<span
|
||||
aria-label="Open room settings"
|
||||
class="_avatar_va14e_8 mx_BaseAvatar _avatar-imageless_va14e_55"
|
||||
data-color="3"
|
||||
data-testid="avatar-img"
|
||||
@@ -95,7 +94,6 @@ exports[`RoomView for a local room in state ERROR should match the snapshot 1`]
|
||||
style="--mx-flex-display: flex; --mx-flex-direction: row; --mx-flex-align: center; --mx-flex-justify: start; --mx-flex-gap: var(--cpd-space-3x); --mx-flex-wrap: nowrap;"
|
||||
>
|
||||
<span
|
||||
aria-label="Open room settings"
|
||||
class="_avatar_va14e_8 mx_BaseAvatar _avatar-imageless_va14e_55"
|
||||
data-color="3"
|
||||
data-testid="avatar-img"
|
||||
@@ -292,7 +290,6 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] =
|
||||
style="--mx-flex-display: flex; --mx-flex-direction: row; --mx-flex-align: center; --mx-flex-justify: start; --mx-flex-gap: var(--cpd-space-3x); --mx-flex-wrap: nowrap;"
|
||||
>
|
||||
<span
|
||||
aria-label="Open room settings"
|
||||
class="_avatar_va14e_8 mx_BaseAvatar _avatar-imageless_va14e_55"
|
||||
data-color="3"
|
||||
data-testid="avatar-img"
|
||||
@@ -680,7 +677,6 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
|
||||
style="--mx-flex-display: flex; --mx-flex-direction: row; --mx-flex-align: center; --mx-flex-justify: start; --mx-flex-gap: var(--cpd-space-3x); --mx-flex-wrap: nowrap;"
|
||||
>
|
||||
<span
|
||||
aria-label="Open room settings"
|
||||
class="_avatar_va14e_8 mx_BaseAvatar _avatar-imageless_va14e_55"
|
||||
data-color="3"
|
||||
data-testid="avatar-img"
|
||||
|
||||
+7
-7
@@ -9,7 +9,7 @@ import React from "react";
|
||||
import { render, screen } from "jest-matrix-react";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import { RoomAvatarView } from "../../../../../src/components/views/avatars/RoomAvatarView";
|
||||
import { DecoratedRoomAvatarView } from "../../../../../src/components/views/avatars/DecoratedRoomAvatarView";
|
||||
import { mkStubRoom, stubClient } from "../../../../test-utils";
|
||||
import {
|
||||
AvatarBadgeDecoration,
|
||||
@@ -24,7 +24,7 @@ jest.mock("../../../../../src/components/viewmodels/avatars/RoomAvatarViewModel"
|
||||
useRoomAvatarViewModel: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("<RoomAvatarView />", () => {
|
||||
describe("<DecoratedRoomAvatarView />", () => {
|
||||
const matrixClient = stubClient();
|
||||
const room = mkStubRoom("roomId", "roomName", matrixClient);
|
||||
|
||||
@@ -44,7 +44,7 @@ describe("<RoomAvatarView />", () => {
|
||||
|
||||
it("should not render a decoration", () => {
|
||||
mocked(useRoomAvatarViewModel).mockReturnValue({ ...defaultValue });
|
||||
const { asFragment } = render(<RoomAvatarView room={room} />);
|
||||
const { asFragment } = render(<DecoratedRoomAvatarView room={room} />);
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@ describe("<RoomAvatarView />", () => {
|
||||
...defaultValue,
|
||||
badgeDecoration: AvatarBadgeDecoration.LowPriority,
|
||||
});
|
||||
const { asFragment } = render(<RoomAvatarView room={room} />);
|
||||
const { asFragment } = render(<DecoratedRoomAvatarView room={room} />);
|
||||
|
||||
expect(screen.getByLabelText("This is a low priority room")).toBeInTheDocument();
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
@@ -64,7 +64,7 @@ describe("<RoomAvatarView />", () => {
|
||||
...defaultValue,
|
||||
badgeDecoration: AvatarBadgeDecoration.VideoRoom,
|
||||
});
|
||||
const { asFragment } = render(<RoomAvatarView room={room} />);
|
||||
const { asFragment } = render(<DecoratedRoomAvatarView room={room} />);
|
||||
|
||||
expect(screen.getByLabelText("This room is a video room")).toBeInTheDocument();
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
@@ -75,7 +75,7 @@ describe("<RoomAvatarView />", () => {
|
||||
...defaultValue,
|
||||
badgeDecoration: AvatarBadgeDecoration.PublicRoom,
|
||||
});
|
||||
const { asFragment } = render(<RoomAvatarView room={room} />);
|
||||
const { asFragment } = render(<DecoratedRoomAvatarView room={room} />);
|
||||
|
||||
expect(screen.getByLabelText("This room is public")).toBeInTheDocument();
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
@@ -92,7 +92,7 @@ describe("<RoomAvatarView />", () => {
|
||||
badgeDecoration: AvatarBadgeDecoration.Presence,
|
||||
presence,
|
||||
});
|
||||
const { asFragment } = render(<RoomAvatarView room={room} />);
|
||||
const { asFragment } = render(<DecoratedRoomAvatarView room={room} />);
|
||||
|
||||
expect(screen.getByLabelText(label)).toBeInTheDocument();
|
||||
expect(asFragment()).toMatchSnapshot();
|
||||
+16
-8
@@ -1,6 +1,6 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
|
||||
exports[`<RoomAvatarView /> should not render a decoration 1`] = `
|
||||
exports[`<DecoratedRoomAvatarView /> should not render a decoration 1`] = `
|
||||
<DocumentFragment>
|
||||
<span
|
||||
aria-label="Avatar"
|
||||
@@ -8,6 +8,7 @@ exports[`<RoomAvatarView /> should not render a decoration 1`] = `
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
@@ -24,7 +25,7 @@ exports[`<RoomAvatarView /> should not render a decoration 1`] = `
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<RoomAvatarView /> should render a low priority room decoration 1`] = `
|
||||
exports[`<DecoratedRoomAvatarView /> should render a low priority room decoration 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="_flex_4dswl_9 mx_RoomAvatarView"
|
||||
@@ -36,6 +37,7 @@ exports[`<RoomAvatarView /> should render a low priority room decoration 1`] = `
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
@@ -68,7 +70,7 @@ exports[`<RoomAvatarView /> should render a low priority room decoration 1`] = `
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<RoomAvatarView /> should render a public room decoration 1`] = `
|
||||
exports[`<DecoratedRoomAvatarView /> should render a public room decoration 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="_flex_4dswl_9 mx_RoomAvatarView"
|
||||
@@ -80,6 +82,7 @@ exports[`<RoomAvatarView /> should render a public room decoration 1`] = `
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
@@ -112,7 +115,7 @@ exports[`<RoomAvatarView /> should render a public room decoration 1`] = `
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<RoomAvatarView /> should render a video room decoration 1`] = `
|
||||
exports[`<DecoratedRoomAvatarView /> should render a video room decoration 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="_flex_4dswl_9 mx_RoomAvatarView"
|
||||
@@ -124,6 +127,7 @@ exports[`<RoomAvatarView /> should render a video room decoration 1`] = `
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
@@ -156,7 +160,7 @@ exports[`<RoomAvatarView /> should render a video room decoration 1`] = `
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<RoomAvatarView /> should render the busy presence 1`] = `
|
||||
exports[`<DecoratedRoomAvatarView /> should render the busy presence 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="_flex_4dswl_9 mx_RoomAvatarView"
|
||||
@@ -168,6 +172,7 @@ exports[`<RoomAvatarView /> should render the busy presence 1`] = `
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
@@ -215,7 +220,7 @@ exports[`<RoomAvatarView /> should render the busy presence 1`] = `
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<RoomAvatarView /> should render the offline presence 1`] = `
|
||||
exports[`<DecoratedRoomAvatarView /> should render the offline presence 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="_flex_4dswl_9 mx_RoomAvatarView"
|
||||
@@ -227,6 +232,7 @@ exports[`<RoomAvatarView /> should render the offline presence 1`] = `
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
@@ -274,7 +280,7 @@ exports[`<RoomAvatarView /> should render the offline presence 1`] = `
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<RoomAvatarView /> should render the online presence 1`] = `
|
||||
exports[`<DecoratedRoomAvatarView /> should render the online presence 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="_flex_4dswl_9 mx_RoomAvatarView"
|
||||
@@ -286,6 +292,7 @@ exports[`<RoomAvatarView /> should render the online presence 1`] = `
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
@@ -331,7 +338,7 @@ exports[`<RoomAvatarView /> should render the online presence 1`] = `
|
||||
</DocumentFragment>
|
||||
`;
|
||||
|
||||
exports[`<RoomAvatarView /> should render the unavailable presence 1`] = `
|
||||
exports[`<DecoratedRoomAvatarView /> should render the unavailable presence 1`] = `
|
||||
<DocumentFragment>
|
||||
<div
|
||||
class="_flex_4dswl_9 mx_RoomAvatarView"
|
||||
@@ -343,6 +350,7 @@ exports[`<RoomAvatarView /> should render the unavailable presence 1`] = `
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
+1
@@ -23,6 +23,7 @@ exports[`RoomAvatar should render an avatar for a room the user is invited to 1`
|
||||
data-color="6"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 36px;"
|
||||
>
|
||||
<img
|
||||
|
||||
+1
@@ -120,6 +120,7 @@ exports[`<ManageRestrictedJoinRuleDialog /> should list spaces which are not par
|
||||
>
|
||||
<div>
|
||||
<span
|
||||
aria-label="Avatar"
|
||||
class="_avatar_va14e_8 mx_BaseAvatar _avatar-imageless_va14e_55"
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
|
||||
+3
-1
@@ -156,6 +156,7 @@ exports[`<TextualBody /> renders formatted m.text correctly pills appear for eve
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 16px;"
|
||||
>
|
||||
<img
|
||||
@@ -203,6 +204,7 @@ exports[`<TextualBody /> renders formatted m.text correctly pills appear for roo
|
||||
data-color="1"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 16px;"
|
||||
>
|
||||
<img
|
||||
@@ -600,7 +602,7 @@ exports[`<TextualBody /> renders plain-text m.text correctly should pillify a ke
|
||||
|
||||
exports[`<TextualBody /> renders plain-text m.text correctly should pillify a permalink to a message in the same room with the label »Message from Member« 1`] = `"Visit <bdi><a class="mx_Pill mx_EventPill" href="https://matrix.to/#/!room1:example.com/%event_id%"><span aria-label="Profile picture" aria-hidden="true" data-testid="avatar-img" data-type="round" data-color="2" class="_avatar_va14e_8 mx_BaseAvatar" style="--cpd-avatar-size: 16px;"><img loading="lazy" alt="" referrerpolicy="no-referrer" class="_image_va14e_43" data-type="round" width="16px" height="16px" src="mxc://avatar.url/image.png"></span><span class="mx_Pill_text">Message from Member</span></a></bdi>"`;
|
||||
|
||||
exports[`<TextualBody /> renders plain-text m.text correctly should pillify a permalink to an event in another room with the label »Message in Room 2« 1`] = `"Visit <bdi><a class="mx_Pill mx_EventPill" href="https://matrix.to/#/!room2:example.com/%event_id%"><span aria-label="Avatar" aria-hidden="true" data-testid="avatar-img" data-type="round" data-color="2" class="_avatar_va14e_8 mx_BaseAvatar" style="--cpd-avatar-size: 16px;"><img loading="lazy" alt="" referrerpolicy="no-referrer" class="_image_va14e_43" data-type="round" width="16px" height="16px" src="mxc://avatar.url/room.png"></span><span class="mx_Pill_text">Message in Room 2</span></a></bdi>"`;
|
||||
exports[`<TextualBody /> renders plain-text m.text correctly should pillify a permalink to an event in another room with the label »Message in Room 2« 1`] = `"Visit <bdi><a class="mx_Pill mx_EventPill" href="https://matrix.to/#/!room2:example.com/%event_id%"><span role="img" aria-label="Avatar" aria-hidden="true" data-testid="avatar-img" data-type="round" data-color="2" class="_avatar_va14e_8 mx_BaseAvatar" style="--cpd-avatar-size: 16px;"><img loading="lazy" alt="" referrerpolicy="no-referrer" class="_image_va14e_43" data-type="round" width="16px" height="16px" src="mxc://avatar.url/room.png"></span><span class="mx_Pill_text">Message in Room 2</span></a></bdi>"`;
|
||||
|
||||
exports[`<TextualBody /> renders plain-text m.text correctly should pillify a permalink to an unknown message in the same room with the label »Message« 1`] = `
|
||||
<div
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ exports[`<AddExistingToSpaceDialog /> looks as expected 1`] = `
|
||||
data-color="2"
|
||||
data-testid="avatar-img"
|
||||
data-type="square"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 40px;"
|
||||
>
|
||||
<img
|
||||
|
||||
+9
-6
@@ -95,13 +95,14 @@ exports[`SpaceItem should render a space with subspaces 1`] = `
|
||||
class="_avatar_va14e_8 mx_BaseAvatar"
|
||||
data-color="3"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
data-type="square"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
alt=""
|
||||
class="_image_va14e_43"
|
||||
data-type="round"
|
||||
data-type="square"
|
||||
height="32px"
|
||||
loading="lazy"
|
||||
referrerpolicy="no-referrer"
|
||||
@@ -184,13 +185,14 @@ exports[`SpaceItem should render a space with subspaces 2`] = `
|
||||
class="_avatar_va14e_8 mx_BaseAvatar"
|
||||
data-color="3"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
data-type="square"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 32px;"
|
||||
>
|
||||
<img
|
||||
alt=""
|
||||
class="_image_va14e_43"
|
||||
data-type="round"
|
||||
data-type="square"
|
||||
height="32px"
|
||||
loading="lazy"
|
||||
referrerpolicy="no-referrer"
|
||||
@@ -252,13 +254,14 @@ exports[`SpaceItem should render a space with subspaces 2`] = `
|
||||
class="_avatar_va14e_8 mx_BaseAvatar"
|
||||
data-color="4"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
data-type="square"
|
||||
role="img"
|
||||
style="--cpd-avatar-size: 24px;"
|
||||
>
|
||||
<img
|
||||
alt=""
|
||||
class="_image_va14e_43"
|
||||
data-type="round"
|
||||
data-type="square"
|
||||
height="24px"
|
||||
loading="lazy"
|
||||
referrerpolicy="no-referrer"
|
||||
|
||||
Reference in New Issue
Block a user