@@ -93,7 +175,7 @@ exports[`
should render the expected pill for a room alias 1`] = `
/>
Room 1
@@ -133,7 +215,7 @@ exports[` should render the expected pill for a space 1`] = `
/>
Space 1
@@ -173,7 +255,7 @@ exports[` should render the expected pill for a user not in the room 1`] =
/>
User 2
@@ -213,7 +295,7 @@ exports[` when rendering a pill for a room should render the expected pill
/>
Room 1
@@ -253,7 +335,7 @@ exports[` when rendering a pill for a user in the room should render as ex
/>
User 1
diff --git a/test/components/views/messages/TextualBody-test.tsx b/test/components/views/messages/TextualBody-test.tsx
index 194b32c430..d597a0f0d0 100644
--- a/test/components/views/messages/TextualBody-test.tsx
+++ b/test/components/views/messages/TextualBody-test.tsx
@@ -63,6 +63,9 @@ describe("", () => {
isGuest: () => false,
mxcUrlToHttp: (s: string) => s,
getUserId: () => "@user:example.com",
+ fetchRoomEvent: () => {
+ throw new Error("MockClient event not found");
+ },
});
});
@@ -172,7 +175,7 @@ describe("", () => {
const { container } = getComponent({ mxEvent: ev });
const content = container.querySelector(".mx_EventTile_body");
expect(content.innerHTML).toMatchInlineSnapshot(
- `"Chat with Member"`,
+ `"Chat with Member"`,
);
});
@@ -190,7 +193,7 @@ describe("", () => {
const { container } = getComponent({ mxEvent: ev });
const content = container.querySelector(".mx_EventTile_body");
expect(content.innerHTML).toMatchInlineSnapshot(
- `"Visit #room:example.com"`,
+ `"Visit #room:example.com"`,
);
});
});
@@ -275,23 +278,26 @@ describe("", () => {
expect(content).toMatchSnapshot();
});
- it("pills do not appear for event permalinks", () => {
+ it("pills do not appear for event permalinks with a custom label", () => {
const ev = mkFormattedMessage(
"An [event link](https://matrix.to/#/!ZxbRYPQXDXKGmDnJNg:example.com/" +
"$16085560162aNpaH:example.com?via=example.com) with text",
-
'An event link with text',
);
- const { container } = getComponent({ mxEvent: ev }, matrixClient);
+ const { asFragment, container } = getComponent({ mxEvent: ev }, matrixClient);
expect(container).toHaveTextContent("An event link with text");
- const content = container.querySelector(".mx_EventTile_body");
- expect(content).toContainHTML(
- '' +
- 'An event link with text',
+ expect(asFragment()).toMatchSnapshot();
+ });
+
+ it("pills appear for event permalinks without a custom label", () => {
+ const ev = mkFormattedMessage(
+ "See this message https://matrix.to/#/!ZxbRYPQXDXKGmDnJNg:example.com/$16085560162aNpaH:example.com?via=example.com",
+ 'See this message ' +
+ "https://matrix.to/#/!ZxbRYPQXDXKGmDnJNg:example.com/$16085560162aNpaH:example.com?via=example.com",
);
+ const { asFragment } = getComponent({ mxEvent: ev }, matrixClient);
+ expect(asFragment()).toMatchSnapshot();
});
it("pills appear for room links with vias", () => {
@@ -301,19 +307,9 @@ describe("", () => {
'A room link with vias',
);
- const { container } = getComponent({ mxEvent: ev }, matrixClient);
+ const { asFragment, container } = getComponent({ mxEvent: ev }, matrixClient);
expect(container).toHaveTextContent("A room name with vias");
- const content = container.querySelector(".mx_EventTile_body");
- expect(content).toContainHTML(
- '' +
- 'A ' +
- 'room name with vias',
- );
+ expect(asFragment()).toMatchSnapshot();
});
it("pills appear for an MXID permalink", () => {
diff --git a/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap b/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap
index 166749bd3b..28fe92c48b 100644
--- a/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap
+++ b/test/components/views/messages/__snapshots__/TextualBody-test.tsx.snap
@@ -62,7 +62,7 @@ exports[` renders formatted m.text correctly pills appear for an
style="width: 16px; height: 16px;"
/>
Member
@@ -72,6 +72,104 @@ exports[` renders formatted m.text correctly pills appear for an
`;
+exports[` renders formatted m.text correctly pills appear for event permalinks without a custom label 1`] = `
+
+
+
+ See this message
+
+
+
+ Message in
+
+
+ room name
+
+
+
+
+
+
+
+`;
+
+exports[` renders formatted m.text correctly pills appear for room links with vias 1`] = `
+
+
+
+ A
+
+
+
+
+
+ room name
+
+
+
+
+ with vias
+
+
+
+`;
+
+exports[` renders formatted m.text correctly pills do not appear for event permalinks with a custom label 1`] = `
+
+
+
+ An
+
+ event link
+
+ with text
+
+
+
+`;
+
exports[` renders formatted m.text correctly pills do not appear in code blocks 1`] = `
renders formatted m.text correctly pills get injected c
style="width: 16px; height: 16px;"
/>
Member
diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts
index c28ccb3d58..05e86a3b8f 100644
--- a/test/test-utils/test-utils.ts
+++ b/test/test-utils/test-utils.ts
@@ -255,6 +255,8 @@ type MakeEventPassThruProps = {
skey?: string;
};
type MakeEventProps = MakeEventPassThruProps & {
+ /** If provided will be used as event Id. Else an Id is generated. */
+ id?: string;
type: string;
redacts?: string;
content: IContent;
@@ -301,7 +303,7 @@ export function mkEvent(opts: MakeEventProps): MatrixEvent {
sender: opts.user,
content: opts.content,
prev_content: opts.prev_content,
- event_id: "$" + Math.random() + "-" + Math.random(),
+ event_id: opts.id ?? "$" + Math.random() + "-" + Math.random(),
origin_server_ts: opts.ts ?? 0,
unsigned: opts.unsigned,
redacts: opts.redacts,
@@ -483,12 +485,13 @@ export function mkMessage({
formattedMsg,
relatesTo,
...opts
-}: MakeEventPassThruProps & {
- room: Room["roomId"];
- msg?: string;
- format?: string;
- formattedMsg?: string;
-}): MatrixEvent {
+}: MakeEventPassThruProps &
+ Pick & {
+ room: Room["roomId"];
+ msg?: string;
+ format?: string;
+ formattedMsg?: string;
+ }): MatrixEvent {
if (!opts.room || !opts.user) {
throw new Error("Missing .room or .user from options");
}