diff --git a/RiotTests/MatrixKitTests/MXKEventFormatter+Tests.h b/RiotTests/MatrixKitTests/MXKEventFormatter+Tests.h
index 8aa5a9c1e..e7f3ccb6a 100644
--- a/RiotTests/MatrixKitTests/MXKEventFormatter+Tests.h
+++ b/RiotTests/MatrixKitTests/MXKEventFormatter+Tests.h
@@ -20,5 +20,6 @@
- (NSString*)userDisplayNameFromContentInEvent:(MXEvent*)event withMembershipFilter:(NSString *)filter;
- (NSString*)userAvatarUrlFromContentInEvent:(MXEvent*)event withMembershipFilter:(NSString *)filter;
+- (NSString*)buildHTMLStringForEvent:(MXEvent*)event inReplyToEvent:(MXEvent*)repliedEvent;
@end
diff --git a/RiotTests/MatrixKitTests/MXKEventFormatterTests.m b/RiotTests/MatrixKitTests/MXKEventFormatterTests.m
index 089d93810..fbe801665 100644
--- a/RiotTests/MatrixKitTests/MXKEventFormatterTests.m
+++ b/RiotTests/MatrixKitTests/MXKEventFormatterTests.m
@@ -22,7 +22,7 @@
@import DTCoreText;
-@interface MXEventFormatterTests : XCTestCase
+@interface MXKEventFormatterTests : XCTestCase
{
MXKEventFormatter *eventFormatter;
MXEvent *anEvent;
@@ -31,7 +31,7 @@
@end
-@implementation MXEventFormatterTests
+@implementation MXKEventFormatterTests
- (void)setUp
{
diff --git a/RiotTests/MatrixKitTests/MXKEventFormatterTests.swift b/RiotTests/MatrixKitTests/MXKEventFormatterTests.swift
new file mode 100644
index 000000000..31db30954
--- /dev/null
+++ b/RiotTests/MatrixKitTests/MXKEventFormatterTests.swift
@@ -0,0 +1,76 @@
+//
+// Copyright 2022 New Vector Ltd
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+import XCTest
+import MatrixSDK
+
+private enum Constants {
+ static let roomId = "someRoomId"
+ static let repliedEventId = "repliedEventId"
+ static let repliedEventBody = "Test message"
+ static let repliedEventEditedBody = "Edited message"
+ static let repliedEventNewContentBody = "New content"
+ static let replyBody = "> <@alice:matrix.org> Test message\n\nReply"
+ static let replyFormattedBodyWithItalic = "In reply to alice
Test message
Reply"
+ static let expectedHTML = "In reply to alice
Test message
Reply"
+ static let expectedEditedHTML = "In reply to alice
Edited message
Reply"
+ static let expectedEditedHTMLWithNewContent = "In reply to alice
New content
Reply"
+ static let expectedEditedHTMLWithParsedItalic = "In reply to alice
New content
Reply"
+}
+
+class MXKEventFormatterTests: XCTestCase {
+ func testBuildHTMLString() {
+ let formatter = MXKEventFormatter()
+ let repliedEvent = MXEvent()
+ let event = MXEvent()
+ func buildHTML() -> String? { return formatter.buildHTMLString(for: event, inReplyTo: repliedEvent) }
+
+ // Initial setup.
+ repliedEvent.sender = "alice"
+ repliedEvent.roomId = Constants.roomId
+ repliedEvent.eventId = Constants.repliedEventId
+ repliedEvent.wireType = kMXEventTypeStringRoomMessage
+ repliedEvent.wireContent = [kMXMessageTypeKey: kMXMessageTypeText,
+ kMXMessageBodyKey: Constants.repliedEventBody]
+ event.sender = "bob"
+ event.wireType = kMXEventTypeStringRoomMessage
+ event.wireContent = [
+ kMXMessageTypeKey: kMXMessageTypeText,
+ kMXMessageBodyKey: Constants.replyBody,
+ kMXEventRelationRelatesToKey: [kMXEventContentRelatesToKeyInReplyTo: ["event_id": Constants.repliedEventId]]
+ ]
+
+ // Default render.
+ XCTAssertEqual(buildHTML(), Constants.expectedHTML)
+
+ // Render after edition.
+ repliedEvent.wireContent[kMXMessageBodyKey] = Constants.repliedEventEditedBody
+ XCTAssertEqual(buildHTML(), Constants.expectedEditedHTML)
+
+ // m.new_content has prioritiy over base content.
+ repliedEvent.wireContent[kMXMessageContentKeyNewContent] = [kMXMessageBodyKey: Constants.repliedEventNewContentBody]
+ XCTAssertEqual(buildHTML(), Constants.expectedEditedHTMLWithNewContent)
+
+ // If reply's formatted_body is available it's used to construct a brand new HTML.
+ event.wireContent["formatted_body"] = Constants.replyFormattedBodyWithItalic
+ XCTAssertEqual(buildHTML(), Constants.expectedEditedHTMLWithParsedItalic)
+
+ // If content from replied event is missing. Reply can't be constructed (client will use fallback).
+ repliedEvent.wireContent[kMXMessageBodyKey] = nil
+ repliedEvent.wireContent[kMXMessageContentKeyNewContent] = nil
+ XCTAssertNil(buildHTML())
+ }
+}
diff --git a/RiotTests/MatrixKitTests/MatrixKitTests-Bridging-Header.h b/RiotTests/MatrixKitTests/MatrixKitTests-Bridging-Header.h
index b3d959c69..648b077d9 100644
--- a/RiotTests/MatrixKitTests/MatrixKitTests-Bridging-Header.h
+++ b/RiotTests/MatrixKitTests/MatrixKitTests-Bridging-Header.h
@@ -3,3 +3,4 @@
//
#import "MXKRoomDataSource+Tests.h"
+#import "MXKEventFormatter+Tests.h"
diff --git a/changelog.d/pr-6380.change b/changelog.d/pr-6380.change
new file mode 100644
index 000000000..1465b71f0
--- /dev/null
+++ b/changelog.d/pr-6380.change
@@ -0,0 +1 @@
+Add formatter build reply HTML unit tests