//
//  OrdersFlowUITests.swift
//  suixinkanUITests
//

import XCTest

final class OrdersFlowUITests: AuthenticatedUITestCase {
    /// 测试押金订单链路可进入列表与详情。
    func testDepositOrderFlow() throws {
        app = try UITestSession.relaunch(openMenu: "押金订单详情")
        NavigationAssertions.waitForNavigationTitle("押金订单", in: app)

        let firstCell = app.application.cells.element(boundBy: 0)
        if firstCell.waitForExistence(timeout: 8) {
            firstCell.tap()
            NavigationAssertions.waitForNavigationTitle("押金订单详情", in: app)
            BackNavigator.goBack(app: app)
        } else {
            throw XCTSkip("测试账号暂无押金订单，跳过详情流测试。")
        }
    }

    /// 测试全局扫码页可打开关闭，关闭后仍停留在打开前的 Tab。
    func testScannerCanOpenAndCloseWithoutChangingCurrentTab() {
        TabBarNavigator.select(.home, app: app)

        let scanButton = TabBarNavigator.scannerButton(in: app)
        XCTAssertTrue(scanButton.waitForExistence(timeout: 6))
        scanButton.tap()

        let closeButton = app.application.buttons["scanner.close"]
        XCTAssertTrue(closeButton.waitForExistence(timeout: 8))
        closeButton.tap()
        XCTAssertTrue(
            app.application.staticTexts["常用应用"].waitForExistence(timeout: 8)
                || app.application.staticTexts["请选择景区"].exists
        )
    }
}
