Skip to content

Commit

Permalink
test remove multiple
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
dnenov committed Oct 29, 2023
1 parent c3de2d7 commit b17a4af
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public HostComboboxEntry(string hostName)
}
}

public PublishPackageView Owner { get; set; }
public Window Owner { get; set; }

/// <summary>
/// A event called when publishing was a success
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
<ColumnDefinition MinWidth="19" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
Expand Down Expand Up @@ -462,6 +462,8 @@
FontSize="14"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
TextTrimming="CharacterEllipsis"
Width="230"
FontFamily="{StaticResource ArtifaktElementRegular}"/>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
37 changes: 29 additions & 8 deletions test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public class PublishPackageViewModelTests: DynamoViewModelUnitTest

[Test, Category("Failure")]
public void AddingDyfRaisesCanExecuteChangeOnDelegateCommand()
{

{
var vm = new PublishPackageViewModel(ViewModel);
ViewModel.OnRequestPackagePublishDialog(vm);

Expand All @@ -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);
Expand Down Expand Up @@ -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]
Expand All @@ -98,7 +94,6 @@ public void CanPublishLateInitializedJsonCustomNode()
Assert.AreEqual(1, vm.CustomNodeDefinitions.Count);
Assert.DoesNotThrow(() => {vm.GetAllFiles();});
Assert.AreEqual(nodePath, vm.GetAllFiles().First());

}


Expand Down Expand Up @@ -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<MessageBoxService.IMessageBox>();
dlgMock.Setup(m => m.Show(It.IsAny<Window>(), It.IsAny<string>(), It.IsAny<string>(),
It.Is<MessageBoxButton>(x => x == MessageBoxButton.OKCancel || x == MessageBoxButton.OK), It.IsAny<MessageBoxImage>()))
.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()
Expand Down Expand Up @@ -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());
Expand All @@ -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
Expand Down

0 comments on commit b17a4af

Please sign in to comment.