mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
ff5dcb040d
Removes the ServiceLocator singleton and instead directly injects the dependencies it was holding for more control over instantiation of the various component subtrees and better visibility over how they're being used.
52 lines
1.7 KiB
Swift
52 lines
1.7 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
// Copyright 2025 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
@testable import ElementX
|
|
import Testing
|
|
|
|
@MainActor
|
|
struct EmojiPickerScreenViewModelTests {
|
|
var timelineProxy: TimelineProxyMock!
|
|
|
|
var viewModel: EmojiPickerScreenViewModel!
|
|
var context: EmojiPickerScreenViewModel.Context {
|
|
viewModel.context
|
|
}
|
|
|
|
@Test
|
|
mutating func toggleReaction() async throws {
|
|
setupViewModel()
|
|
let reaction = "👋"
|
|
|
|
let deferred = deferFulfillment(viewModel.actions) { $0 == .dismiss }
|
|
|
|
await waitForConfirmation(timeout: .seconds(5)) { confirmation in
|
|
timelineProxy.toggleReactionToClosure = { toggledReaction, _ in
|
|
defer { confirmation() }
|
|
#expect(toggledReaction == reaction)
|
|
return .success(())
|
|
}
|
|
|
|
context.send(viewAction: .emojiTapped(emoji: .init(id: "wave", value: reaction)))
|
|
}
|
|
|
|
try await deferred.fulfill()
|
|
}
|
|
|
|
// MARK: - Helpers
|
|
|
|
private mutating func setupViewModel(selectedEmojis: Set<String> = []) {
|
|
timelineProxy = TimelineProxyMock(.init())
|
|
|
|
viewModel = EmojiPickerScreenViewModel(itemID: .randomEvent,
|
|
selectedEmojis: selectedEmojis,
|
|
emojiProvider: EmojiProvider(appSettings: AppSettings()),
|
|
timelineController: MockTimelineController(timelineProxy: timelineProxy))
|
|
}
|
|
}
|