import BaseKit import Foundation import RastrilloApple import RastrilloSnapshots import RastrilloTestSupport import SwiftUI import XCTest /// Sign-in (Task 12, mockups mac-signin, phone-signin): the email step, /// the code step and P3's "sign in on the web once", walked to through the /// kit's in-memory Oficina ID (no keychain, App Group or network). final class SignInSnapshots: XCTestCase { @MainActor func testSignIn() async throws { try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh") BaseFonts.register() let email = model(), code = model(), unknown = model(admission: .nonMember) await email.start() await walk(code) await walk(unknown, signIn: true) await assertSnapshots(of: SnapshotCatalog(app: "base-signin", settings: SnapshotSettings(tint: LookSnapshots.tint), screens: [ SnapshotScreen("email", mac: .fixed(width: 560, height: 640), iphone: .fixed(width: 402, height: 874)) { BaseSignIn(model: email).skyFrozen() }, SnapshotScreen("code", mac: .fixed(width: 560, height: 640), iphone: .fixed(width: 402, height: 874)) { BaseSignIn(model: code).skyFrozen() }, SnapshotScreen("unknown", mac: .fixed(width: 560, height: 640), iphone: .fixed(width: 402, height: 874)) { BaseSignIn(model: unknown).skyFrozen() }, ])) } @MainActor func model(admission: FakeOficinaIDService.Admission = .linked) -> OficinaIDModel { let service = FakeOficinaIDService() service.addPerson(email: "paul@fennel.example", identityID: "id-paul") let team = OficinaTeam(sqid: "t1", label: "fennel", name: "Fennel & Rye", role: "member", apps: [OficinaTeamApp(app: "base", origin: "https://fennel.base.oficina.works", consumerID: "t1-base")]) service.setTeams([team], for: "id-paul") service.admit("id-paul", at: team.origin(for: "base")!, as: admission) let suite = "SignInSnapshots.\(UUID().uuidString)" let defaults = UserDefaults(suiteName: suite)! let store = OficinaIDStore(shared: OficinaMemoryStore(), appPrivate: OficinaMemoryStore(), group: defaults) return OficinaIDModel(configuration: BaseSession.configuration, store: store, service: service, passkeys: FakePasskeys(), makeKey: { OficinaSoftwareKey() }, now: { SnapshotSettings.now }, appDefaults: defaults) } @MainActor func walk(_ model: OficinaIDModel, signIn: Bool = false) async { await model.start() model.continueWithEmail() model.email = "paul@fennel.example" await model.submitEmail() guard signIn else { return } model.code = FakeOficinaIDService.goodCode await model.submitCode() } }