Files
pacs_win_uia/tests/regression/FloatingConditionsTests.cs
T
zimoyin f31b50bb36 完善 XPath 定位与控件监控体验
- 增加简明到深入的 XPath 定位教程
- 保留增量控件树刷新与可编辑 Path
- 完善悬浮条条件选择和诊断

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-13 13:00:10 +08:00

49 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using pacs_win_uia.Models;
using pacs_win_uia.Services;
namespace PacsWinUia.RegressionTests
{
internal static class FloatingConditionsTests
{
public static void Register(IList<KeyValuePair<string, Action>> tests)
{
tests.Add(new KeyValuePair<string, Action>("Floating conditions require all supplied clues and unique window", WindowConditions));
tests.Add(new KeyValuePair<string, Action>("Floating display explains missing configuration before provider calls", InvalidConfiguration));
}
private static void WindowConditions()
{
var first = new NativeWindowInfo(new IntPtr(1)) { ProcessName = "fixture", ClassName = "Host", Title = "测试窗口 A", IsVisible = true };
var second = new NativeWindowInfo(new IntPtr(2)) { ProcessName = "fixture", ClassName = "Host", Title = "测试窗口 B", IsVisible = true };
var windows = new List<NativeWindowInfo> { first, second };
string error;
Check.Same(first, FloatingBarManager.FindConditionWindow(windows, "Fixture.exe", "Host", "窗口 A", out error), "Friendly .exe process input not normalized");
Check.Equal<string>(null, error, "Exact match error");
Check.Equal<NativeWindowInfo>(null, FloatingBarManager.FindConditionWindow(windows, "fixture", "Host", "不存在", out error), "Wrong title fell back to process");
Check.True(!string.IsNullOrEmpty(error), "Missing title diagnostic");
Check.Equal<NativeWindowInfo>(null, FloatingBarManager.FindConditionWindow(windows, "fixture", null, null, out error), "Ambiguous windows silently chose first");
Check.True(!string.IsNullOrEmpty(error), "Ambiguity diagnostic");
Check.Equal<NativeWindowInfo>(null, FloatingBarManager.FindConditionWindow(windows, null, null, null, out error), "Empty clues matched a window");
Check.Equal<NativeWindowInfo>(null, FloatingBarManager.FindConditionWindow(windows, null, "Host", "wrong", out error), "Class OR title bug returned");
}
private static void InvalidConfiguration()
{
var bar = new FloatingBarDefinition { Enabled = false };
var result = FloatingBarManager.CheckDisplayConditions(bar);
Check.True(!result.CanShow && !string.IsNullOrWhiteSpace(result.Reason), "Disabled bar lacks reason");
bar.Enabled = true;
result = FloatingBarManager.CheckDisplayConditions(bar);
Check.True(!result.CanShow && !string.IsNullOrWhiteSpace(result.Reason), "Empty buttons lack reason");
bar.Buttons.Add(new FloatingButtonDefinition { Enabled = true, Label = "测试", Action = FloatingActionKind.PickControl });
result = FloatingBarManager.CheckDisplayConditions(bar);
Check.True(!result.CanShow && !string.IsNullOrWhiteSpace(result.Reason), "No anchor lacks reason");
bar.ImportedCondition = new ControlMonitorDefinition { ControlPath = TreeFixture.MenuLegacy, ProcessName = "fixture" };
result = FloatingBarManager.CheckDisplayConditions(bar);
Check.True(!result.CanShow && result.Reason.IndexOf("path", StringComparison.OrdinalIgnoreCase) >= 0, "Old imported path lacks diagnostic");
}
}
}