Skip to content

Commit dce1b57

Browse files
committed
Update model to respond to changes
1 parent f8d7f5b commit dce1b57

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

packages/shared-components/src/message-body/ReactionsRowButton/ReactionsRowButtonView.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import { type ViewModel, useViewModel } from "../../viewmodel";
1212
import { ReactionsRowButtonTooltipView, type ReactionsRowButtonTooltipViewModel } from "../ReactionsRowButtonTooltip";
1313
import styles from "./ReactionsRowButton.module.css";
1414

15-
type ButtonAttribute = HTMLAttributes<HTMLButtonElement>;
16-
17-
export interface ReactionsRowButtonViewSnapshot extends Pick<HTMLAttributes<HTMLButtonElement>, "className" | "aria-label"> {
15+
export interface ReactionsRowButtonViewSnapshot extends Pick<
16+
HTMLAttributes<HTMLButtonElement>,
17+
"className" | "aria-label"
18+
> {
1819
/**
1920
* The reaction content to display when not using a custom image.
2021
*/

src/viewmodels/message-body/ReactionsRowButtonViewModel.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export class ReactionsRowButtonViewModel
6363
implements ReactionsRowButtonViewModelInterface
6464
{
6565
private readonly tooltipVm: ReactionsRowButtonTooltipViewModel;
66+
private static readonly getAriaLabel = (snapshot: ReactionsRowButtonViewSnapshot): string | undefined =>
67+
(snapshot as ReactionsRowButtonViewSnapshot & { ariaLabel?: string }).ariaLabel;
6668

6769
private static readonly computeSnapshot = (
6870
props: ReactionsRowButtonViewModelProps,
@@ -115,7 +117,7 @@ export class ReactionsRowButtonViewModel
115117
}
116118
}
117119

118-
return {
120+
const snapshot = {
119121
content,
120122
count,
121123
className,
@@ -126,6 +128,8 @@ export class ReactionsRowButtonViewModel
126128
imageAlt,
127129
tooltipVm,
128130
};
131+
132+
return snapshot;
129133
};
130134

131135
public constructor(props: ReactionsRowButtonViewModelProps) {
@@ -147,7 +151,8 @@ export class ReactionsRowButtonViewModel
147151
if (
148152
nextSnapshot.content === currentSnapshot.content &&
149153
nextSnapshot.count === currentSnapshot.count &&
150-
nextSnapshot.ariaLabel === currentSnapshot.ariaLabel &&
154+
ReactionsRowButtonViewModel.getAriaLabel(nextSnapshot) ===
155+
ReactionsRowButtonViewModel.getAriaLabel(currentSnapshot) &&
151156
nextSnapshot.isSelected === currentSnapshot.isSelected &&
152157
nextSnapshot.isDisabled === currentSnapshot.isDisabled &&
153158
nextSnapshot.imageSrc === currentSnapshot.imageSrc &&

test/viewmodels/message-body/ReactionsRowButtonViewModel-test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ describe("ReactionsRowButtonViewModel", () => {
5151

5252
const getTooltipVm = (vm: ReactionsRowButtonViewModel): ReactionsRowButtonTooltipViewModel =>
5353
vm.getSnapshot().tooltipVm as ReactionsRowButtonTooltipViewModel;
54+
const getAriaLabel = (vm: ReactionsRowButtonViewModel): string | undefined =>
55+
(vm.getSnapshot() as { ariaLabel?: string }).ariaLabel;
5456

5557
beforeEach(() => {
5658
jest.clearAllMocks();
@@ -83,6 +85,12 @@ describe("ReactionsRowButtonViewModel", () => {
8385
expect(listener).toHaveBeenCalledTimes(2);
8486
});
8587

88+
it("includes an ariaLabel in the snapshot", () => {
89+
const vm = new ReactionsRowButtonViewModel(createProps());
90+
91+
expect(getAriaLabel(vm)).toContain("reacted with 👍");
92+
});
93+
8694
it("updates selected state with myReactionEvent without touching tooltip props", () => {
8795
const vm = new ReactionsRowButtonViewModel(createProps());
8896
const tooltipSetPropsSpy = jest.spyOn(getTooltipVm(vm), "setProps");

0 commit comments

Comments
 (0)