Allow thread panel to be closed after being opened from notification (#9937)
* Allow thread panel to be closed after being opened from notification * Add test to ensure the behavior is correct
This commit is contained in:
parent
056fec844f
commit
a0a419a3b8
2 changed files with 28 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2021 - 2022 The Matrix.org Foundation C.I.C.
|
Copyright 2021 - 2023 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -123,7 +123,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
|
||||||
SettingsStore.unwatchSetting(this.layoutWatcherRef);
|
SettingsStore.unwatchSetting(this.layoutWatcherRef);
|
||||||
|
|
||||||
const hasRoomChanged = SdkContextClass.instance.roomViewStore.getRoomId() !== roomId;
|
const hasRoomChanged = SdkContextClass.instance.roomViewStore.getRoomId() !== roomId;
|
||||||
if (this.props.isInitialEventHighlighted && !hasRoomChanged) {
|
if (this.props.initialEvent && !hasRoomChanged) {
|
||||||
dis.dispatch<ViewRoomPayload>({
|
dis.dispatch<ViewRoomPayload>({
|
||||||
action: Action.ViewRoom,
|
action: Action.ViewRoom,
|
||||||
room_id: this.props.room.roomId,
|
room_id: this.props.room.roomId,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
Copyright 2022-2023 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -29,6 +29,8 @@ import ThreadView from "../../../src/components/structures/ThreadView";
|
||||||
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
|
||||||
import RoomContext from "../../../src/contexts/RoomContext";
|
import RoomContext from "../../../src/contexts/RoomContext";
|
||||||
import { SdkContextClass } from "../../../src/contexts/SDKContext";
|
import { SdkContextClass } from "../../../src/contexts/SDKContext";
|
||||||
|
import { Action } from "../../../src/dispatcher/actions";
|
||||||
|
import dispatcher from "../../../src/dispatcher/dispatcher";
|
||||||
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
|
||||||
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
import DMRoomMap from "../../../src/utils/DMRoomMap";
|
||||||
import ResizeNotifier from "../../../src/utils/ResizeNotifier";
|
import ResizeNotifier from "../../../src/utils/ResizeNotifier";
|
||||||
|
@ -47,7 +49,7 @@ describe("ThreadView", () => {
|
||||||
|
|
||||||
let changeEvent: (event: MatrixEvent) => void;
|
let changeEvent: (event: MatrixEvent) => void;
|
||||||
|
|
||||||
function TestThreadView() {
|
function TestThreadView({ initialEvent }: { initialEvent?: MatrixEvent }) {
|
||||||
const [event, setEvent] = useState(rootEvent);
|
const [event, setEvent] = useState(rootEvent);
|
||||||
changeEvent = setEvent;
|
changeEvent = setEvent;
|
||||||
|
|
||||||
|
@ -58,15 +60,21 @@ describe("ThreadView", () => {
|
||||||
canSendMessages: true,
|
canSendMessages: true,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<ThreadView room={room} onClose={jest.fn()} mxEvent={event} resizeNotifier={new ResizeNotifier()} />
|
<ThreadView
|
||||||
|
room={room}
|
||||||
|
onClose={jest.fn()}
|
||||||
|
mxEvent={event}
|
||||||
|
initialEvent={initialEvent}
|
||||||
|
resizeNotifier={new ResizeNotifier()}
|
||||||
|
/>
|
||||||
</RoomContext.Provider>
|
</RoomContext.Provider>
|
||||||
,
|
,
|
||||||
</MatrixClientContext.Provider>
|
</MatrixClientContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getComponent(): Promise<RenderResult> {
|
async function getComponent(initialEvent?: MatrixEvent): Promise<RenderResult> {
|
||||||
const renderResult = render(<TestThreadView />);
|
const renderResult = render(<TestThreadView initialEvent={initialEvent} />);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(() => getByTestId(renderResult.container, "spinner")).toThrow();
|
expect(() => getByTestId(renderResult.container, "spinner")).toThrow();
|
||||||
|
@ -171,4 +179,17 @@ describe("ThreadView", () => {
|
||||||
unmount();
|
unmount();
|
||||||
await waitFor(() => expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBeNull());
|
await waitFor(() => expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBeNull());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("clears highlight message in the room view store", async () => {
|
||||||
|
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(room.roomId);
|
||||||
|
const mock = jest.spyOn(dispatcher, "dispatch");
|
||||||
|
const { unmount } = await getComponent(rootEvent);
|
||||||
|
mock.mockClear();
|
||||||
|
unmount();
|
||||||
|
expect(mock).toHaveBeenCalledWith({
|
||||||
|
action: Action.ViewRoom,
|
||||||
|
room_id: room.roomId,
|
||||||
|
metricsTrigger: undefined,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue