summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests/P76HotbarPanelTests.fs
blob: 5a1dd55f32e2ae2dea99acfbdb943b8a5bf352f6 (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
namespace LivingVillage.Desktop.Tests

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

/// P76 回归:底部条/槽位药丸化(键位+图形并排)与面板文本换行不截断。
[<TestClass>]
type P76HotbarPanelTests () =

    let slot = HudLayout.hotbarSlotRect 1280 720 0

    [<TestMethod>]
    member _.KeyChipSitsBesideIconInsideTheSlot () =
        let chip = HudLayout.hotbarKeyChipRect slot
        let icon = HudLayout.hotbarIconRectBesideKey slot
        Assert.IsTrue(chip.X >= slot.X && chip.Right <= slot.Right, "键位小片须在槽内")
        Assert.IsTrue(icon.X >= chip.Right, "图形须在键位小片右侧(并排)")
        Assert.IsTrue(icon.Right <= slot.Right, "图形须在槽内")
        Assert.IsTrue(chip.Y >= slot.Y && chip.Bottom <= slot.Bottom, "键位小片须垂直居中在槽内")
        let bar = HudLayout.hotbarBarRect 1280 720
        let hair = HudLayout.hotbarBarHairline bar
        Assert.AreEqual<int>(1, hair.Height)
        Assert.IsTrue(hair.X >= bar.X && hair.Right <= bar.Right, "发丝线须在条内")

    [<TestMethod>]
    member _.ActionLegendUsesOnlyRealControlRows () =
        let legend = HudLayout.actionLegend MenuState.controlRows
        Assert.IsTrue(legend.Length > 0, "图例不得为空")
        for row in legend do
            Assert.IsTrue(
                MenuState.controlRows |> List.exists (fun r -> r.Keys = row.Keys && r.Action = row.Action),
                sprintf "图例项 %s/%s 必须是真实 controlRows,不得杜撰" row.Keys row.Action)
            Assert.IsFalse(System.String.IsNullOrWhiteSpace row.Keys)
            Assert.IsFalse(System.String.IsNullOrWhiteSpace row.Action)
        // 键序与预设一致(纯展示,不改绑定)。
        Assert.AreEqual<string list>(HudLayout.actionLegendKeys, legend |> List.map (fun r -> r.Keys))

    [<TestMethod>]
    member _.PanelWrapNeverExceedsWidthNorDropsCharacters () =
        let maxWidth = 240
        let scale = 2
        let text = "今日天气晴好适合下田耕作记得给菜畦浇水并去市集看看货郎的货品是否齐全"
        let wrapped = HudLayout.wrapText maxWidth scale text
        Assert.IsTrue(wrapped.Length > 1, "长行须折成多行")
        for line in wrapped do
            Assert.IsTrue(FloatingPrompt.measureWidth line scale <= maxWidth, sprintf "折行超宽: %s" line)
        Assert.AreEqual<string>(text, System.String.Concat wrapped)
        Assert.AreEqual<string list>([ "" ], HudLayout.wrapText maxWidth scale "")
        Assert.AreEqual<string list>([ "短行" ], HudLayout.wrapText maxWidth scale "短行")

    [<TestMethod>]
    member _.WrapLinesFlattensWithoutLosingText () =
        let source = [ "第一行"; "第二行很长很长很长很长很长很长很长很长很长很长很长很长"; "" ]
        let wrapped = HudLayout.wrapLines 160 2 source
        Assert.AreEqual<string>(System.String.Concat source, System.String.Concat wrapped)
        for line in wrapped do
            Assert.IsTrue(FloatingPrompt.measureWidth line 2 <= 160)