SPB Git

spb/focale Public

Swift 100%
2.9 KB · 75 lines swift
Raw Blame History
1//2//  FavoriteFlowUITests.swift3//  FocaleUITests4//5//  Author: Simon-Pierre Boucher6//  Contact: contact@spboucher.ai7//8//  Regression test for the heart-button crash: the PHPhotoLibrary change9//  block must stay isolation-free (Swift 6) or tapping the favorite10//  button kills the app on PhotoKit's queue.11//1213import XCTest1415final class FavoriteFlowUITests: XCTestCase {1617    override func setUpWithError() throws {18        continueAfterFailure = false19    }2021    @MainActor22    func testHeartToggleTogglesAndDoesNotCrash() throws {23        let app = XCUIApplication()24        app.launch()2526        // The test runner reinstalls the app, which resets the photo27        // permission: walk through onboarding + the system dialog if shown.28        let allowButton = app.buttons["Autoriser l'accès à mes photos"]29        if allowButton.waitForExistence(timeout: 5) {30            allowButton.tap()31            let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")32            let fullAccess = springboard.buttons.matching(NSPredicate(33                format: "label CONTAINS[c] 'toutes' OR label CONTAINS[c] 'complet' OR label CONTAINS[c] 'Allow'"34            )).firstMatch35            if fullAccess.waitForExistence(timeout: 8) {36                fullAccess.tap()37            }38        }3940        let libraryTab = app.buttons["Bibliothèque"].firstMatch41        XCTAssertTrue(libraryTab.waitForExistence(timeout: 20), "Library tab should exist")42        libraryTab.tap()4344        let thumbnail = app.buttons.matching(identifier: "photo-thumbnail").firstMatch45        XCTAssertTrue(thumbnail.waitForExistence(timeout: 15), "At least one photo thumbnail")46        thumbnail.tap()4748        let addFavorite = app.buttons["Ajouter aux favoris"]49        let removeFavorite = app.buttons["Retirer des favoris"]50        XCTAssertTrue(51            addFavorite.waitForExistence(timeout: 10) || removeFavorite.exists,52            "Favorite button should be visible in the viewer toolbar"53        )5455        let startedAsFavorite = removeFavorite.exists56        (startedAsFavorite ? removeFavorite : addFavorite).tap()5758        // Optimistic UI: the label flips immediately, and the app survives59        // the PhotoKit write that crashed build 3.60        let flipped = startedAsFavorite ? addFavorite : removeFavorite61        XCTAssertTrue(flipped.waitForExistence(timeout: 5), "Heart state should flip after tap")6263        // Give the PhotoKit change block time to run (the old crash fired here).64        Thread.sleep(forTimeInterval: 2)65        XCTAssertEqual(app.state, .runningForeground, "App must survive the favorite write")6667        // Toggle back so the test leaves the library as it found it.68        flipped.tap()69        let restored = startedAsFavorite ? removeFavorite : addFavorite70        XCTAssertTrue(restored.waitForExistence(timeout: 5), "Heart state should flip back")71        Thread.sleep(forTimeInterval: 2)72        XCTAssertEqual(app.state, .runningForeground)73    }74}75