summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests/P67TaskTargetUiTests.fs
blob: f6e7168fc4c7e1d264ede0ea4ab4a7ff476c4b56 (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
67
68
69
70
71
72
73
74
namespace LivingVillage.Desktop.Tests

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

/// P67(设计 §2.4-3 收口后的可见化):把 P66 定点的 TargetNpc/TargetTile
/// 展示到玩家可见的每日任务面板;无目标时文案逐字节不变;新字形(地/块/→)有覆盖断言。
[<TestClass>]
type P67TaskTargetUiTests () =

    let world =
        WorldBootstrap.initialWorldWithOccupation false 42UL 30 (Some(Occupation.stateOf Occupation.Farmer))

    let task template npc tile state : Occupation.DailyTask =
        { TemplateId = template
          TargetNpc = npc
          TargetTile = tile
          OfferedTick = 0L
          DueTick = 0L
          State = state }

    let farmerState = Occupation.stateOf Occupation.Farmer

    let taskPanelView (state: Occupation.State option) : M5View =
        { M5Interaction.initial with Panel = TaskPanel; Task = state; Status = "ready" }

    [<TestMethod>]
    member _.HelpWorkTargetShowsVillagerName () =
        let target = task Occupation.HelpWork (Some(Sim.NpcId 9)) None Occupation.Active
        Assert.AreEqual<string>("帮工:进行中 → 村民 9", TaskRuntime.taskLine target "进行中")

    [<TestMethod>]
    member _.TillSoilTargetShowsHomePlot () =
        let target = task Occupation.TillSoil None (Some(33, 25)) Occupation.Offered
        Assert.AreEqual<string>("翻土:待接受 → 自家地块", TaskRuntime.taskLine target "待接受")

    [<TestMethod>]
    member _.NoTargetKeepsLegacyCopy () =
        let helpWildcard = task Occupation.HelpWork None None Occupation.Active
        Assert.AreEqual<string>("帮工:进行中", TaskRuntime.taskLine helpWildcard "进行中")
        let nightWildcard = task Occupation.NightCatch None None Occupation.Offered
        Assert.AreEqual<string>("夜捕:待接受", TaskRuntime.taskLine nightWildcard "待接受")
        let tillWildcard = task Occupation.TillSoil None None Occupation.Done
        Assert.AreEqual<string>("翻土:已完成", TaskRuntime.taskLine tillWildcard "已完成")

    [<TestMethod>]
    member _.TaskPanelShowsTargetLineAndKeepsWildcardCopy () =
        let targeted =
            { farmerState with
                Today = Some(task Occupation.HelpWork (Some(Sim.NpcId 7)) None Occupation.Active) }
        let targetedLines = M5Interaction.panelLines world (taskPanelView (Some targeted))
        CollectionAssert.Contains(
            ResizeArray(targetedLines),
            "帮工:进行中 → 村民 7",
            sprintf "目标面板行缺失:%A" targetedLines)
        let wildcard =
            { farmerState with Today = Some(task Occupation.HelpWork None None Occupation.Active) }
        let wildcardLines = M5Interaction.panelLines world (taskPanelView (Some wildcard))
        CollectionAssert.Contains(ResizeArray(wildcardLines), "帮工:进行中")
        Assert.IsFalse(
            wildcardLines |> List.exists (fun line -> line.Contains '→'),
            sprintf "无目标面板不应出现目标箭头:%A" wildcardLines)

    [<TestMethod>]
    member _.TargetLinesAreFullyRenderableIncludingArrow () =
        let lines =
            [ TaskRuntime.taskLine (task Occupation.HelpWork (Some(Sim.NpcId 9)) None Occupation.Active) "进行中"
              TaskRuntime.taskLine (task Occupation.TillSoil None (Some(34, 25)) Occupation.Offered) "待接受"
              TaskRuntime.taskLine (task Occupation.HelpWork None None Occupation.Active) "进行中" ]
        for line in lines do
            Assert.IsTrue(PixelText.isRenderable line, sprintf "任务面板文案有缺字/不可渲染:%s" line)
        Assert.IsTrue(CjkGlyphAtlas.contains '→', "箭头字形 → 未入图集")