mattercontrol/Tests/MatterControl.AutomationTests/PartPreviewTests.cs

162 lines
5.1 KiB
C#
Raw Normal View History

using System.Threading;
using System.Threading.Tasks;
using MatterHackers.MatterControl.PartPreviewWindow;
using MatterHackers.MatterControl.PrintQueue;
using NUnit.Framework;
namespace MatterHackers.MatterControl.Tests.Automation
{
[TestFixture, Category("MatterControl.UI.Automation"), RunInApplicationDomain, Apartment(ApartmentState.STA)]
public class PartPreviewTests
{
[Test]
public async Task CopyButtonMakesCopyOfPart()
{
await MatterControlUtilities.RunTest((testRunner) =>
{
testRunner.OpenEmptyPartTab();
testRunner.AddItemToBedplate();
2016-10-19 11:10:30 -07:00
// Get View3DWidget
View3DWidget view3D = testRunner.GetWidgetByName("View3DWidget", out _, 3) as View3DWidget;
2020-09-11 19:59:14 -07:00
var scene = view3D.Object3DControlLayer.Scene;
2016-10-19 11:10:30 -07:00
testRunner.WaitForName("Calibration - Box.stl");
2017-09-16 01:11:44 -07:00
Assert.AreEqual(1, scene.Children.Count, "Should have 1 part before copy");
// Select scene object
testRunner.Select3DPart("Calibration - Box.stl");
2016-10-19 11:10:30 -07:00
// Click Copy button and count Scene.Children
testRunner.ClickByName("Duplicate Button");
testRunner.WaitFor(() => scene.Children.Count == 2);
2017-09-16 01:11:44 -07:00
Assert.AreEqual(2, scene.Children.Count, "Should have 2 parts after copy");
2016-10-19 11:10:30 -07:00
2017-03-15 16:17:06 -07:00
// Click Copy button a second time and count Scene.Children
testRunner.ClickByName("Duplicate Button");
testRunner.WaitFor(() => scene.Children.Count > 2);
2017-09-16 01:11:44 -07:00
Assert.AreEqual(3, scene.Children.Count, "Should have 3 parts after 2nd copy");
return Task.CompletedTask;
}, overrideWidth: 1300, maxTimeToRun: 60);
}
[Test]
public async Task GroupAndUngroup()
{
await MatterControlUtilities.RunTest((testRunner) =>
{
testRunner.OpenEmptyPartTab();
testRunner.AddItemToBedplate();
// Get View3DWidget and count Scene.Children before Copy button is clicked
View3DWidget view3D = testRunner.GetWidgetByName("View3DWidget", out _, 3) as View3DWidget;
2020-09-11 19:59:14 -07:00
var scene = view3D.Object3DControlLayer.Scene;
// Assert expected start count
2017-09-16 01:11:44 -07:00
Assert.AreEqual(1, scene.Children.Count, "Should have one part before copy");
// Select scene object
testRunner.Select3DPart("Calibration - Box.stl");
for (int i = 2; i <= 6; i++)
2016-10-19 11:10:30 -07:00
{
testRunner.ClickByName("Duplicate Button");
testRunner.WaitFor(() => scene.Children.Count == i);
2017-09-16 01:11:44 -07:00
Assert.AreEqual(i, scene.Children.Count, $"Should have {i} parts after copy");
2016-10-19 11:10:30 -07:00
}
// Get MeshGroupCount before Group is clicked
2017-09-16 01:11:44 -07:00
Assert.AreEqual(6, scene.Children.Count, "Scene should have 6 parts after copy loop");
2017-03-15 16:17:06 -07:00
// Duplicate button moved to new container - move focus back to View3DWidget so CTRL-A below is seen by expected control
testRunner.Select3DPart("Calibration - Box.stl");
// select all
2017-03-15 16:17:06 -07:00
testRunner.Type("^a");
testRunner.ClickByName("Group Button");
testRunner.WaitFor(() => scene.Children.Count == 1);
2017-09-16 01:11:44 -07:00
Assert.AreEqual(1, scene.Children.Count, $"Should have 1 parts after group");
testRunner.ClickByName("Ungroup Button");
testRunner.WaitFor(() => scene.Children.Count == 6);
2017-09-16 01:11:44 -07:00
Assert.AreEqual(6, scene.Children.Count, $"Should have 6 parts after ungroup");
return Task.CompletedTask;
}, overrideWidth: 1300);
}
[Test]
public async Task RemoveButtonRemovesParts()
{
2017-06-05 23:06:50 -07:00
await MatterControlUtilities.RunTest((testRunner) =>
{
testRunner.OpenEmptyPartTab();
testRunner.AddItemToBedplate();
2017-09-16 01:11:44 -07:00
2017-06-05 23:06:50 -07:00
var view3D = testRunner.GetWidgetByName("View3DWidget", out _) as View3DWidget;
2020-09-11 19:59:14 -07:00
var scene = view3D.Object3DControlLayer.Scene;
2017-06-05 23:06:50 -07:00
testRunner.Select3DPart("Calibration - Box.stl");
2017-09-16 01:11:44 -07:00
Assert.AreEqual(1, scene.Children.Count, "There should be 1 part on the bed after AddDefaultFileToBedplate()");
2017-06-05 23:06:50 -07:00
// Add 5 items
2016-10-19 11:10:30 -07:00
for (int i = 0; i <= 4; i++)
{
testRunner.ClickByName("Duplicate Button");
2017-02-01 10:12:31 -08:00
testRunner.Delay(.5);
2016-10-19 11:10:30 -07:00
}
2017-09-16 01:11:44 -07:00
Assert.AreEqual(6, scene.Children.Count, "There should be 6 parts on the bed after the copy loop");
2017-06-05 23:06:50 -07:00
// Remove an item
testRunner.ClickByName("Remove Button");
2017-06-05 23:06:50 -07:00
// Confirm
2017-09-16 01:11:44 -07:00
Assert.AreEqual(5, scene.Children.Count, "There should be 5 parts on the bed after remove");
2017-06-05 23:06:50 -07:00
return Task.CompletedTask;
}, overrideWidth:1300);
}
[Test]
public async Task SaveAsToQueue()
{
await MatterControlUtilities.RunTest((testRunner) =>
{
2018-10-10 13:33:16 -07:00
testRunner.AddAndSelectPrinter();
testRunner.AddItemToBedplate();
var view3D = testRunner.GetWidgetByName("View3DWidget", out _) as View3DWidget;
testRunner.Select3DPart("Calibration - Box.stl");
2016-10-19 11:10:30 -07:00
for (int i = 0; i <= 2; i++)
{
testRunner.ClickByName("Duplicate Button");
2017-02-01 10:12:31 -08:00
testRunner.Delay(.5);
2016-10-19 11:10:30 -07:00
}
int expectedCount = QueueData.Instance.ItemCount + 1;
testRunner.SaveBedplateToFolder("Test PartA", "Print Queue Row Item Collection");
// Click Home -> Local Library
2017-06-18 10:02:34 -07:00
testRunner.NavigateToLibraryHome();
testRunner.NavigateToFolder("Print Queue Row Item Collection");
Assert.IsTrue(testRunner.WaitForName("Row Item Test PartA", 5), "The part we added should be in the library");
Assert.AreEqual(expectedCount, QueueData.Instance.ItemCount, "Queue count should increase by one after Save operation");
return Task.CompletedTask;
}, overrideWidth: 1300);
}
}
}