Skip to content

Commit 2a9ad6b

Browse files
committed
tests: Add test suite for RoomStatusBarHistoryVisible.
1 parent c19d13a commit 2a9ad6b

File tree

4 files changed

+183
-4
lines changed

4 files changed

+183
-4
lines changed

src/components/structures/RoomStatusBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
109109
unsentMessages: getUnsentMessages(this.props.room),
110110
isResending: false,
111111
roomHistoryVisibility: this.props.room.getHistoryVisibility(),
112-
roomHasEncryptionStateEvent: false,
112+
roomHasEncryptionStateEvent: this.props.room.hasEncryptionStateEvent(),
113113
acknowledgedHistoryVisibility: this.getUpdatedAcknowledgedHistoryVisibility(),
114114
};
115115
}

test/test-utils/test-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ Please see LICENSE files in the repository root for full details.
99
import EventEmitter from "events";
1010
import { mocked, type MockedObject } from "jest-mock";
1111
import {
12+
EventTimeline,
1213
MatrixEvent,
1314
type Room,
1415
type User,
1516
type IContent,
1617
type IEvent,
1718
type RoomMember,
1819
type MatrixClient,
19-
type EventTimeline,
2020
type RoomState,
2121
EventType,
2222
type IEventRelation,

test/unit-tests/components/structures/RoomStatusBar-test.tsx

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
77
*/
88

99
import React from "react";
10-
import { render } from "jest-matrix-react";
10+
import { fireEvent, render } from "jest-matrix-react";
1111
import {
1212
type MatrixClient,
1313
PendingEventOrdering,
@@ -20,8 +20,12 @@ import {
2020
import RoomStatusBar, { getUnsentMessages } from "../../../../src/components/structures/RoomStatusBar";
2121
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
2222
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
23-
import { mkEvent, stubClient } from "../../../test-utils/test-utils";
23+
import { mkEvent, stubClient, upsertRoomStateEvents } from "../../../test-utils/test-utils";
2424
import { mkThread } from "../../../test-utils/threads";
25+
import { flushPromises } from "../../../test-utils";
26+
import SettingsStore from "../../../../src/settings/SettingsStore";
27+
import { SettingLevel } from "../../../../src/settings/SettingLevel";
28+
import { type Settings } from "../../../../src/settings/Settings";
2529

2630
describe("RoomStatusBar", () => {
2731
const ROOM_ID = "!roomId:example.org";
@@ -35,6 +39,7 @@ describe("RoomStatusBar", () => {
3539
stubClient();
3640
client = MatrixClientPeg.safeGet();
3741
client.getSyncStateData = jest.fn().mockReturnValue({});
42+
client.setRoomAccountData = jest.fn().mockResolvedValue({});
3843
room = new Room(ROOM_ID, client, client.getUserId()!, {
3944
pendingEventOrdering: PendingEventOrdering.Detached,
4045
});
@@ -147,4 +152,111 @@ describe("RoomStatusBar", () => {
147152
});
148153
});
149154
});
155+
156+
describe("Shared History Visibility Acknowledgement", () => {
157+
let acknowledgedHistoryVisibility = false;
158+
159+
beforeAll(() => {
160+
jest.spyOn(SettingsStore, "setValue").mockImplementation(
161+
async (settingName: keyof Settings, roomId: string | null = null, level: SettingLevel, value: any) => {
162+
if (settingName == "acknowledgedHistoryVisibility") {
163+
acknowledgedHistoryVisibility = value;
164+
}
165+
},
166+
);
167+
jest.spyOn(SettingsStore, "getValue").mockImplementation(
168+
(settingName: keyof Settings, roomId: string | null = null, excludeDefault = false) => {
169+
if (settingName == "acknowledgedHistoryVisibility") {
170+
return acknowledgedHistoryVisibility;
171+
}
172+
return acknowledgedHistoryVisibility;
173+
},
174+
);
175+
});
176+
177+
beforeEach(async () => {
178+
await SettingsStore.setValue("acknowledgedHistoryVisibility", ROOM_ID, SettingLevel.ROOM_ACCOUNT, false);
179+
});
180+
181+
it("should not render history visibility acknowledgement in unencrypted rooms", () => {
182+
const { container } = getComponent();
183+
expect(container).toMatchSnapshot();
184+
});
185+
186+
it("should not render history visibility acknowledgement in encrypted rooms with joined history visibility", () => {
187+
upsertRoomStateEvents(room, [
188+
mkEvent({
189+
event: true,
190+
type: "m.room.encryption",
191+
user: "@user1:server",
192+
content: {},
193+
}),
194+
mkEvent({
195+
event: true,
196+
type: "m.room.history_visibility",
197+
content: {
198+
history_visibility: "joined",
199+
},
200+
user: "@user1:server",
201+
}),
202+
]);
203+
204+
const { container } = getComponent();
205+
expect(container).toMatchSnapshot();
206+
});
207+
208+
it("should not render history visibility acknowledgement if it has previously been dismissed", async () => {
209+
await SettingsStore.setValue("acknowledgedHistoryVisibility", ROOM_ID, SettingLevel.ROOM_ACCOUNT, true);
210+
upsertRoomStateEvents(room, [
211+
mkEvent({
212+
event: true,
213+
type: "m.room.encryption",
214+
user: "@user1:server",
215+
content: {},
216+
}),
217+
mkEvent({
218+
event: true,
219+
type: "m.room.history_visibility",
220+
user: "@user1:server",
221+
content: {
222+
history_visibility: "shared",
223+
},
224+
}),
225+
]);
226+
227+
const { container } = getComponent();
228+
expect(container).toMatchSnapshot();
229+
});
230+
231+
it("should render dismissable history visibility acknowledgement in encrypted rooms with non-join history visibility", async () => {
232+
upsertRoomStateEvents(room, [
233+
mkEvent({
234+
event: true,
235+
type: "m.room.encryption",
236+
user: "@user1:server",
237+
content: {},
238+
}),
239+
mkEvent({
240+
event: true,
241+
type: "m.room.history_visibility",
242+
user: "@user1:server",
243+
content: {
244+
history_visibility: "shared",
245+
},
246+
}),
247+
]);
248+
249+
const { container } = getComponent();
250+
expect(container).toMatchSnapshot();
251+
252+
// assert dismiss button exists, and press it
253+
const dismissButton = container.querySelector<HTMLDivElement>('div[role="button"]');
254+
expect(dismissButton).not.toBeNull();
255+
fireEvent.click(dismissButton!);
256+
257+
await flushPromises();
258+
259+
expect(container).toBeEmptyDOMElement();
260+
});
261+
});
150262
});

test/unit-tests/components/structures/__snapshots__/RoomStatusBar-test.tsx.snap

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,70 @@ exports[`RoomStatusBar <RoomStatusBar /> unsent messages should render warning w
124124
</div>
125125
</div>
126126
`;
127+
128+
exports[`RoomStatusBar Shared History Visibility Acknowledgement should not render history visibility acknowledgement if it has previously been dismissed 1`] = `<div />`;
129+
130+
exports[`RoomStatusBar Shared History Visibility Acknowledgement should not render history visibility acknowledgement in encrypted rooms with joined history visibility 1`] = `<div />`;
131+
132+
exports[`RoomStatusBar Shared History Visibility Acknowledgement should not render history visibility acknowledgement in unencrypted rooms 1`] = `<div />`;
133+
134+
exports[`RoomStatusBar Shared History Visibility Acknowledgement should render dismissable history visibility acknowledgement in encrypted rooms with non-join history visibility 1`] = `
135+
<div>
136+
<div
137+
class="mx_RoomStatusBar mx_RoomStatusBar_historyVisibility"
138+
>
139+
<div
140+
role="alert"
141+
>
142+
<div
143+
class="mx_RoomStatusBar_historyVisibilityBadge"
144+
>
145+
<svg
146+
fill="currentColor"
147+
height="1em"
148+
viewBox="0 0 24 24"
149+
width="1em"
150+
xmlns="http://www.w3.org/2000/svg"
151+
>
152+
<path
153+
d="M11.288 7.288A.97.97 0 0 1 12 7q.424 0 .713.287Q13 7.576 13 8t-.287.713A.97.97 0 0 1 12 9a.97.97 0 0 1-.713-.287A.97.97 0 0 1 11 8q0-.424.287-.713m.001 4.001A.97.97 0 0 1 12 11q.424 0 .713.287.287.288.287.713v4q0 .424-.287.712A.97.97 0 0 1 12 17a.97.97 0 0 1-.713-.288A.97.97 0 0 1 11 16v-4q0-.424.287-.713"
154+
/>
155+
<path
156+
clip-rule="evenodd"
157+
d="M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10m-2 0a8 8 0 1 1-16 0 8 8 0 0 1 16 0"
158+
fill-rule="evenodd"
159+
/>
160+
</svg>
161+
</div>
162+
<div>
163+
<div
164+
class="mx_RoomStatusBar_historyVisibilityDescription"
165+
>
166+
Messages you send will be shared with new members invited to this room.
167+
</div>
168+
<a
169+
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_link_inline"
170+
href="https://examplecom"
171+
rel="noreferrer noopener"
172+
role="button"
173+
tabindex="0"
174+
target="_blank"
175+
>
176+
Learn more
177+
</a>
178+
</div>
179+
<div
180+
class="mx_RoomStatusBar_historyVisibilityButtonBar"
181+
>
182+
<div
183+
class="mx_AccessibleButton mx_RoomStatusBar_historyVisibilityButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary"
184+
role="button"
185+
tabindex="0"
186+
>
187+
Dismiss
188+
</div>
189+
</div>
190+
</div>
191+
</div>
192+
</div>
193+
`;

0 commit comments

Comments
 (0)