| 1 | import BaseKit |
| 2 | import Foundation |
| 3 | import RastrilloApple |
| 4 | import RastrilloSnapshots |
| 5 | import RastrilloTestSupport |
| 6 | import SwiftUI |
| 7 | import XCTest |
| 8 | |
| 9 | /// Sign-in (Task 12, mockups mac-signin, phone-signin): the email step, |
| 10 | /// the code step and P3's "sign in on the web once", walked to through the |
| 11 | /// kit's in-memory Oficina ID (no keychain, App Group or network). |
| 12 | final class SignInSnapshots: XCTestCase { |
| 13 | @MainActor func testSignIn() async throws { |
| 14 | try XCTSkipUnless(ProcessInfo.processInfo.environment["RASTRILLO_SNAPSHOTS"] != nil, "Run with native/scripts/snapshots.sh") |
| 15 | BaseFonts.register() |
| 16 | let email = model(), code = model(), unknown = model(admission: .nonMember) |
| 17 | await email.start() |
| 18 | await walk(code) |
| 19 | await walk(unknown, signIn: true) |
| 20 | await assertSnapshots(of: SnapshotCatalog(app: "base-signin", settings: SnapshotSettings(tint: LookSnapshots.tint), screens: [ |
| 21 | SnapshotScreen("email", mac: .fixed(width: 560, height: 640), iphone: .fixed(width: 402, height: 874)) { BaseSignIn(model: email).skyFrozen() }, |
| 22 | SnapshotScreen("code", mac: .fixed(width: 560, height: 640), iphone: .fixed(width: 402, height: 874)) { BaseSignIn(model: code).skyFrozen() }, |
| 23 | SnapshotScreen("unknown", mac: .fixed(width: 560, height: 640), iphone: .fixed(width: 402, height: 874)) { BaseSignIn(model: unknown).skyFrozen() }, |
| 24 | ])) |
| 25 | } |
| 26 | |
| 27 | @MainActor func model(admission: FakeOficinaIDService.Admission = .linked) -> OficinaIDModel { |
| 28 | let service = FakeOficinaIDService() |
| 29 | service.addPerson(email: "paul@fennel.example", identityID: "id-paul") |
| 30 | let team = OficinaTeam(sqid: "t1", label: "fennel", name: "Fennel & Rye", role: "member", |
| 31 | apps: [OficinaTeamApp(app: "base", origin: "https://fennel.base.oficina.works", consumerID: "t1-base")]) |
| 32 | service.setTeams([team], for: "id-paul") |
| 33 | service.admit("id-paul", at: team.origin(for: "base")!, as: admission) |
| 34 | let suite = "SignInSnapshots.\(UUID().uuidString)" |
| 35 | let defaults = UserDefaults(suiteName: suite)! |
| 36 | let store = OficinaIDStore(shared: OficinaMemoryStore(), appPrivate: OficinaMemoryStore(), group: defaults) |
| 37 | return OficinaIDModel(configuration: BaseSession.configuration, store: store, service: service, passkeys: FakePasskeys(), |
| 38 | makeKey: { OficinaSoftwareKey() }, now: { SnapshotSettings.now }, appDefaults: defaults) |
| 39 | } |
| 40 | |
| 41 | @MainActor func walk(_ model: OficinaIDModel, signIn: Bool = false) async { |
| 42 | await model.start() |
| 43 | model.continueWithEmail() |
| 44 | model.email = "paul@fennel.example" |
| 45 | await model.submitEmail() |
| 46 | guard signIn else { return } |
| 47 | model.code = FakeOficinaIDService.goodCode |
| 48 | await model.submitCode() |
| 49 | } |
| 50 | } |
| 51 | |