Files
element-x-ios/ElementX/Sources/Mocks/MediaProviderMock.swift
T
Doug 751be7b3a7 Update the SDK. (#3565)
* Update the SDK.

* Add mockMXC URLs to fix all the crashes during tests.

* Refactor Voice Messages to not use a MediaSource for local files.
2024-11-28 08:34:38 +00:00

59 lines
1.6 KiB
Swift

//
// Copyright 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only
// Please see LICENSE in the repository root for full details.
//
import SwiftUI
extension MediaProviderMock {
struct Configuration { }
convenience init(configuration: Configuration) {
self.init()
imageFromSourceSizeClosure = { mediaSource, _ in
guard mediaSource != nil else {
return nil
}
// At some stage it would be nice to return different images, but for now they can be the same.
if mediaSource?.url == .mockMXCImage || mediaSource?.url == .mockMXCAvatar {
return Asset.Images.appLogo.image
}
return UIImage(systemName: "photo")
}
loadImageFromSourceSizeClosure = { _, _ in
guard let image = UIImage(systemName: "photo") else {
fatalError()
}
return .success(image)
}
loadImageDataFromSourceClosure = { _ in
guard let image = UIImage(systemName: "photo"),
let data = image.pngData() else {
fatalError()
}
return .success(data)
}
loadFileFromSourceFilenameReturnValue = .failure(.failedRetrievingFile)
loadImageRetryingOnReconnectionSizeClosure = { _, _ in
Task {
guard let image = UIImage(systemName: "photo") else {
fatalError()
}
return image
}
}
}
}