Writing test for Save As functionality
This commit is contained in:
parent
e3ede822f9
commit
11ff49bb7e
11 changed files with 152 additions and 26 deletions
|
|
@ -304,6 +304,7 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
|
||||
var yesButton = theme.CreateDialogButton(yesText);
|
||||
yesButton.Name = "Yes Button";
|
||||
yesButton.Click += (s, e) =>
|
||||
{
|
||||
// If applicable, invoke the callback
|
||||
|
|
@ -316,6 +317,7 @@ namespace MatterHackers.MatterControl
|
|||
this.AddPageAction(yesButton, true);
|
||||
|
||||
var noButton = theme.CreateDialogButton(noText);
|
||||
noButton.Name = "No Button";
|
||||
noButton.Click += (s, e) =>
|
||||
{
|
||||
// If applicable, invoke the callback
|
||||
|
|
@ -328,8 +330,7 @@ namespace MatterHackers.MatterControl
|
|||
this.AddPageAction(noButton);
|
||||
|
||||
this.WindowTitle = "MatterControl - " + "Please Confirm".Localize();
|
||||
yesButton.Name = "Yes Button";
|
||||
this.SetCancelButtonName("No Button");
|
||||
this.SetCancelButtonName("Cancel Button");
|
||||
|
||||
this.AdjustTextWrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -475,6 +475,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
UiThread.RunOnIdle(async () =>
|
||||
{
|
||||
await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), this, partTab.Workspace.SceneContext.SaveChanges);
|
||||
|
||||
|
||||
this.CloseClicked?.Invoke(this, null);
|
||||
// Must be called after CloseClicked otherwise listeners are cleared before event is invoked
|
||||
this.parentTabControl.CloseTab(this);
|
||||
|
|
|
|||
|
|
@ -1202,7 +1202,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
this.DragOperationActive = true;
|
||||
|
||||
// ContentStore is null for plated gcode, call ClearPlate to exit mode and return to bed mcx
|
||||
if (sceneContext.EditContext.ContentStore == null)
|
||||
if (sceneContext.Printer?.Bed?.LoadedGCode != null)
|
||||
{
|
||||
this.ClearPlate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -841,7 +841,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
|
|||
return theme.CreateSplitButton(new SplitButtonParams()
|
||||
{
|
||||
ButtonText = "Save".Localize(),
|
||||
ButtonName = "Save",
|
||||
ButtonName = "Save Button",
|
||||
Icon = StaticData.Instance.LoadIcon("save_grey_16x.png", 16, 16).SetToColor(theme.TextColor),
|
||||
ButtonAction = (menuButton) =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit cc9acbd562493175ae80bab2c23fbe6e2d25a006
|
||||
Subproject commit 255aa2aa1a9a157fb44e0aa9a62438173de67905
|
||||
|
|
@ -45,7 +45,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
testRunner.OpenEmptyPartTab();
|
||||
testRunner.OpenPartTab();
|
||||
|
||||
testRunner.NavigateToFolder("Local Library Row Item Collection");
|
||||
testRunner.InvokeLibraryCreateFolderDialog();
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
testRunner.OpenEmptyPartTab();
|
||||
testRunner.OpenPartTab();
|
||||
|
||||
var primitive = "Cube";
|
||||
var primitiveName = "Row Item " + primitive;
|
||||
|
|
@ -130,7 +130,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
testRunner.OpenEmptyPartTab();
|
||||
testRunner.OpenPartTab();
|
||||
|
||||
var primitive = "Cube";
|
||||
var primitiveName = "Row Item " + primitive;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
using System.Threading;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.MatterControl.PartPreviewWindow;
|
||||
using MatterHackers.MatterControl.PrintQueue;
|
||||
using NUnit.Framework;
|
||||
|
|
@ -14,7 +17,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
testRunner.OpenEmptyPartTab();
|
||||
testRunner.OpenPartTab();
|
||||
|
||||
testRunner.AddItemToBed();
|
||||
|
||||
|
|
@ -29,24 +32,113 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
testRunner.Select3DPart("Calibration - Box.stl")
|
||||
// Click Copy button and count Scene.Children
|
||||
.ClickByName("Duplicate Button")
|
||||
.WaitFor(() => scene.Children.Count == 2);
|
||||
Assert.AreEqual(2, scene.Children.Count, "Should have 2 parts after copy");
|
||||
.Require(() => scene.Children.Count == 2, "Should have 2 parts after copy");
|
||||
|
||||
// Click Copy button a second time and count Scene.Children
|
||||
testRunner.ClickByName("Duplicate Button");
|
||||
testRunner.WaitFor(() => scene.Children.Count > 2);
|
||||
Assert.AreEqual(3, scene.Children.Count, "Should have 3 parts after 2nd copy");
|
||||
testRunner.Require(() => scene.Children.Count == 3, "Should have 3 parts after 2nd copy");
|
||||
|
||||
return Task.CompletedTask;
|
||||
}, overrideWidth: 1300, maxTimeToRun: 60);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DesignTabFileOpperations()
|
||||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
testRunner.OpenPartTab(false);
|
||||
|
||||
// Get View3DWidget
|
||||
var view3D = testRunner.GetWidgetByName("View3DWidget", out SystemWindow systemWindow, 3) as View3DWidget;
|
||||
var scene = view3D.Object3DControlLayer.Scene;
|
||||
|
||||
testRunner.Require(() => scene.Children.Count == 1, "Should have 1 part (the phil)");
|
||||
|
||||
var tempFilaname = "Temp Test Save.mcx";
|
||||
var tempFullPath = Path.Combine(ApplicationDataStorage.Instance.MyDocumentsDirectory, tempFilaname);
|
||||
|
||||
// delete the temp file if it exists in the Downloads folder
|
||||
void DeleteTempFile()
|
||||
{
|
||||
if (File.Exists(tempFullPath))
|
||||
{
|
||||
File.Delete(tempFullPath);
|
||||
}
|
||||
}
|
||||
|
||||
DeleteTempFile();
|
||||
|
||||
// Make sure the tab is named 'New Design'
|
||||
Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design"));
|
||||
|
||||
// Click the save button
|
||||
testRunner.ClickByName("Save Button")
|
||||
// Cancle the save as
|
||||
.ClickByName("Cancel Wizard Button");
|
||||
|
||||
// Make sure the tab is named 'New Design'
|
||||
Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design"));
|
||||
|
||||
// Click the close tab button
|
||||
testRunner.ClickByName("Close Tab Button")
|
||||
// Select Cancel
|
||||
.ClickByName("Cancel Button");
|
||||
|
||||
// Make sure the tab is named 'New Design'
|
||||
Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design"));
|
||||
|
||||
// Click the close tab button
|
||||
testRunner.ClickByName("Close Tab Button")
|
||||
// Select 'Save'
|
||||
.ClickByName("Yes Button")
|
||||
// Cancel the 'Save As'
|
||||
.ClickByName("Cancel Wizard Button");
|
||||
|
||||
// Make sure the window is still open and the tab is named 'New Design'
|
||||
Assert.IsNotNull(systemWindow.GetVisibleWigetWithText("New Design"));
|
||||
|
||||
// Click the save button
|
||||
testRunner.ClickByName("Save Button")
|
||||
// Save a temp file to the downloads folder
|
||||
.DoubleClickByName("Computer Row Item Collection")
|
||||
.DoubleClickByName("Downloads Row Item Collection")
|
||||
.ClickByName("Design Name Edit Field")
|
||||
.Type(tempFilaname)
|
||||
.ClickByName("Accept Button");
|
||||
// Verify it is there
|
||||
Assert.IsTrue(File.Exists(tempFullPath));
|
||||
// And that the tab got the name
|
||||
Assert.IsNotNull(systemWindow.GetVisibleWigetWithText(tempFilaname));
|
||||
// and the tooltip is right
|
||||
Assert.IsTrue(systemWindow.GetVisibleWigetWithText(tempFilaname).ToolTipText == tempFullPath);
|
||||
// Add a part to the bed
|
||||
testRunner.AddItemToBed();
|
||||
// Click the close tab button (we have an edit so it should show the save request)
|
||||
testRunner.ClickByName("Close Tab Button")
|
||||
// Click the 'Cancel'
|
||||
.ClickByName("Cancel Button")
|
||||
// Click the 'Save' button
|
||||
.ClickByName("Save Button")
|
||||
// Click the close button (now we have no edit it should cancel without request)
|
||||
.ClickByName("Close Tab Button");
|
||||
|
||||
// Verify the tab closes without requesting save
|
||||
testRunner.Require(() => systemWindow.GetVisibleWigetWithText(tempFilaname) == null, "The tab should have closed");
|
||||
|
||||
// delete the temp file if it exists in the Downloads folder
|
||||
DeleteTempFile();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}, maxTimeToRun: 60);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GroupAndUngroup()
|
||||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
testRunner.OpenEmptyPartTab();
|
||||
testRunner.OpenPartTab();
|
||||
|
||||
testRunner.AddItemToBed();
|
||||
|
||||
|
|
@ -63,8 +155,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
for (int i = 2; i <= 6; i++)
|
||||
{
|
||||
testRunner.ClickByName("Duplicate Button")
|
||||
.WaitFor(() => scene.Children.Count == i);
|
||||
Assert.AreEqual(i, scene.Children.Count, $"Should have {i} parts after copy");
|
||||
.Require(() => scene.Children.Count == i, $"Should have {i} parts after copy");
|
||||
}
|
||||
|
||||
// Get MeshGroupCount before Group is clicked
|
||||
|
|
@ -75,12 +166,10 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
// select all
|
||||
.Type("^a")
|
||||
.ClickByName("Group Button")
|
||||
.WaitFor(() => scene.Children.Count == 1);
|
||||
Assert.AreEqual(1, scene.Children.Count, $"Should have 1 parts after group");
|
||||
.Require(() => scene.Children.Count == 1, $"Should have 1 parts after group");
|
||||
|
||||
testRunner.ClickByName("Ungroup Button")
|
||||
.WaitFor(() => scene.Children.Count == 6);
|
||||
Assert.AreEqual(6, scene.Children.Count, $"Should have 6 parts after ungroup");
|
||||
.Require(() => scene.Children.Count == 6, $"Should have 6 parts after ungroup");
|
||||
|
||||
return Task.CompletedTask;
|
||||
}, overrideWidth: 1300);
|
||||
|
|
@ -91,7 +180,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
testRunner.OpenEmptyPartTab();
|
||||
testRunner.OpenPartTab();
|
||||
|
||||
testRunner.AddItemToBed();
|
||||
|
||||
|
|
@ -172,4 +261,35 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static class WidgetExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Search the widget stack for a widget that is both visible on screen and has it's text set to the visibleText string
|
||||
/// </summary>
|
||||
/// <param name="widget">The root widget to search</param>
|
||||
/// <param name="">the name to search for</param>
|
||||
/// <returns></returns>
|
||||
public static GuiWidget GetVisibleWigetWithText(this GuiWidget widget, string visibleText)
|
||||
{
|
||||
if (widget.ActuallyVisibleOnScreen())
|
||||
{
|
||||
if (widget.Text == visibleText)
|
||||
{
|
||||
return widget;
|
||||
}
|
||||
|
||||
foreach(var child in widget.Children)
|
||||
{
|
||||
var childWithText = GetVisibleWigetWithText(child, visibleText);
|
||||
if (childWithText != null)
|
||||
{
|
||||
return childWithText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
testRunner.OpenEmptyPartTab();
|
||||
testRunner.OpenPartTab();
|
||||
|
||||
testRunner.AddTestAssetsToLibrary(new[] { "Batman.stl" });
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
{
|
||||
await MatterControlUtilities.RunTest((testRunner) =>
|
||||
{
|
||||
testRunner.OpenEmptyPartTab()
|
||||
testRunner.OpenPartTab()
|
||||
.AddItemToBed();
|
||||
|
||||
var view3D = testRunner.GetWidgetByName("View3DWidget", out _) as View3DWidget;
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
return testRunner;
|
||||
}
|
||||
|
||||
public static AutomationRunner OpenEmptyPartTab(this AutomationRunner testRunner)
|
||||
public static AutomationRunner OpenPartTab(this AutomationRunner testRunner, bool removeDefaultPhil = true)
|
||||
{
|
||||
SystemWindow systemWindow;
|
||||
testRunner.GetWidgetByName("Hardware Tab", out systemWindow, 10);
|
||||
|
|
@ -250,7 +250,10 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
|||
testRunner.ClickByName("Start New Design");
|
||||
}
|
||||
|
||||
testRunner.VerifyAndRemovePhil();
|
||||
if (removeDefaultPhil)
|
||||
{
|
||||
testRunner.VerifyAndRemovePhil();
|
||||
}
|
||||
|
||||
return testRunner;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue