Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Test that pinned messages reflect edits correctly (#7960)
Browse files Browse the repository at this point in the history
* Hide unpinnable pinned messages in more cases

Signed-off-by: Robin Townsend <[email protected]>

* Fix typo

Signed-off-by: Robin Townsend <[email protected]>

* Test that unpinnable pinned messages get hidden

Signed-off-by: Robin Townsend <[email protected]>

* Fix cli.relations error in test

Signed-off-by: Robin Townsend <[email protected]>

* Use event: true shortcut when calling mkEvent

Signed-off-by: Robin Townsend <[email protected]>

* Use mockResolvedValue instead of mockReturnValue for async mock

Signed-off-by: Robin Townsend <[email protected]>

* Actually mock redacted messages correctly

Signed-off-by: Robin Townsend <[email protected]>

* Ensure that panel is updated before assertions are made

Signed-off-by: Robin Townsend <[email protected]>

* Test that pinned messages reflect edits correctly

Signed-off-by: Robin Townsend <[email protected]>

* Fix warning about missing date

Signed-off-by: Robin Townsend <[email protected]>

* Move calls to update out of act

They don't need to be there.

Signed-off-by: Robin Townsend <[email protected]>

* Move calls to update out of act

They don't need to be there.

Signed-off-by: Robin Townsend <[email protected]>

* Fix lint

Signed-off-by: Robin Townsend <[email protected]>
  • Loading branch information
robintown authored Mar 3, 2022
1 parent c42ef0d commit 8a7ffb4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
53 changes: 50 additions & 3 deletions test/components/views/right_panel/PinnedMessagesCard-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ import React from "react";
import { mount } from "enzyme";
import { act } from "react-dom/test-utils";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { EventType, RelationType, MsgType } from "matrix-js-sdk/src/@types/event";

import "../../../skinned-sdk";
import { stubClient, wrapInMatrixClientContext, mkStubRoom, mkEvent } from "../../../test-utils";
import {
stubClient,
wrapInMatrixClientContext,
mkStubRoom,
mkEvent,
mkMessage,
} from "../../../test-utils";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import _PinnedMessagesCard from "../../../../src/components/views/right_panel/PinnedMessagesCard";
import PinnedEventTile from "../../../../src/components/views/rooms/PinnedEventTile";
Expand All @@ -35,7 +41,7 @@ describe("<PinnedMessagesCard />", () => {

const mkRoom = (localPins: MatrixEvent[], nonLocalPins: MatrixEvent[]) => {
const pins = [...localPins, ...nonLocalPins];
const room = mkStubRoom();
const room = mkStubRoom("!room:example.org");

// Insert pin IDs into room state
const pinState = mkEvent({
Expand Down Expand Up @@ -97,4 +103,45 @@ describe("<PinnedMessagesCard />", () => {
pins.update();
expect(pins.find(PinnedEventTile).length).toBe(0);
});

it("accounts for edits", async () => {
const pin = mkMessage({
event: true,
room: "!room:example.org",
user: "@alice:example.org",
msg: "Hello!",
});
cli.relations.mockResolvedValue({
events: [mkEvent({
event: true,
type: EventType.RoomMessage,
room: "!room:example.org",
user: "@alice:example.org",
content: {
"msgtype": MsgType.Text,
"body": " * Hello again!",
"m.new_content": {
msgtype: MsgType.Text,
body: "Hello again!",
},
"m.relates_to": {
rel_type: RelationType.Replace,
event_id: pin.getId(),
},
},
})],
});

let pins;
await act(async () => {
pins = mount(<PinnedMessagesCard room={mkRoom([], [pin])} onClose={() => {}} />);
// Wait a tick for state updates
await new Promise(resolve => setImmediate(resolve));
});
pins.update();

const pinTile = pins.find(PinnedEventTile);
expect(pinTile.length).toBe(1);
expect(pinTile.find(".mx_EventTile_body").text()).toEqual("Hello again!");
});
});
2 changes: 1 addition & 1 deletion test/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function mkEvent(opts: MakeEventProps): MatrixEvent {
content: opts.content,
prev_content: opts.prev_content,
event_id: "$" + Math.random() + "-" + Math.random(),
origin_server_ts: opts.ts,
origin_server_ts: opts.ts ?? 0,
unsigned: opts.unsigned,
};
if (opts.skey) {
Expand Down

0 comments on commit 8a7ffb4

Please sign in to comment.