Skip to content

Commit 5a64f24

Browse files
committed
cleanup
1 parent 4c203d3 commit 5a64f24

3 files changed

Lines changed: 117 additions & 5 deletions

File tree

apps/web/src/components/structures/ThreadView.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,13 @@ export default class ThreadView extends React.Component<IProps, IState> {
168168
switch (payload.action) {
169169
case Action.ComposerInsert: {
170170
const insertPayload = payload as ComposerInsertPayload;
171-
const timelineRenderingType = insertPayload.timelineRenderingType;
172171
if (insertPayload.composerType) break;
173-
if (timelineRenderingType !== TimelineRenderingType.Thread) break;
172+
if (insertPayload.timelineRenderingType !== TimelineRenderingType.Thread) break;
174173

175174
// re-dispatch to the correct composer
176175
dis.dispatch<ComposerInsertPayload>({
177176
...insertPayload,
178-
timelineRenderingType,
177+
timelineRenderingType: TimelineRenderingType.Thread,
179178
composerType: this.state.editState ? ComposerType.Edit : ComposerType.Send,
180179
});
181180
break;

apps/web/test/unit-tests/components/structures/RoomView-test.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,6 @@ describe("RoomView", () => {
10781078

10791079
describe("handles Action.ComposerInsert", () => {
10801080
it("redispatches an empty composerType, timelineRenderingType with the current state", async () => {
1081-
jest.spyOn(defaultDispatcher, "dispatch");
10821081
await mountRoomView();
10831082
const promise = untilDispatch((payload) => {
10841083
try {
@@ -1100,7 +1099,6 @@ describe("RoomView", () => {
11001099
await promise;
11011100
});
11021101
it("redispatches an empty composerType with the current state", async () => {
1103-
jest.spyOn(defaultDispatcher, "dispatch");
11041102
await mountRoomView();
11051103
const promise = untilDispatch((payload) => {
11061104
try {
@@ -1122,6 +1120,34 @@ describe("RoomView", () => {
11221120
} satisfies ComposerInsertPayload);
11231121
await promise;
11241122
});
1123+
it("ignores payloads with a timelineRenderingType != TimelineRenderingType.Thread", async () => {
1124+
await mountRoomView();
1125+
const promise = untilDispatch(
1126+
(payload) => {
1127+
try {
1128+
expect(payload).toStrictEqual({
1129+
action: Action.ComposerInsert,
1130+
text: "Hello world",
1131+
timelineRenderingType: TimelineRenderingType.Thread,
1132+
composerType: ComposerType.Send,
1133+
});
1134+
} catch {
1135+
return false;
1136+
}
1137+
return true;
1138+
},
1139+
defaultDispatcher,
1140+
500,
1141+
);
1142+
defaultDispatcher.dispatch({
1143+
action: Action.ComposerInsert,
1144+
text: "Hello world",
1145+
composerType: ComposerType.Send,
1146+
timelineRenderingType: TimelineRenderingType.Room,
1147+
viaTest: true,
1148+
} satisfies ComposerInsertPayload);
1149+
await expect(promise).rejects.toThrow();
1150+
});
11251151
});
11261152

11271153
describe("when there is a RoomView", () => {

apps/web/test/unit-tests/components/structures/ThreadView-test.tsx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ import { getRoomContext } from "../../../test-utils/room";
3434
import { mkMessage, stubClient } from "../../../test-utils/test-utils";
3535
import { mkThread } from "../../../test-utils/threads";
3636
import { ScopedRoomContextProvider } from "../../../../src/contexts/ScopedRoomContext.tsx";
37+
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
38+
import { untilDispatch } from "../../../test-utils/utilities.ts";
39+
import { TimelineRenderingType } from "../../../../src/contexts/RoomContext.ts";
40+
import { ComposerInsertPayload, ComposerType } from "../../../../src/dispatcher/payloads/ComposerInsertPayload.ts";
3741

3842
describe("ThreadView", () => {
3943
const ROOM_ID = "!roomId:example.org";
@@ -209,4 +213,87 @@ describe("ThreadView", () => {
209213
metricsTrigger: undefined,
210214
});
211215
});
216+
217+
describe("handles Action.ComposerInsert", () => {
218+
it("redispatches a payload of timelineRenderingType=Thread", async () => {
219+
await getComponent();
220+
const promise = untilDispatch((payload) => {
221+
try {
222+
expect(payload).toEqual({
223+
action: Action.ComposerInsert,
224+
text: "Hello world",
225+
timelineRenderingType: TimelineRenderingType.Thread,
226+
composerType: ComposerType.Send,
227+
});
228+
} catch {
229+
return false;
230+
}
231+
return true;
232+
}, defaultDispatcher);
233+
defaultDispatcher.dispatch({
234+
action: Action.ComposerInsert,
235+
text: "Hello world",
236+
timelineRenderingType: TimelineRenderingType.Thread,
237+
} satisfies ComposerInsertPayload);
238+
await promise;
239+
});
240+
it("ignores payloads with a composerType", async () => {
241+
await getComponent();
242+
const promise = untilDispatch(
243+
(payload) => {
244+
try {
245+
expect(payload).toStrictEqual({
246+
action: Action.ComposerInsert,
247+
text: "Hello world",
248+
timelineRenderingType: TimelineRenderingType.Thread,
249+
composerType: ComposerType.Send,
250+
});
251+
} catch {
252+
return false;
253+
}
254+
return true;
255+
},
256+
defaultDispatcher,
257+
500,
258+
);
259+
defaultDispatcher.dispatch({
260+
action: Action.ComposerInsert,
261+
text: "Hello world",
262+
composerType: ComposerType.Send,
263+
timelineRenderingType: TimelineRenderingType.Thread,
264+
// Ensure we don't accidentally pick up this emit by strictly checking above.
265+
viaTest: true,
266+
} satisfies ComposerInsertPayload);
267+
await expect(promise).rejects.toThrow();
268+
});
269+
it("ignores payloads with a timelineRenderingType != TimelineRenderingType.Thread", async () => {
270+
await getComponent();
271+
const promise = untilDispatch(
272+
(payload) => {
273+
try {
274+
expect(payload).toStrictEqual({
275+
action: Action.ComposerInsert,
276+
text: "Hello world",
277+
timelineRenderingType: TimelineRenderingType.Thread,
278+
composerType: ComposerType.Send,
279+
});
280+
} catch {
281+
return false;
282+
}
283+
return true;
284+
},
285+
defaultDispatcher,
286+
500,
287+
);
288+
defaultDispatcher.dispatch({
289+
action: Action.ComposerInsert,
290+
text: "Hello world",
291+
composerType: ComposerType.Send,
292+
timelineRenderingType: TimelineRenderingType.Room,
293+
// Ensure we don't accidentally pick up this emit by strictly checking above.
294+
viaTest: true,
295+
} satisfies ComposerInsertPayload);
296+
await expect(promise).rejects.toThrow();
297+
});
298+
});
212299
});

0 commit comments

Comments
 (0)