//
//  AccessibilityTextSizeTests.swift
//  Tests iOS
//
//  TC-142: App remains functional at largest accessibility text size.
//

import XCTest

final class AccessibilityTextSizeTests: BaseUITestCase {
    override var seedFixture: String? { "single_mood" }
    override var bypassSubscription: Bool { true }

    override func setUp() {
        // Do NOT call super — we need custom content size launch args
        continueAfterFailure = false

        let application = XCUIApplication()
        var args: [String] = [
            "--ui-testing", "--disable-animations",
            "--reset-state",
            "--bypass-subscription",
            "--skip-onboarding",
            "-AppleLanguages", "(en)",
            "-AppleLocale", "en_US",
            "-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityXXL"
        ]
        application.launchArguments = args
        application.launchEnvironment = ["UI_TEST_FIXTURE": "single_mood"]
        application.launch()
        app = application
    }

    /// TC-142: App launches and is navigable at largest accessibility text size.
    func testLargestTextSize_AppRemainsNavigable() {
        // Verify Day tab is loaded and has content
        assertDayContentVisible()

        captureScreenshot(name: "accessibility_xxl_day")

        // Navigate through all tabs to verify nothing crashes
        let tabBar = TabBarScreen(app: app)

        tabBar.tapMonth()
        XCTAssertTrue(
            tabBar.monthTab.waitForExistence(timeout: 5),
            "Month tab should be accessible at XXL text size"
        )
        captureScreenshot(name: "accessibility_xxl_month")

        tabBar.tapYear()
        XCTAssertTrue(
            tabBar.yearTab.waitForExistence(timeout: 5),
            "Year tab should be accessible at XXL text size"
        )
        captureScreenshot(name: "accessibility_xxl_year")

        let settingsScreen = tabBar.tapSettings()
        settingsScreen.assertVisible()
        captureScreenshot(name: "accessibility_xxl_settings")
    }
}
