Files
element-x-ios/UnitTests/Sources/EmojiPickerScreenViewModelTests.swift
T
Michael ff5dcb040d Replace the ServiceLocator with direct dependency injection (#5548)
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.
2026-05-14 09:45:49 +03:00

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))
}
}