mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:31:27 +00:00
@room in user suggestions (#1880)
* for now I am using a local RTE solution, need to fix one test * fixed a test * new rte version * pr suggestions * @room added to the suggestions * removed empty space * revert * code improvement * project updated * package
This commit is contained in:
@@ -49,5 +49,42 @@ final class CompletionSuggestionServiceTests: XCTestCase {
|
||||
}
|
||||
service.setSuggestionTrigger(.init(type: .user, text: "me"))
|
||||
try await deferred.fulfill()
|
||||
|
||||
deferred = deferFulfillment(service.suggestionsPublisher) { suggestions in
|
||||
suggestions == []
|
||||
}
|
||||
service.setSuggestionTrigger(.init(type: .user, text: "room"))
|
||||
try await deferred.fulfill()
|
||||
|
||||
deferred = deferFulfillment(service.suggestionsPublisher) { suggestions in
|
||||
suggestions == []
|
||||
}
|
||||
service.setSuggestionTrigger(.init(type: .user, text: "everyon"))
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
|
||||
func testUserSuggestonsIncludingAllUsers() async throws {
|
||||
let alice: RoomMemberProxyMock = .mockAlice
|
||||
let members: [RoomMemberProxyMock] = [alice, .mockBob, .mockCharlie, .mockMe]
|
||||
let roomProxyMock = RoomProxyMock(with: .init(displayName: "test", members: members, canUserTriggerRoomNotification: true))
|
||||
let service = CompletionSuggestionService(roomProxy: roomProxyMock, areSuggestionsEnabled: true)
|
||||
|
||||
var deferred = deferFulfillment(service.suggestionsPublisher) { suggestions in
|
||||
suggestions == []
|
||||
}
|
||||
|
||||
try await deferred.fulfill()
|
||||
|
||||
deferred = deferFulfillment(service.suggestionsPublisher) { suggestions in
|
||||
suggestions == [.allUsers(item: .allUsersMention(roomAvatar: nil))]
|
||||
}
|
||||
service.setSuggestionTrigger(.init(type: .user, text: "ro"))
|
||||
try await deferred.fulfill()
|
||||
|
||||
deferred = deferFulfillment(service.suggestionsPublisher) { suggestions in
|
||||
suggestions == [.allUsers(item: .allUsersMention(roomAvatar: nil))]
|
||||
}
|
||||
service.setSuggestionTrigger(.init(type: .user, text: "every"))
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,14 +123,24 @@ class ComposerToolbarViewModelTests: XCTestCase {
|
||||
XCTAssertEqual(completionSuggestionServiceMock.setSuggestionTriggerReceivedInvocations, [nil, .init(type: .user, text: "test"), nil])
|
||||
}
|
||||
|
||||
func testSelectedSuggestion() {
|
||||
func testSelectedUserSuggestion() {
|
||||
let suggestion = SuggestionItem.user(item: .init(id: "@test:matrix.org", displayName: "Test", avatarURL: nil))
|
||||
viewModel.context.send(viewAction: .selectedSuggestion(suggestion))
|
||||
|
||||
XCTAssertEqual(wysiwygViewModel.content.html, "<a data-mention-type=\"user\" href=\"https://matrix.to/#/@test:matrix.org\" contenteditable=\"false\">Test</a> ")
|
||||
XCTAssertEqual(wysiwygViewModel.content.html, "<a href=\"https://matrix.to/#/@test:matrix.org\">Test</a> ")
|
||||
}
|
||||
|
||||
func testUserMentionInRTE() {
|
||||
func testAllUsersSuggestion() {
|
||||
let suggestion = SuggestionItem.allUsers(item: .allUsersMention(roomAvatar: nil))
|
||||
viewModel.context.send(viewAction: .selectedSuggestion(suggestion))
|
||||
|
||||
var string = "@room"
|
||||
// swiftlint:disable:next force_unwrapping
|
||||
string.unicodeScalars.append(UnicodeScalar(String.nbsp)!)
|
||||
XCTAssertEqual(wysiwygViewModel.content.html, string)
|
||||
}
|
||||
|
||||
func testUserMentionPillInRTE() {
|
||||
let userID = "@test:matrix.org"
|
||||
let suggestion = SuggestionItem.user(item: .init(id: userID, displayName: "Test", avatarURL: nil))
|
||||
viewModel.context.send(viewAction: .selectedSuggestion(suggestion))
|
||||
@@ -138,4 +148,12 @@ class ComposerToolbarViewModelTests: XCTestCase {
|
||||
let attachment = wysiwygViewModel.textView.attributedText.attribute(.attachment, at: 0, effectiveRange: nil) as? PillTextAttachment
|
||||
XCTAssertEqual(attachment?.pillData?.type, .user(userID: userID))
|
||||
}
|
||||
|
||||
func testAllUsersMentionPillInRTE() {
|
||||
let suggestion = SuggestionItem.allUsers(item: .allUsersMention(roomAvatar: nil))
|
||||
viewModel.context.send(viewAction: .selectedSuggestion(suggestion))
|
||||
|
||||
let attachment = wysiwygViewModel.textView.attributedText.attribute(.attachment, at: 0, effectiveRange: nil) as? PillTextAttachment
|
||||
XCTAssertEqual(attachment?.pillData?.type, .allUsers)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user