mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Completion Suggestion view for user mentions (#1859)
* created the list but I need to find a way to overlay it * make the list able to have an intrinsic height * best solution so far but does not work with expansion * needs testing * more scalable solution * tests completed * changelog * injecting the media provider * fix tests * pr suggestions * better testing
This commit is contained in:
@@ -14,15 +14,18 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
@testable import ElementX
|
||||
import WysiwygComposer
|
||||
import XCTest
|
||||
|
||||
import WysiwygComposer
|
||||
|
||||
@MainActor
|
||||
class ComposerToolbarViewModelTests: XCTestCase {
|
||||
private var appSettings: AppSettings!
|
||||
private var wysiwygViewModel: WysiwygComposerViewModel!
|
||||
private var viewModel: ComposerToolbarViewModel!
|
||||
private var completionSuggestionServiceMock: CompletionSuggestionServiceMock!
|
||||
|
||||
override func setUp() {
|
||||
AppSettings.reset()
|
||||
@@ -30,7 +33,10 @@ class ComposerToolbarViewModelTests: XCTestCase {
|
||||
appSettings.richTextEditorEnabled = true
|
||||
ServiceLocator.shared.register(appSettings: appSettings)
|
||||
wysiwygViewModel = WysiwygComposerViewModel()
|
||||
viewModel = ComposerToolbarViewModel(wysiwygViewModel: wysiwygViewModel)
|
||||
completionSuggestionServiceMock = CompletionSuggestionServiceMock(configuration: .init())
|
||||
viewModel = ComposerToolbarViewModel(wysiwygViewModel: wysiwygViewModel,
|
||||
completionSuggestionService: completionSuggestionServiceMock,
|
||||
mediaProvider: MockMediaProvider())
|
||||
}
|
||||
|
||||
func testComposerFocus() {
|
||||
@@ -92,4 +98,23 @@ class ComposerToolbarViewModelTests: XCTestCase {
|
||||
viewModel.process(viewAction: .composerAction(action: .link))
|
||||
XCTAssertNotNil(viewModel.state.bindings.alertInfo)
|
||||
}
|
||||
|
||||
func testSuggestions() {
|
||||
let suggestions: [SuggestionItem] = [.user(item: MentionSuggestionItem(id: "@user_mention_1:matrix.org", displayName: "User 1", avatarURL: nil)),
|
||||
.user(item: MentionSuggestionItem(id: "@user_mention_2:matrix.org", displayName: "User 2", avatarURL: URL.documentsDirectory))]
|
||||
let mockCompletionSuggestionService = CompletionSuggestionServiceMock(configuration: .init(suggestions: suggestions))
|
||||
viewModel = ComposerToolbarViewModel(wysiwygViewModel: wysiwygViewModel,
|
||||
completionSuggestionService: mockCompletionSuggestionService,
|
||||
mediaProvider: MockMediaProvider())
|
||||
|
||||
XCTAssertEqual(viewModel.state.suggestions, suggestions)
|
||||
}
|
||||
|
||||
func testSuggestionTrigger() {
|
||||
wysiwygViewModel.setMarkdownContent("@test")
|
||||
wysiwygViewModel.setMarkdownContent("#not_implemented_yey")
|
||||
|
||||
// The first one is nil because when initialised the view model is empty
|
||||
XCTAssertEqual(completionSuggestionServiceMock.setSuggestionTriggerReceivedInvocations, [nil, .init(type: .user, text: "test"), nil])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user