using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Automation.Peers; using Microsoft.UI.Xaml.Automation.Provider; using System.IO.Compression; using System.Text.Json; using XFEWorkflow.Abstractions; using XFEWorkflow.Core.Runtime; using XFEWorkflow.ViewModels; using XFEWorkflow.Views; namespace XFEWorkflow.Services; internal static partial class UiSmokeTest { private static async Task SmokeWeComPanelAsync(string output) { var services = AppServices.Current; var navigation = AppShellPage.Current!.ViewModel.NavigationViewService; var bundled = Directory.GetFiles(Path.Combine(AppContext.BaseDirectory, "BundledPlugins", "xfe.wecom"), "plugin.json", SearchOption.AllDirectories); if (bundled.Length != 1 || JsonSerializer.Deserialize(await File.ReadAllTextAsync(bundled[0]), WorkflowJson.Options)?.Version != "3.0.0") throw new InvalidOperationException("软件必须只打包完整的企业微信插件"); if (!services.Plugins.Installed.Any(x => x.Manifest.Id == "xfe.wecom" && x.Manifest.Version == "1.0.0")) { // Reproduce an existing user's legacy installation with the real old assembly. var standardFile = Path.Combine(services.Plugins.Installed.First(x => x.Manifest.Id == "xfe.http").Directory, "XFEWorkflow.Plugins.Standard.dll"); var standard = System.Reflection.Assembly.LoadFrom(standardFile); using var resource = standard.GetManifestResourceStream("XFEWorkflow.Plugins.Standard.Manifests.xfe.wecom.json")!; var legacy = JsonSerializer.Deserialize(resource, WorkflowJson.Options)!; var package = Path.Combine(services.Paths.Temp, "legacy-wecom-ui-fixture.xfeplugin"); try { using (var archive = ZipFile.Open(package, ZipArchiveMode.Create)) { using (var writer = new StreamWriter(archive.CreateEntry("plugin.json").Open())) writer.Write(JsonSerializer.Serialize(legacy, WorkflowJson.Options)); archive.CreateEntryFromFile(standardFile, legacy.Assembly); } await services.Plugins.InstallAsync(package); } finally { if (File.Exists(package)) File.Delete(package); } } var size = App.MainWindow.AppWindow.Size; var scale = App.MainWindow.Content.XamlRoot.RasterizationScale; App.MainWindow.AppWindow.Resize(new((int)(1920 * scale), (int)(1040 * scale))); navigation.NavigateTo(); await WaitManagementAsync(() => Descendants(App.MainWindow.Content).Any(x => x.Items.OfType().Any(y => y.Manifest.Id == "xfe.wecom" && y.Manifest.Version == "3.0.0"))); var catalog = Descendants(App.MainWindow.Content).Single(); catalog.SelectedItem = catalog.Items.OfType().Single(x => x.Manifest.Id == "xfe.wecom" && x.Manifest.Version == "3.0.0"); await WaitManagementAsync(() => Descendants