summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Desktop.Tests')
-rw-r--r--src/LivingVillage.Desktop.Tests/DesktopTests.fs69
-rw-r--r--src/LivingVillage.Desktop.Tests/M6bTests.fs30
2 files changed, 99 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)
diff --git a/src/LivingVillage.Desktop.Tests/M6bTests.fs b/src/LivingVillage.Desktop.Tests/M6bTests.fs
index 6ae0634..5aea9bd 100644
--- a/src/LivingVillage.Desktop.Tests/M6bTests.fs
+++ b/src/LivingVillage.Desktop.Tests/M6bTests.fs
@@ -80,3 +80,33 @@ type M6bMenuTests () =
Assert.AreEqual<string option>(Some "missing save", failed.Error)
Assert.AreEqual<MenuPage>(MainMenu, returned.Page)
Assert.AreEqual<MenuCommand>(NoCommand, command)
+
+ // ---- P15 开局职业选择页 ----
+
+ [<TestMethod>]
+ member _.OccupationSelectOffersFourKindsThenNoneAndDefaultsToNone () =
+ let page = MenuState.openOccupationSelect (MenuState.create SimulationControl.initial false)
+
+ Assert.AreEqual<MenuPage>(OccupationSelect, page.Page)
+ Assert.AreEqual<Occupation.Kind option list>(
+ [ Some Occupation.Farmer; Some Occupation.Fisher; Some Occupation.Peddler; Some Occupation.Scholar; None ],
+ MenuState.occupationOptions)
+ Assert.AreEqual<Occupation.Kind option>(None, MenuState.selectedOccupation page)
+ Assert.AreEqual<string>("暂不选择", MenuState.occupationLabel None)
+ Assert.AreEqual<string>("农夫", MenuState.occupationLabel (Some Occupation.Farmer))
+ Assert.AreEqual<string>("书生", MenuState.occupationLabel (Some Occupation.Scholar))
+
+ [<TestMethod>]
+ member _.OccupationSelectConfirmEmitsChosenKindAndBackReturnsToMenu () =
+ let page = MenuState.openOccupationSelect (MenuState.create SimulationControl.initial false)
+ let _, defaultCommand = MenuState.update Confirm page
+ Assert.AreEqual<MenuCommand>(StartNewGameWith None, defaultCommand)
+
+ let picked = MenuState.move Up (MenuState.move Up page)
+ Assert.AreEqual<Occupation.Kind option>(Some Occupation.Peddler, MenuState.selectedOccupation picked)
+ let _, command = MenuState.update Confirm picked
+ Assert.AreEqual<MenuCommand>(StartNewGameWith (Some Occupation.Peddler), command)
+
+ let back, backCommand = MenuState.update Back page
+ Assert.AreEqual<MenuPage>(MainMenu, back.Page)
+ Assert.AreEqual<MenuCommand>(NoCommand, backCommand)