This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Improve message body output from plain text editor #11124
Merged
alunturner
merged 5 commits into
develop
from
alunturner/plaintext-message-output-improvements
Jun 21, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5a25f6
Merge remote-tracking branch 'origin/develop' into alunturner/plainte…
b09ddbd
add failing test
77bfd96
WIP - pause work until we can implement with new patch release of RTE
3b093da
focus tests purely on the body output
2816c8f
remove unused import
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,117 +41,146 @@ describe("createMessageContent", () => { | |
jest.resetAllMocks(); | ||
}); | ||
|
||
it("Should create html message", async () => { | ||
// When | ||
const content = await createMessageContent(message, true, { permalinkCreator }); | ||
|
||
// Then | ||
expect(content).toEqual({ | ||
body: "*__hello__ world*", | ||
format: "org.matrix.custom.html", | ||
formatted_body: message, | ||
msgtype: "m.text", | ||
describe("Richtext composer input", () => { | ||
it("Should create html message", async () => { | ||
// When | ||
const content = await createMessageContent(message, true, { permalinkCreator }); | ||
|
||
// Then | ||
expect(content).toEqual({ | ||
body: "*__hello__ world*", | ||
format: "org.matrix.custom.html", | ||
formatted_body: message, | ||
msgtype: "m.text", | ||
}); | ||
}); | ||
}); | ||
|
||
it("Should add reply to message content", async () => { | ||
// When | ||
const content = await createMessageContent(message, true, { permalinkCreator, replyToEvent: mockEvent }); | ||
|
||
// Then | ||
expect(content).toEqual({ | ||
"body": "> <myfakeuser> Replying to this\n\n*__hello__ world*", | ||
"format": "org.matrix.custom.html", | ||
"formatted_body": | ||
'<mx-reply><blockquote><a href="$$permalink$$">In reply to</a>' + | ||
' <a href="https://matrix.to/#/myfakeuser">myfakeuser</a>' + | ||
"<br>Replying to this</blockquote></mx-reply><em><b>hello</b> world</em>", | ||
"msgtype": "m.text", | ||
"m.relates_to": { | ||
"m.in_reply_to": { | ||
event_id: mockEvent.getId(), | ||
it("Should add reply to message content", async () => { | ||
// When | ||
const content = await createMessageContent(message, true, { permalinkCreator, replyToEvent: mockEvent }); | ||
|
||
// Then | ||
expect(content).toEqual({ | ||
"body": "> <myfakeuser> Replying to this\n\n*__hello__ world*", | ||
"format": "org.matrix.custom.html", | ||
"formatted_body": | ||
'<mx-reply><blockquote><a href="$$permalink$$">In reply to</a>' + | ||
' <a href="https://matrix.to/#/myfakeuser">myfakeuser</a>' + | ||
"<br>Replying to this</blockquote></mx-reply><em><b>hello</b> world</em>", | ||
"msgtype": "m.text", | ||
"m.relates_to": { | ||
"m.in_reply_to": { | ||
event_id: mockEvent.getId(), | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
it("Should add relation to message", async () => { | ||
// When | ||
const relation = { | ||
rel_type: "m.thread", | ||
event_id: "myFakeThreadId", | ||
}; | ||
const content = await createMessageContent(message, true, { permalinkCreator, relation }); | ||
|
||
// Then | ||
expect(content).toEqual({ | ||
"body": "*__hello__ world*", | ||
"format": "org.matrix.custom.html", | ||
"formatted_body": message, | ||
"msgtype": "m.text", | ||
"m.relates_to": { | ||
event_id: "myFakeThreadId", | ||
it("Should add relation to message", async () => { | ||
// When | ||
const relation = { | ||
rel_type: "m.thread", | ||
}, | ||
event_id: "myFakeThreadId", | ||
}; | ||
const content = await createMessageContent(message, true, { permalinkCreator, relation }); | ||
|
||
// Then | ||
expect(content).toEqual({ | ||
"body": "*__hello__ world*", | ||
"format": "org.matrix.custom.html", | ||
"formatted_body": message, | ||
"msgtype": "m.text", | ||
"m.relates_to": { | ||
event_id: "myFakeThreadId", | ||
rel_type: "m.thread", | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
it("Should add fields related to edition", async () => { | ||
// When | ||
const editedEvent = mkEvent({ | ||
type: "m.room.message", | ||
room: "myfakeroom", | ||
user: "myfakeuser2", | ||
content: { | ||
it("Should add fields related to edition", async () => { | ||
// When | ||
const editedEvent = mkEvent({ | ||
type: "m.room.message", | ||
room: "myfakeroom", | ||
user: "myfakeuser2", | ||
content: { | ||
"msgtype": "m.text", | ||
"body": "First message", | ||
"formatted_body": "<b>First Message</b>", | ||
"m.relates_to": { | ||
"m.in_reply_to": { | ||
event_id: "eventId", | ||
}, | ||
}, | ||
}, | ||
event: true, | ||
}); | ||
const content = await createMessageContent(message, true, { permalinkCreator, editedEvent }); | ||
|
||
// Then | ||
expect(content).toEqual({ | ||
"body": " * *__hello__ world*", | ||
"format": "org.matrix.custom.html", | ||
"formatted_body": ` * ${message}`, | ||
"msgtype": "m.text", | ||
"body": "First message", | ||
"formatted_body": "<b>First Message</b>", | ||
"m.new_content": { | ||
body: "*__hello__ world*", | ||
format: "org.matrix.custom.html", | ||
formatted_body: message, | ||
msgtype: "m.text", | ||
}, | ||
"m.relates_to": { | ||
"m.in_reply_to": { | ||
event_id: "eventId", | ||
}, | ||
event_id: editedEvent.getId(), | ||
rel_type: "m.replace", | ||
}, | ||
}, | ||
event: true, | ||
}); | ||
}); | ||
const content = await createMessageContent(message, true, { permalinkCreator, editedEvent }); | ||
|
||
// Then | ||
expect(content).toEqual({ | ||
"body": " * *__hello__ world*", | ||
"format": "org.matrix.custom.html", | ||
"formatted_body": ` * ${message}`, | ||
"msgtype": "m.text", | ||
"m.new_content": { | ||
body: "*__hello__ world*", | ||
format: "org.matrix.custom.html", | ||
formatted_body: message, | ||
msgtype: "m.text", | ||
}, | ||
"m.relates_to": { | ||
event_id: editedEvent.getId(), | ||
rel_type: "m.replace", | ||
}, | ||
|
||
it("Should strip the /me prefix from a message", async () => { | ||
const textBody = "some body text"; | ||
const content = await createMessageContent(EMOTE_PREFIX + textBody, true, { permalinkCreator }); | ||
|
||
expect(content).toMatchObject({ body: textBody, formatted_body: textBody }); | ||
}); | ||
}); | ||
|
||
it("Should strip the /me prefix from a message", async () => { | ||
const textBody = "some body text"; | ||
const content = await createMessageContent(EMOTE_PREFIX + textBody, true, { permalinkCreator }); | ||
it("Should strip single / from message prefixed with //", async () => { | ||
const content = await createMessageContent("//twoSlashes", true, { permalinkCreator }); | ||
|
||
expect(content).toMatchObject({ body: textBody, formatted_body: textBody }); | ||
}); | ||
expect(content).toMatchObject({ body: "/twoSlashes", formatted_body: "/twoSlashes" }); | ||
}); | ||
|
||
it("Should strip single / from message prefixed with //", async () => { | ||
const content = await createMessageContent("//twoSlashes", true, { permalinkCreator }); | ||
it("Should set the content type to MsgType.Emote when /me prefix is used", async () => { | ||
const textBody = "some body text"; | ||
const content = await createMessageContent(EMOTE_PREFIX + textBody, true, { permalinkCreator }); | ||
|
||
expect(content).toMatchObject({ body: "/twoSlashes", formatted_body: "/twoSlashes" }); | ||
expect(content).toMatchObject({ msgtype: MsgType.Emote }); | ||
}); | ||
}); | ||
|
||
it("Should set the content type to MsgType.Emote when /me prefix is used", async () => { | ||
const textBody = "some body text"; | ||
const content = await createMessageContent(EMOTE_PREFIX + textBody, true, { permalinkCreator }); | ||
describe("Plaintext composer input", () => { | ||
it("Should replace at-room mentions with `@room` in body", async () => { | ||
const messageComposerState = `<a href="#" contenteditable="false" data-mention-type="at-room" style="some styling">@room</a> `; | ||
|
||
const content = await createMessageContent(messageComposerState, false, { permalinkCreator }); | ||
expect(content).toMatchObject({ body: "@room " }); | ||
}); | ||
|
||
it("Should replace user mentions with user name in body", async () => { | ||
const messageComposerState = `<a href="https://matrix.to/#/@test_user:element.io" contenteditable="false" data-mention-type="user" style="some styling">a test user</a> `; | ||
|
||
const content = await createMessageContent(messageComposerState, false, { permalinkCreator }); | ||
|
||
expect(content).toMatchObject({ msgtype: MsgType.Emote }); | ||
expect(content).toMatchObject({ body: "a test user " }); | ||
}); | ||
|
||
it("Should replace room mentions with room mxid in body", async () => { | ||
const messageComposerState = `<a href="https://matrix.to/#/#test_room:element.io" contenteditable="false" data-mention-type="room" style="some styling">a test room</a> `; | ||
|
||
const content = await createMessageContent(messageComposerState, false, { permalinkCreator }); | ||
|
||
expect(content).toMatchObject({ | ||
body: "#test_room:element.io ", | ||
}); | ||
}); | ||
Comment on lines
+160
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the new tests, all other changes in this file result from increased nesting |
||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds nesting to separate tests for rich text/plain text