using Microsoft.UI.Xaml.Media;
using XFEWorkflow.Abstractions;
using XFEWorkflow.Core.Runtime;
using XFEWorkflow.Infrastructure.Storage;
using XFEWorkflow.Services;
namespace XFEWorkflow.Views;
public sealed partial class MainPage
{
internal async Task SmokeTypedWorkbenchAsync(string output)
{
await ready.Task; var previous = ViewModel.SelectedWorkflow; var size = App.MainWindow.AppWindow.Size;
var workflow = new WorkflowDefinition { Name = "端口类型与视角验收", Enabled = false, PluginVersions = new() { ["xfe.wecom"] = "3.0.0" }, Graph = new()
{ Nodes = [new() { Id = "receive", CapabilityId = "xfe.wecom.message.received", Name = "接收企微消息", X = 0, Y = 0, Trigger = new() { Kind = TriggerKind.Plugin, CapabilityId = "xfe.wecom.message.received" } },
new() { Id = "reply", CapabilityId = "xfe.wecom.quoteReply", Name = "引用回复", X = 440, Y = 0, Parameters = new() { ["content"] = "1" } },
new() { Id = "convert", CapabilityId = "core.convert.string", Name = "转换为文本", X = 440, Y = 410 }] } };
try
{
var scale = XamlRoot.RasterizationScale; App.MainWindow.AppWindow.Resize(new((int)(1600 * scale), (int)(1060 * scale)));
await ViewModel.NewAsync(workflow);
App.MainWindow.Activate(); UiSmokeTest.SetForegroundWindow(WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow)); await Task.Delay(150);
await CanvasEditor.SmokeTypedPortsAsync(output, async () =>
{
ShowProperties(CanvasEditor.Graph.Nodes.Single(x => x.Id == "reply"));
await Task.Delay(100);
var text = string.Join("\n", UiSmokeTest.Descendants<TextBlock>(PropertyPanel).Select(x => x.Text));
if (!text.Contains("输入连接点 · message") || !text.Contains("来自:接收企微消息 · message") || !text.Contains("content(文本)")
|| UiSmokeTest.Descendants<Button>(PropertyPanel).Any(x => x.Content as string == "断开连接")
|| UiSmokeTest.Descendants<Expander>(PropertyPanel).Any(x => x.Header as string == "连接点与当前连线")) throw new InvalidOperationException("参数下方未标明端口或仍存在独立连线栏:" + text);
var footer = UiSmokeTest.Descendants<StackPanel>(PropertyPanel).Single(x => Microsoft.UI.Xaml.Automation.AutomationProperties.GetAutomationId(x) == "PortConnection-input-content");
if (PropertyPanel.Children.IndexOf(footer) < 1 || PropertyPanel.Children[PropertyPanel.Children.IndexOf(footer) - 1] is not TextBox) throw new InvalidOperationException("连线信息未放在对应参数控件下方");
});
CanvasEditor.Zoom(1.13f); await Task.Delay(120);
var before = CanvasEditor.InspectViewport(); var graph = CanvasEditor.Graph;
var evidence = new List<object>();
for (var i = 0; i < 5; i++)
{
await ChangeWorkflowModeAsync(WorkflowKind.CSharp); await Task.Delay(60); await ChangeWorkflowModeAsync(WorkflowKind.Graph); await Task.Delay(160);
var after = CanvasEditor.InspectViewport();
if (!ReferenceEquals(graph, CanvasEditor.Graph) || Math.Abs(before["horizontalOffset"]!.GetValue<double>() - after["horizontalOffset"]!.GetValue<double>()) > 2
|| Math.Abs(before["verticalOffset"]!.GetValue<double>() - after["verticalOffset"]!.GetValue<double>()) > 2
|| Math.Abs(before["zoom"]!.GetValue<double>() - after["zoom"]!.GetValue<double>()) > .001)
throw new InvalidOperationException("图形与 C# 往返切换没有保留视角:" + after.ToJsonString());
evidence.Add(new { iteration = i, viewport = after });
}
if (CanvasEditor.Graph.Edges.Count != 1) throw new InvalidOperationException("切换模式修改了连线");
CanvasEditor.Undo(); await Task.Delay(120);
if (CanvasEditor.Graph.Edges.Count != 0) throw new InvalidOperationException("切换模式清空了画布的撤销记录");
await AtomicJson.WriteAsync(Path.Combine(output, "stable-mode-viewport.json"), new { before, evidence });
await UiSmokeTest.CaptureWindowAsync(Path.Combine(output, "typed-workflow-stable-viewport.png"));
}
finally { ViewModel.SelectedWorkflow = previous; App.MainWindow.AppWindow.Resize(size); }
}
}
using Microsoft.UI.Xaml.Media;
using XFEWorkflow.Abstractions;
using XFEWorkflow.Core.Runtime;
using XFEWorkflow.Infrastructure.Storage;
using XFEWorkflow.Services;
namespace XFEWorkflow.Views;
public sealed partial class MainPage
{
internal async Task SmokeTypedWorkbenchAsync(string output)
{
await ready.Task; var previous = ViewModel.SelectedWorkflow; var size = App.MainWindow.AppWindow.Size;
var workflow = new WorkflowDefinition { Name = "端口类型与视角验收", Enabled = false, PluginVersions = new() { ["xfe.wecom"] = "3.0.0" }, Graph = new()
{ Nodes = [new() { Id = "receive", CapabilityId = "xfe.wecom.message.received", Name = "接收企微消息", X = 0, Y = 0, Trigger = new() { Kind = TriggerKind.Plugin, CapabilityId = "xfe.wecom.message.received" } },
new() { Id = "reply", CapabilityId = "xfe.wecom.quoteReply", Name = "引用回复", X = 440, Y = 0, Parameters = new() { ["content"] = "1" } },
new() { Id = "convert", CapabilityId = "core.convert.string", Name = "转换为文本", X = 440, Y = 410 }] } };
try
{
var scale = XamlRoot.RasterizationScale; App.MainWindow.AppWindow.Resize(new((int)(1600 * scale), (int)(1060 * scale)));
await ViewModel.NewAsync(workflow);
App.MainWindow.Activate(); UiSmokeTest.SetForegroundWindow(WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow)); await Task.Delay(150);
await CanvasEditor.SmokeTypedPortsAsync(output, async () =>
{
ShowProperties(CanvasEditor.Graph.Nodes.Single(x => x.Id == "reply"));
await Task.Delay(100);
var text = string.Join("\n", UiSmokeTest.Descendants<TextBlock>(PropertyPanel).Select(x => x.Text));
if (!text.Contains("输入连接点 · message") || !text.Contains("来自:接收企微消息 · message") || !text.Contains("content(文本)")
|| UiSmokeTest.Descendants<Button>(PropertyPanel).Any(x => x.Content as string == "断开连接")
|| UiSmokeTest.Descendants<Expander>(PropertyPanel).Any(x => x.Header as string == "连接点与当前连线")) throw new InvalidOperationException("参数下方未标明端口或仍存在独立连线栏:" + text);
var footer = UiSmokeTest.Descendants<StackPanel>(PropertyPanel).Single(x => Microsoft.UI.Xaml.Automation.AutomationProperties.GetAutomationId(x) == "PortConnection-input-content");
if (PropertyPanel.Children.IndexOf(footer) < 1 || PropertyPanel.Children[PropertyPanel.Children.IndexOf(footer) - 1] is not TextBox) throw new InvalidOperationException("连线信息未放在对应参数控件下方");
});
CanvasEditor.Zoom(1.13f); await Task.Delay(120);
var before = CanvasEditor.InspectViewport(); var graph = CanvasEditor.Graph;
var evidence = new List<object>();
for (var i = 0; i < 5; i++)
{
await ChangeWorkflowModeAsync(WorkflowKind.CSharp); await Task.Delay(60); await ChangeWorkflowModeAsync(WorkflowKind.Graph); await Task.Delay(160);
var after = CanvasEditor.InspectViewport();
if (!ReferenceEquals(graph, CanvasEditor.Graph) || Math.Abs(before["horizontalOffset"]!.GetValue<double>() - after["horizontalOffset"]!.GetValue<double>()) > 2
|| Math.Abs(before["verticalOffset"]!.GetValue<double>() - after["verticalOffset"]!.GetValue<double>()) > 2
|| Math.Abs(before["zoom"]!.GetValue<double>() - after["zoom"]!.GetValue<double>()) > .001)
throw new InvalidOperationException("图形与 C# 往返切换没有保留视角:" + after.ToJsonString());
evidence.Add(new { iteration = i, viewport = after });
}
if (CanvasEditor.Graph.Edges.Count != 1) throw new InvalidOperationException("切换模式修改了连线");
CanvasEditor.Undo(); await Task.Delay(120);
if (CanvasEditor.Graph.Edges.Count != 0) throw new InvalidOperationException("切换模式清空了画布的撤销记录");
await AtomicJson.WriteAsync(Path.Combine(output, "stable-mode-viewport.json"), new { before, evidence });
await UiSmokeTest.CaptureWindowAsync(Path.Combine(output, "typed-workflow-stable-viewport.png"));
}
finally { ViewModel.SelectedWorkflow = previous; App.MainWindow.AppWindow.Resize(size); }
}
}