// // DataPersistenceTests.swift // Tests iOS // // Data persistence tests — verify entries survive app relaunch. // import XCTest final class DataPersistenceTests: BaseUITestCase { override var seedFixture: String? { "empty" } /// TC-156: Log a mood, force quit, relaunch → entry should persist. func testDataPersists_AcrossRelaunch() { let dayScreen = DayScreen(app: app) // Log a mood dayScreen.assertMoodHeaderVisible() dayScreen.logMood(.great) // Verify entry was created let greatEntry = app.descendants(matching: .any) .matching(NSPredicate(format: "label CONTAINS[cd] %@", "Great")) .firstMatch XCTAssertTrue( greatEntry.waitForExistence(timeout: 8), "Entry should appear after logging" ) captureScreenshot(name: "before_relaunch") // Terminate the app app.terminate() // Relaunch WITHOUT --reset-state to preserve data let freshApp = XCUIApplication() freshApp.launchArguments = ["--ui-testing", "--disable-animations", "--bypass-subscription", "--skip-onboarding"] freshApp.launch() // The entry should still exist after relaunch let entryRow = freshApp.descendants(matching: .any) .matching(NSPredicate(format: "identifier BEGINSWITH %@", "entry_row_")) .firstMatch XCTAssertTrue( entryRow.waitForExistence(timeout: 8), "Entry should persist after force quit and relaunch" ) captureScreenshot(name: "after_relaunch_data_persists") } }