//
//  GlobalLoadingManagerTests.swift
//  suixinkanTests
//

import XCTest
@testable import suixinkan

@MainActor
/// 全局 Loading 管理器测试。
final class GlobalLoadingManagerTests: XCTestCase {

    override func tearDown() {
        GlobalLoadingManager.shared.hideAll()
        super.tearDown()
    }

    func testShowAndHideToggleVisibilityState() {
        let manager = GlobalLoadingManager.shared
        XCTAssertFalse(manager.isShowing)

        manager.show()
        XCTAssertTrue(manager.isShowing)

        manager.hide()
        XCTAssertFalse(manager.isShowing)
    }

    func testNestedShowRequiresMatchingHideCount() {
        let manager = GlobalLoadingManager.shared

        manager.show()
        manager.show()
        XCTAssertTrue(manager.isShowing)

        manager.hide()
        XCTAssertTrue(manager.isShowing)

        manager.hide()
        XCTAssertFalse(manager.isShowing)
    }

    func testHideAllResetsNestedCount() {
        let manager = GlobalLoadingManager.shared

        manager.show()
        manager.show()
        manager.hideAll()
        XCTAssertFalse(manager.isShowing)

        manager.hide()
        XCTAssertFalse(manager.isShowing)
    }
}
