SPB Git

Repository Public

StepRenderingTests.swift 9.3 KB 181 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : MacLustr Identity9// File             : sdk/swift/Tests/MacLustrIdentityUITests/StepRenderingTests.swift10// Module           : MacLustrIdentityUITests11// Repository       : https://git.spboucher.ai/maclustr-identity12// Project Website  : https://identity.spboucher.ai13// Created          : 2026-12-0114// Last Modified    : 2026-12-0115//16// =============================================================================17// AUTHOR & PROFESSIONAL AFFILIATION18// =============================================================================19//20// Author           : Simon-Pierre Boucher21// Position         : Professor of Finance22// Institution      : Université du Québec en Outaouais (UQO)23// Department       : Département des sciences administratives24// Organization     : SP Boucher25//26// Website          : https://spboucher.ai27// Git              : https://git.spboucher.ai28//29// =============================================================================30// OFFICIAL CONTACT DIRECTORY31// =============================================================================32//33// General          : info@spboucher.ai34// Professional     : contact@spboucher.ai35// Direct           : simon@spboucher.ai36// Research         : research@spboucher.ai37// Development      : dev@spboucher.ai38// Support          : support@spboucher.ai39// Security/Admin   : admin@spboucher.ai40// Notifications    : notifications@spboucher.ai41//42// Preferred Contact: admin@spboucher.ai43//44// =============================================================================45// COPYRIGHT & INTELLECTUAL PROPERTY46// =============================================================================47//48// Copyright (c) 202649// Simon-Pierre Boucher50//51// All rights reserved where applicable.52//53// This file is governed by the applicable project license,54// copyright notices, institutional agreements and relevant law.55//56// Unless expressly authorized by the applicable license or57// rights holder, copying, redistribution, sublicensing,58// publication and commercial exploitation are not permitted.59//60// Existing third-party rights and notices remain unaffected.61//62// =============================================================================63// CONFIDENTIALITY & SECURITY64// =============================================================================65//66// Classification   : Public67// Distribution     : Public repository; use is governed by the project license68// Security Contact : admin@spboucher.ai69//70// Access to this source does not independently grant permission71// to redistribute or disclose confidential materials.72//73// Do not embed credentials, private keys, access tokens,74// certificates or confidential personal information.75//76// =============================================================================77// LICENSE & MAINTENANCE78// =============================================================================79//80// License          : None specified (no license file in this repository)81// Maintainer       : Simon-Pierre Boucher82// Technical Contact: dev@spboucher.ai83//84// =============================================================================85// END OF SP BOUCHER SOURCE HEADER86// =============================================================================8788import SwiftUI89import XCTest90@testable import MacLustrIdentityUI9192/// Renders the camera-free screens off screen from real captured flow states, in both languages and at a large93/// text size. Set MLID_RENDER_DIR to keep the PNG files for a visual review.94@MainActor95final class StepRenderingTests: XCTestCase {96    private struct Stub: IdentityTransport {97        let body: Data98        func send(_ request: URLRequest) async throws -> (Data, HTTPURLResponse) {99            (body, HTTPURLResponse(url: request.url!, statusCode: 200, httpVersion: nil, headerFields: nil)!)100        }101    }102103    private func coreFixture(_ name: String, file: StaticString = #filePath) throws -> Data {104        var url = URL(fileURLWithPath: "\(file)")105        url.deleteLastPathComponent(); url.deleteLastPathComponent()106        url.appendPathComponent("MacLustrIdentityCoreTests/Fixtures/\(name).json")107        return try Data(contentsOf: url)108    }109110    private func flow(_ fixture: String, language: IdentityLanguage) async throws -> VerificationFlowModel {111        let session = try IdentitySession(sessionID: "vs_render", clientSecret: "vsc_render")112        let m = VerificationFlowModel(client: IdentityClient(session: session, transport: Stub(body: try coreFixture(fixture))), language: language, sleeper: { _ in try await Task.sleep(nanoseconds: 60_000_000_000) })113        await m.start()114        return m115    }116117    private func render<V: View>(_ name: String, _ view: V, language: IdentityLanguage, size: DynamicTypeSize = .large, dark: Bool = false) throws {118        let content = view119            .environment(\.identityLanguage, language)120            .environment(\.identityFlatLayout, true)121            .environment(\.dynamicTypeSize, size)122            .environment(\.colorScheme, dark ? .dark : .light)123            .tint(.blue)124            .frame(width: 390, height: size == .large ? 780 : 1900)125            .background(dark ? Color.black : Color.white)126        let renderer = ImageRenderer(content: content)127        renderer.scale = 2128        let image = try XCTUnwrap(renderer.cgImage, name)129        XCTAssertEqual(image.width, 780, name)130        if let dir = ProcessInfo.processInfo.environment["MLID_RENDER_DIR"] {131            let url = URL(fileURLWithPath: dir).appendingPathComponent("\(name)-\(language.rawValue)\(dark ? "-dark" : "")\(size == .large ? "" : "-xl").png")132            let dest = CGImageDestinationCreateWithURL(url as CFURL, "public.png" as CFString, 1, nil)!133            CGImageDestinationAddImage(dest, image, nil)134            CGImageDestinationFinalize(dest)135        }136    }137138    func testCameraFreeScreensRender() async throws {139        for lang in IdentityLanguage.allCases {140            let created = try await flow("flow_created", language: lang)141            XCTAssertEqual(created.step, .intro)142            try render("intro", IntroStepView(flow: created), language: lang)143            try render("intro", IntroStepView(flow: created), language: lang, size: .accessibility3)144            try render("method", MethodStepView(flow: created), language: lang, dark: lang == .fr)145            try render("consent", ConsentStepView(flow: created, methodID: "document_selfie"), language: lang)146            try render("consent", ConsentStepView(flow: created, methodID: "document_review"), language: lang, size: .accessibility3)147            let sandbox = try await flow("flow_awaiting_document", language: lang)148            XCTAssertEqual(sandbox.step, .sandbox)149            try render("sandbox", SandboxStepView(flow: sandbox), language: lang)150            for (fixture, status) in [("flow_sandbox_verified", SessionStatus.verified), ("flow_sandbox_rejected", .rejected), ("flow_sandbox_manual_review", .manualReview),151                                      ("flow_sandbox_inconclusive", .inconclusive), ("flow_cancelled", .cancelled)] {152                let m = try await flow(fixture, language: lang)153                XCTAssertEqual(m.step, .result(status))154                try render("result-\(status.rawValue)", ResultStepView(flow: m, status: status, onClose: {}), language: lang, dark: status == .rejected)155            }156            let processing = try await flow("flow_live_processing", language: lang)157            XCTAssertEqual(processing.step, .processing)158            try render("processing", ProgressStepView(flow: processing, submitting: false, onClose: {}), language: lang)159            processing.stop()160            // Changing method from a capture: the notice about destroyed photos and the way back.161            let capturing = try await flow("flow_live_awaiting_selfie", language: lang)162            XCTAssertEqual(capturing.step, .selfie)163            XCTAssertTrue(capturing.canChangeMethod)164            capturing.changeMethod()165            XCTAssertEqual(capturing.step, .method)166            try render("method-change", MethodStepView(flow: capturing), language: lang)167            // Manual review of a live session: the withdrawal button is offered (and only opens a confirmation).168            let review = try await flow("flow_sandbox_manual_review", language: lang)169            XCTAssertTrue(review.canWithdraw)170            try render("result-review-withdraw", ResultStepView(flow: review, status: .manualReview, onClose: {}), language: lang, size: .accessibility3)171            try render("failed", FailedStepView(flow: created, error: .network("x"), onClose: {}), language: lang)172            try render("dispute", DisputeSheet(flow: created, isPresented: .constant(true)), language: lang)173        }174    }175176    func testOverlaysRender() throws {177        try render("overlay-document", ZStack { Color.gray; DocumentFrameOverlay(active: true) }, language: .en)178        try render("overlay-face", ZStack { Color.gray; FaceOvalOverlay(active: false) }, language: .en)179    }180}181
Files main
Menu

Theme