//
//  WalletUITests.swift
//  suixinkanUITests
//

import XCTest

final class WalletUITests: AuthenticatedUITestCase {
    /// 测试钱包首页与提现表单校验。
    func testWalletWithdrawValidation() throws {
        try openWallet()

        UITestTapHelper.tapLabel("提现", in: app)
        NavigationAssertions.waitForNavigationTitle("提现申请", in: app)

        let submitButton = app.application.buttons["提交提现申请"]
        XCTAssertTrue(submitButton.waitForExistence(timeout: 6))
        submitButton.tap()
        XCTAssertTrue(
            app.application.staticTexts["请输入提现金额"].waitForExistence(timeout: 4)
                || app.application.staticTexts.matching(NSPredicate(format: "label CONTAINS '金额'")).firstMatch.exists
        )
    }

    /// 测试银行卡与积分兑换二级页可打开。
    func testWalletSecondaryPages() throws {
        try openWallet()

        UITestTapHelper.tapLabel("银行卡", in: app)
        NavigationAssertions.waitForNavigationTitle("银行卡设置", in: app)
        BackNavigator.goBack(app: app)

        UITestTapHelper.tapLabel("积分兑换", in: app)
        NavigationAssertions.waitForNavigationTitle("积分兑换", in: app)
    }

    /// 直达钱包首页。
    private func openWallet() throws {
        app = try UITestSession.relaunch(openMenu: "我的钱包")
        NavigationAssertions.waitForNavigationTitle("我的钱包", in: app)
    }
}
