summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests/P16UiTests.fs
blob: 0bfdb62997152e92069b4669dfad8f7e90f8fe47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
namespace LivingVillage.Desktop.Tests

open Microsoft.VisualStudio.TestTools.UnitTesting
open LivingVillage.Kernel
open LivingVillage.Desktop

// ---- P16 启动画面 / 开始界面 ----

[<TestClass>]
type P16LaunchTests () =

    [<TestMethod>]
    member _.LaunchRevealAndVeilAreDeterministicAndComplete () =
        Assert.AreEqual<float32>(0.0f, LaunchScreen.revealProgress 0L)
        Assert.AreEqual<float32>(1.0f, LaunchScreen.revealProgress LaunchScreen.fadeInFrames)
        Assert.AreEqual<float32>(1.0f, LaunchScreen.revealProgress 1000L)
        Assert.AreEqual<float32>(1.0f, LaunchScreen.veilAlpha 0L)
        Assert.AreEqual<float32>(0.0f, LaunchScreen.veilAlpha LaunchScreen.durationFrames)
        Assert.IsTrue(LaunchScreen.veilAlpha 30L > LaunchScreen.veilAlpha 90L, "veil must decrease monotonically")
        Assert.IsFalse(LaunchScreen.isComplete (LaunchScreen.durationFrames - 1L))
        Assert.IsTrue(LaunchScreen.isComplete LaunchScreen.durationFrames)

    [<TestMethod>]
    member _.LaunchSkipIsEscOrSpaceAndTextUsesTheAtlasPath () =
        Assert.IsTrue(LaunchScreen.skipRequested true false)
        Assert.IsTrue(LaunchScreen.skipRequested false true)
        Assert.IsFalse(LaunchScreen.skipRequested false false)
        Assert.IsTrue(PixelText.isRenderable LaunchScreen.title)
        Assert.IsTrue(PixelText.isRenderable LaunchScreen.skipHint)
        Assert.IsTrue(PixelText.isRenderable LaunchScreen.subtitle)
        Assert.IsTrue(ChineseText.requiredUiLabels |> List.contains LaunchScreen.skipHint)

[<TestClass>]
type P16StartMenuTests () =

    [<TestMethod>]
    member _.StartMenuIsExactlyThreeItemsWithChineseLabels () =
        let state = MenuState.create SimulationControl.initial false

        Assert.AreEqual<int>(3, MenuState.items state |> List.length)
        Assert.AreEqual<string list>([ "开始"; "读档"; "退出" ], MenuState.items state |> List.map MenuState.itemLabel)

    [<TestMethod>]
    member _.StartMenuNavigationSelectsEachItemAndWraps () =
        let state = MenuState.create SimulationControl.initial false
        let down1 = MenuState.move Down state
        let down2 = MenuState.move Down down1
        let wrap = MenuState.move Down down2

        Assert.AreEqual<MenuItem>(NewGameItem, MenuState.selectedItem state)
        Assert.AreEqual<MenuItem>(LoadItem, MenuState.selectedItem down1)
        Assert.AreEqual<MenuItem>(ExitItem, MenuState.selectedItem down2)
        Assert.AreEqual<MenuItem>(NewGameItem, MenuState.selectedItem wrap)

        Assert.AreEqual<MenuCommand>(StartNewGame, MenuState.update Confirm state |> snd)
        Assert.AreEqual<MenuCommand>(LoadGame, MenuState.update Confirm down1 |> snd)
        Assert.AreEqual<MenuCommand>(ExitGame, MenuState.update Confirm down2 |> snd)

    [<TestMethod>]
    member _.ReturningToMenuOffersContinueAsTheFirstOfThreeItems () =
        let playing = MenuState.create SimulationControl.initial true |> MenuState.enterGame
        let main = MenuState.openMain playing

        Assert.AreEqual<MenuItem list>([ ContinueItem; LoadItem; ExitItem ], MenuState.items main)
        Assert.AreEqual<string list>([ "继续"; "读档"; "退出" ], MenuState.items main |> List.map MenuState.itemLabel)
        Assert.AreEqual<MenuCommand>(ContinueGame, MenuState.update Confirm main |> snd)