namespace LivingVillage.Desktop.Tests open Microsoft.VisualStudio.TestTools.UnitTesting open LivingVillage.Desktop /// P76 回归:底部条/槽位药丸化(键位+图形并排)与面板文本换行不截断。 [] type P76HotbarPanelTests () = let slot = HudLayout.hotbarSlotRect 1280 720 0 [] 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(1, hair.Height) Assert.IsTrue(hair.X >= bar.X && hair.Right <= bar.Right, "发丝线须在条内") [] 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(HudLayout.actionLegendKeys, legend |> List.map (fun r -> r.Keys)) [] 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(text, System.String.Concat wrapped) Assert.AreEqual([ "" ], HudLayout.wrapText maxWidth scale "") Assert.AreEqual([ "短行" ], HudLayout.wrapText maxWidth scale "短行") [] member _.WrapLinesFlattensWithoutLosingText () = let source = [ "第一行"; "第二行很长很长很长很长很长很长很长很长很长很长很长很长"; "" ] let wrapped = HudLayout.wrapLines 160 2 source Assert.AreEqual(System.String.Concat source, System.String.Concat wrapped) for line in wrapped do Assert.IsTrue(FloatingPrompt.measureWidth line 2 <= 160)