summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests/DesktopTests.fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Desktop.Tests/DesktopTests.fs')
-rw-r--r--src/LivingVillage.Desktop.Tests/DesktopTests.fs69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop.Tests/DesktopTests.fs b/src/LivingVillage.Desktop.Tests/DesktopTests.fs
index 52443e9..5f2d6df 100644
--- a/src/LivingVillage.Desktop.Tests/DesktopTests.fs
+++ b/src/LivingVillage.Desktop.Tests/DesktopTests.fs
@@ -208,3 +208,72 @@ type TaskPanelTests () =
Assert.AreEqual<M5View>(dialogueView, afterTask)
let _, closed = M5Interaction.apply ClosePanel world { dialogueView with Panel = TaskPanel }
Assert.AreEqual<M5Panel>(WorldPanel, closed.Panel)
+
+// ---- P15 开局职业选择接入:bootstrap 职业状态 / 存档 round-trip / 面板联调 ----
+
+module private OccupationFlowHarness =
+
+ let withTempSave (action: string -> unit) =
+ let id = System.Guid.NewGuid().ToString("N")
+ let path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"living-village-p15-{id}.save")
+ try
+ action path
+ finally
+ if System.IO.File.Exists path then System.IO.File.Delete path
+
+[<TestClass>]
+type OccupationFlowTests () =
+
+ [<TestMethod>]
+ member _.BootstrapStampsOccupationMoneyEnergyAndTodaysOfferedTask () =
+ for kind in Occupation.all do
+ let state = WorldBootstrap.occupationStateFor 42UL kind 0L
+ let task = state.Today.Value
+ Assert.AreEqual<Occupation.TaskState>(Occupation.Offered, task.State)
+ Assert.IsTrue(Occupation.taskPoolOf kind |> List.contains task.TemplateId)
+ Assert.AreEqual<Occupation.DailyTask>(
+ (Occupation.dailyTaskOf 42UL (Occupation.occupationSeedOf kind) 0L kind).Value,
+ task)
+ let world = WorldBootstrap.initialWorldWithOccupation true 42UL 4 (Some state)
+ Assert.AreEqual<float32>(float32 state.Profile.InitialMoney, world.Avatar.Mind.Needs.Money)
+ Assert.AreEqual<float32>(state.Profile.InitialEnergy, world.Avatar.Mind.Needs.Energy)
+
+ [<TestMethod>]
+ member _.ChosenOccupationAndTodaysTaskRoundTripThroughV3Save () =
+ for kind in Occupation.all do
+ let state = WorldBootstrap.occupationStateFor 42UL kind (3L * Sim.ticksPerDay + 120L)
+ let world = WorldBootstrap.initialWorldWithOccupation false 42UL 4 (Some state)
+ OccupationFlowHarness.withTempSave (fun path ->
+ WorldSave.saveToFileWith (Some state) path world
+ let text = System.IO.File.ReadAllText path
+ Assert.IsTrue(text.StartsWith("LV_WORLD_SAVE_V3"), "chosen occupation must save as v3")
+ match WorldSave.loadFromFileWith path with
+ | Ok (restoredWorld, Some restoredState) ->
+ Assert.AreEqual<Occupation.Kind>(kind, restoredState.Profile.Kind)
+ Assert.AreEqual<Occupation.State>(state, restoredState)
+ Assert.AreEqual<string>(text, WorldSave.saveWith (Some restoredState) restoredWorld)
+ | Ok (_, None) -> Assert.Fail($"v3 occupation lost for {kind}")
+ | Error message -> Assert.Fail($"v3 round trip failed for {kind}: {message}"))
+
+ [<TestMethod>]
+ member _.TaskPanelShowsTheChosenOccupationsOfferedTask () =
+ let world = Sim.initialWorldN 42UL 4
+ for kind in Occupation.all do
+ let state = WorldBootstrap.occupationStateFor 42UL kind 0L
+ let view = { M5Interaction.initial with Task = Some state }
+ let _, taskView = M5Interaction.apply ShowTaskPanel world view
+ let lines = M5Interaction.panelLines world taskView
+ Assert.IsTrue(lines |> List.contains (Occupation.nameOf kind), $"occupation name missing for {kind}")
+ Assert.IsTrue(
+ lines |> List.exists (fun line -> line.Contains(Occupation.taskNameOf state.Today.Value.TemplateId)),
+ $"task name missing for {kind}")
+ Assert.IsTrue(lines |> List.exists (fun line -> line.Contains("待接受")), $"offered state missing for {kind}")
+
+ [<TestMethod>]
+ member _.RefreshOccupationTodayKeepsSameDayAndRegeneratesForTheNewDay () =
+ let state = WorldBootstrap.occupationStateFor 42UL Occupation.Farmer 0L
+ Assert.AreEqual<Occupation.State>(state, WorldBootstrap.refreshOccupationToday 42UL state (Sim.ticksPerDay - 1L))
+ let day1 = WorldBootstrap.refreshOccupationToday 42UL state Sim.ticksPerDay
+ Assert.AreEqual<Occupation.DailyTask option>(
+ Some (Occupation.dailyTaskOf 42UL (Occupation.occupationSeedOf Occupation.Farmer) 1L Occupation.Farmer).Value,
+ day1.Today)