metatext/ViewModels/Sources/PreviewViewModels/PreviewViewModels.swift

109 lines
3.1 KiB
Swift
Raw Permalink Normal View History

2020-09-08 02:12:38 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import Combine
import DB
import Foundation
import Mastodon
2020-11-30 02:54:11 +00:00
import MastodonAPI
2020-09-08 02:12:38 +00:00
import MastodonAPIStubs
import MockKeychain
import Secrets
import ServiceLayer
import ServiceLayerMocks
import ViewModels
// swiftlint:disable force_try
2020-11-30 02:54:11 +00:00
let identityId = Identity.Id()
2020-09-08 02:12:38 +00:00
let db: IdentityDatabase = {
2020-11-09 03:07:23 +00:00
let db = try! IdentityDatabase(inMemory: true, appGroup: "", keychain: MockKeychain.self)
2020-11-30 02:54:11 +00:00
let secrets = Secrets(identityId: identityId, keychain: MockKeychain.self)
2020-09-08 02:12:38 +00:00
2020-09-11 09:55:06 +00:00
try! secrets.setInstanceURL(.previewInstanceURL)
2020-09-08 02:12:38 +00:00
try! secrets.setAccessToken(UUID().uuidString)
2020-11-30 02:54:11 +00:00
_ = db.createIdentity(id: identityId, url: .previewInstanceURL, authenticated: true, pending: false)
2020-09-08 02:12:38 +00:00
.receive(on: ImmediateScheduler.shared)
.sink { _ in } receiveValue: { _ in }
2020-11-30 02:54:11 +00:00
_ = db.updateInstance(.preview, id: identityId)
2020-09-08 02:12:38 +00:00
.receive(on: ImmediateScheduler.shared)
.sink { _ in } receiveValue: { _ in }
2020-11-30 02:54:11 +00:00
_ = db.updateAccount(.preview, id: identityId)
2020-09-08 02:12:38 +00:00
.receive(on: ImmediateScheduler.shared)
.sink { _ in } receiveValue: { _ in }
return db
}()
let environment = AppEnvironment.mock(fixtureDatabase: db)
2020-09-11 09:55:06 +00:00
let decoder = MastodonDecoder()
2020-11-30 02:54:11 +00:00
extension MastodonAPIClient {
static let preview = MastodonAPIClient(
session: URLSession(configuration: .stubbing),
instanceURL: .previewInstanceURL)
}
extension ContentDatabase {
static let preview = try! ContentDatabase(
id: identityId,
useHomeTimelineLastReadId: false,
inMemory: true,
appGroup: "group.metabolist.metatext",
keychain: MockKeychain.self)
}
2022-11-08 22:04:34 +00:00
public extension AppEnvironment {
static let preview = environment
}
2020-09-11 09:55:06 +00:00
public extension URL {
static let previewInstanceURL = URL(string: "https://mastodon.social")!
}
public extension Account {
static let preview = try! decoder.decode(Account.self, from: StubData.account)
}
public extension Instance {
static let preview = try! decoder.decode(Instance.self, from: StubData.instance)
}
2020-09-08 02:12:38 +00:00
public extension RootViewModel {
2021-03-05 02:13:30 +00:00
static let preview = try! RootViewModel(environment: environment,
registerForRemoteNotifications: { Empty().eraseToAnyPublisher() })
2020-09-08 02:12:38 +00:00
}
2021-01-26 00:06:35 +00:00
public extension IdentityContext {
static let preview = RootViewModel.preview.navigationViewModel!.identityContext
2020-09-08 02:12:38 +00:00
}
2020-11-30 02:54:11 +00:00
public extension ReportViewModel {
static let preview = ReportViewModel(
accountService: AccountService(
account: .preview,
environment: environment,
2020-11-30 02:54:11 +00:00
mastodonAPIClient: .preview,
contentDatabase: .preview),
2021-01-26 00:06:35 +00:00
identityContext: .preview)
2020-11-30 02:54:11 +00:00
}
2021-02-10 23:41:41 +00:00
public extension MuteViewModel {
static let preview = MuteViewModel(
accountService: AccountService(
account: .preview,
environment: environment,
2021-02-10 23:41:41 +00:00
mastodonAPIClient: .preview,
contentDatabase: .preview),
identityContext: .preview)
}
2020-12-04 03:13:18 +00:00
public extension DomainBlocksViewModel {
static let preview = DomainBlocksViewModel(service: .init(mastodonAPIClient: .preview))
}
2020-09-08 02:12:38 +00:00
// swiftlint:enable force_try