From b17a4af4ee6fdb51ce91772aacc984c15921a3ef Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Sun, 29 Oct 2023 18:50:33 +0000 Subject: [PATCH] test remove multiple - added test to assert correct removal of multiple root items - publish package clears on window close without prompt - added ellipsis for package name - center message prompts to main view --- .../PackageManager/PublishPackageViewModel.cs | 38 +++++++++---------- .../Controls/CustomBrowserControl.xaml | 4 +- .../PackageManagerPublishControl.xaml.cs | 1 + .../PackageManager/PackageManagerView.xaml.cs | 1 + .../PublishPackageViewModelTests.cs | 37 ++++++++++++++---- 5 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs index ae8bf459cd5..f956f10160c 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs @@ -77,7 +77,7 @@ public HostComboboxEntry(string hostName) } } - public PublishPackageView Owner { get; set; } + public Window Owner { get; set; } /// /// A event called when publishing was a success @@ -1488,7 +1488,7 @@ private void SelectDirectoryAndAddFilesRecursively() { ErrorString = String.Format(Resources.FolderNotWritableError, directoryPath); var ErrorMessage = ErrorString + "\n" + Resources.SolutionToFolderNotWritatbleError; - Dynamo.Wpf.Utilities.MessageBoxService.Show(ErrorMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Warning); + Dynamo.Wpf.Utilities.MessageBoxService.Show(Owner, ErrorMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Warning); return; } @@ -1555,7 +1555,7 @@ private void SelectMarkdownDirectory() ErrorString = String.Format(Resources.FolderNotWritableError, directoryPath); string errorMessage = ErrorString + Environment.NewLine + Resources.SolutionToFolderNotWritatbleError; if (DynamoModel.IsTestMode) return; - MessageBoxService.Show(errorMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Error); + MessageBoxService.Show(Owner, errorMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Error); return; } MarkdownFilesDirectory = directoryPath; @@ -1624,19 +1624,17 @@ private void RemoveSingleItem(PackageItemRootViewModel vm, DependencyType fileTy { var fileName = vm.DisplayName; - if (fileName.ToLower().EndsWith(".dll") || fileType.Equals(DependencyType.Assembly)) + if (fileType.Equals(DependencyType.Assembly)) { - // It is possible that the .dll was external and added as an additional file - if (!Assemblies.Any(x => x.Name.Equals(Path.GetFileNameWithoutExtension(fileName)))) - { - AdditionalFiles.Remove(AdditionalFiles - .First(x => x == fileName)); - } - else - { - Assemblies.Remove(Assemblies - .First(x => x.Name == Path.GetFileNameWithoutExtension(fileName))); - } + Assemblies.Remove(Assemblies + .First(x => x.Name == fileName)); + } + else if (fileName.ToLower().EndsWith(".dll")) + { + fileName = vm.FilePath; + AdditionalFiles.Remove(AdditionalFiles + .First(x => x == fileName)); + } else if (fileType.Equals(DependencyType.CustomNode) || fileType.Equals(DependencyType.CustomNodePreview)) { @@ -1741,7 +1739,7 @@ private void AddDllFile(string filename) // as the existing assembly cannot be modified while Dynamo is active. if (this.Assemblies.Any(x => assemName == x.Assembly.GetName().Name)) { - MessageBoxService.Show(string.Format(Resources.PackageDuplicateAssemblyWarning, + MessageBoxService.Show(Owner, string.Format(Resources.PackageDuplicateAssemblyWarning, dynamoViewModel.BrandingResourceProvider.ProductName), Resources.PackageDuplicateAssemblyWarningTitle, MessageBoxButton.OK, @@ -1861,7 +1859,7 @@ private void PublishLocally() } string FileNotPublishMessage = string.Format(Resources.FileNotPublishMessage, filesCannotBePublished); UploadState = PackageUploadHandle.State.Error; - MessageBoxResult response = DynamoModel.IsTestMode ? MessageBoxResult.OK : MessageBoxService.Show(FileNotPublishMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Error); + MessageBoxResult response = DynamoModel.IsTestMode ? MessageBoxResult.OK : MessageBoxService.Show(Owner, FileNotPublishMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Error); if (response == MessageBoxResult.OK) { @@ -2020,7 +2018,7 @@ private string GetPublishFolder() { ErrorString = String.Format(Resources.FolderNotWritableError, folder); var ErrorMessage = ErrorString + "\n" + Resources.SolutionToFolderNotWritatbleError; - Dynamo.Wpf.Utilities.MessageBoxService.Show(ErrorMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Warning); + Dynamo.Wpf.Utilities.MessageBoxService.Show(Owner, ErrorMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Warning); return string.Empty; } @@ -2183,7 +2181,7 @@ private void PreviewPackageBuild() } string FileNotPublishMessage = string.Format(Resources.FileNotPublishMessage, filesCannotBePublished); UploadState = PackageUploadHandle.State.Error; - MessageBoxResult response = DynamoModel.IsTestMode ? MessageBoxResult.OK : MessageBoxService.Show(FileNotPublishMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Error); + MessageBoxResult response = DynamoModel.IsTestMode ? MessageBoxResult.OK : MessageBoxService.Show(Owner, FileNotPublishMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Error); return; } @@ -2224,7 +2222,7 @@ internal PackageItemRootViewModel GetExistingRootItemViewModel(string publishPat foreach(var item in PackageContents) { item.isChild = true; - rootItem.AddChild(item); + rootItem.AddChildren(item); } return rootItem; } diff --git a/src/DynamoCoreWpf/Views/PackageManager/Controls/CustomBrowserControl.xaml b/src/DynamoCoreWpf/Views/PackageManager/Controls/CustomBrowserControl.xaml index acd184b129b..6a4e1dd5ee8 100644 --- a/src/DynamoCoreWpf/Views/PackageManager/Controls/CustomBrowserControl.xaml +++ b/src/DynamoCoreWpf/Views/PackageManager/Controls/CustomBrowserControl.xaml @@ -324,7 +324,7 @@ - + @@ -462,6 +462,8 @@ FontSize="14" SnapsToDevicePixels="True" UseLayoutRounding="True" + TextTrimming="CharacterEllipsis" + Width="230" FontFamily="{StaticResource ArtifaktElementRegular}"/> diff --git a/src/DynamoCoreWpf/Views/PackageManager/Controls/PackageManagerPublishControl.xaml.cs b/src/DynamoCoreWpf/Views/PackageManager/Controls/PackageManagerPublishControl.xaml.cs index 1f5b58a5d31..c80944f34d9 100644 --- a/src/DynamoCoreWpf/Views/PackageManager/Controls/PackageManagerPublishControl.xaml.cs +++ b/src/DynamoCoreWpf/Views/PackageManager/Controls/PackageManagerPublishControl.xaml.cs @@ -41,6 +41,7 @@ private void InitializeContext(object sender, RoutedEventArgs e) PublishPackageViewModel = this.DataContext as PublishPackageViewModel; + PublishPackageViewModel.Owner = this.Owner; PublishPackageViewModel.PublishSuccess += PackageViewModelOnPublishSuccess; PublishPackageViewModel.RequestShowFolderBrowserDialog += OnRequestShowFolderBrowserDialog; diff --git a/src/DynamoCoreWpf/Views/PackageManager/PackageManagerView.xaml.cs b/src/DynamoCoreWpf/Views/PackageManager/PackageManagerView.xaml.cs index c535bb2f11a..377c67a53bc 100644 --- a/src/DynamoCoreWpf/Views/PackageManager/PackageManagerView.xaml.cs +++ b/src/DynamoCoreWpf/Views/PackageManager/PackageManagerView.xaml.cs @@ -124,6 +124,7 @@ private void CloseButton_Click(object sender, RoutedEventArgs e) private void WindowClosed(object sender, EventArgs e) { this.packageManagerPublish.Dispose(); + this.PackageManagerViewModel.PublishPackageViewModel.CancelCommand.Execute(); this.PackageManagerViewModel.PackageSearchViewModel.RequestShowFileDialog -= OnRequestShowFileDialog; this.PackageManagerViewModel.PackageSearchViewModel.Close(); } diff --git a/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs b/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs index 6a9e7ffa889..333dd715a84 100644 --- a/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs +++ b/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs @@ -22,8 +22,7 @@ public class PublishPackageViewModelTests: DynamoViewModelUnitTest [Test, Category("Failure")] public void AddingDyfRaisesCanExecuteChangeOnDelegateCommand() - { - + { var vm = new PublishPackageViewModel(ViewModel); ViewModel.OnRequestPackagePublishDialog(vm); @@ -44,13 +43,11 @@ public void AddingDyfRaisesCanExecuteChangeOnDelegateCommand() //assert that canExecute changed was fired one time Assert.AreEqual(canExecuteChangedFired, 1); - } [Test] public void SetsErrorState() - { - + { //open a dyf file and modify it string packagedirectory = Path.Combine(TestDirectory, "pkgs"); var packages = Directory.EnumerateDirectories(packagedirectory); @@ -78,7 +75,6 @@ public void SetsErrorState() //assert that we have not uploaded the file or indicated that we have Assert.AreNotEqual(vm.UploadState,PackageUploadHandle.State.Uploaded); Console.WriteLine(vm.ErrorString); - } [Test] @@ -98,7 +94,6 @@ public void CanPublishLateInitializedJsonCustomNode() Assert.AreEqual(1, vm.CustomNodeDefinitions.Count); Assert.DoesNotThrow(() => {vm.GetAllFiles();}); Assert.AreEqual(nodePath, vm.GetAllFiles().First()); - } @@ -148,6 +143,31 @@ public void AddsFilesAndFoldersFromFilePathsCorrectly() Assert.AreEqual(allFilesAndFoldres.Count(i => i.DependencyType.Equals(DependencyType.Folder)), allFolders.Count + 1); } + [Test] + public void RemoveMultipleRootItemsCorrectly() + { + string nodePath = Path.Combine(TestDirectory, "core", "docbrowser\\pkgs\\RootPackageFolder\\PackageWithNodeDocumentation"); + string duplicateNodePath = Path.Combine(TestDirectory, "core", "docbrowser\\pkgs\\RootPackageFolder\\DuplicatePackageWithNodeDocumentation"); + var allFiles = Directory.GetFiles(nodePath, "*", SearchOption.AllDirectories).ToList(); + var allDuplicateFiles = Directory.GetFiles(duplicateNodePath, "*", SearchOption.AllDirectories).ToList(); + + // Arrange + var dlgMock = new Mock(); + dlgMock.Setup(m => m.Show(It.IsAny(), It.IsAny(), It.IsAny(), + It.Is(x => x == MessageBoxButton.OKCancel || x == MessageBoxButton.OK), It.IsAny())) + .Returns(MessageBoxResult.OK); + MessageBoxService.OverrideMessageBoxDuringTests(dlgMock.Object); + + var vm = new PublishPackageViewModel(this.ViewModel); + vm.AddAllFilesAfterSelection(allFiles); + vm.AddAllFilesAfterSelection(allDuplicateFiles); + + var packageContents = vm.PackageContents; + Assert.AreEqual(packageContents.Count, 2); // We expect 2 separate root item here + + Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(packageContents.First())); + } + [Test] public void AddsFilesAndFoldersFromMultipleFilePathsCorrectly() @@ -433,7 +453,7 @@ public void CanRemoveAllDependencyTypes() var dyfPreviewFiles = childItems.Where(x => x.DependencyType.Equals(DependencyType.CustomNodePreview)); var folders = childItems.Where(x => x.DependencyType.Equals(DependencyType.Folder)); - Assert.AreEqual(4, files.Count()); + Assert.AreEqual(5, files.Count()); Assert.AreEqual(1, dllFiles.Count()); Assert.AreEqual(1, dyfPreviewFiles.Count()); Assert.AreEqual(5, folders.Count()); @@ -443,6 +463,7 @@ public void CanRemoveAllDependencyTypes() Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(dyfPreviewFiles.First())); Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(files.First(x => x.DisplayName.EndsWith(".json")))); Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(files.First(x => x.DisplayName.EndsWith(".xml")))); + Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(files.First(x => x.DisplayName.EndsWith(".dll")))); // At this point, only one root item remains, not the original one but the 'doc' folder // The original root item no longer contains a file, therefore it was removed