Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

1.2 KB
Raw Blame
import XCTest
@testable import NX2Apple
@testable import NXCore
@testable import NXLauncher

/// The Dock tile's text for a running build (DockProgress): the text is pure, the tile view is built without a Dock.
final class DockProgressTests: IsolatedDefaultsTestCase {
    func testThePercentTextForAProgressFraction() {
        XCTAssertEqual(DockProgress.percentText(0), "0%")
        XCTAssertEqual(DockProgress.percentText(0.404), "40%", "rounded, never 40.4%")
        XCTAssertEqual(DockProgress.percentText(1), "100%")
    }

    func testNilAndOddValuesClearTheTile() {
        XCTAssertNil(DockProgress.percentText(nil), "build not running: the plain icon comes back")
        XCTAssertNil(DockProgress.percentText(-0.2))
        XCTAssertNil(DockProgress.percentText(1.5))
        XCTAssertNil(DockProgress.percentText(.nan))
    }

    @MainActor
    func testTheTileHoldsTheIconAndAGrayBar() {
        let icon = NSImage(size: NSSize(width: 64, height: 64))
        let tile = DockProgress.makeTileView(fraction: 0.5, icon: icon, size: 128)
        XCTAssertEqual(tile.frame.size, NSSize(width: 128, height: 128))
        XCTAssertEqual(tile.subviews.count, 2, "the icon and the bar")
        XCTAssertNotNil((tile.subviews.last as? NSImageView)?.image)
    }
}