Files
letro-ios/UnitTests/Sources/CompletionSuggestionServiceTests.swift
Mauro eed60f3c62 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
2023-10-06 15:47:31 +02:00

54 lines
1.9 KiB
Swift

//
// Copyright 2023 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 Combine
import XCTest
@testable import ElementX
final class CompletionSuggestionServiceTests: XCTestCase {
private var cancellables = Set<AnyCancellable>()
override func setUp() {
cancellables.removeAll()
}
func testUserSuggestons() async throws {
let alice: RoomMemberProxyMock = .mockAlice
let members: [RoomMemberProxyMock] = [alice, .mockBob, .mockCharlie, .mockMe]
let roomProxyMock = RoomProxyMock(with: .init(displayName: "test", members: members))
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 == [.user(item: .init(id: alice.userID, displayName: alice.displayName, avatarURL: alice.avatarURL))]
}
service.setSuggestionTrigger(.init(type: .user, text: "ali"))
try await deferred.fulfill()
deferred = deferFulfillment(service.suggestionsPublisher) { suggestions in
suggestions == []
}
service.setSuggestionTrigger(.init(type: .user, text: "me"))
try await deferred.fulfill()
}
}