mattercontrol/Tests/MatterControl.AutomationTests/DesignTools/SheetTests.cs

266 lines
8.2 KiB
C#
Raw Normal View History

2021-07-22 10:02:43 -07:00
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
2021-06-06 09:07:18 -07:00
using System.Threading.Tasks;
2021-06-06 22:18:29 -07:00
using MatterHackers.Agg;
2021-06-14 08:00:14 -07:00
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
2021-06-06 22:18:29 -07:00
using MatterHackers.DataConverters3D;
2021-06-14 08:00:14 -07:00
using MatterHackers.GuiAutomation;
2021-06-06 22:18:29 -07:00
using MatterHackers.MatterControl.DesignTools;
2021-06-11 11:23:15 -07:00
using MatterHackers.MatterControl.DesignTools.Operations;
2021-06-06 09:07:18 -07:00
using MatterHackers.MatterControl.PartPreviewWindow;
2021-06-11 11:23:15 -07:00
using MatterHackers.VectorMath;
2021-06-06 09:07:18 -07:00
using NUnit.Framework;
2022-07-15 17:28:39 -07:00
using TestInvoker;
2021-06-06 09:07:18 -07:00
namespace MatterHackers.MatterControl.Tests.Automation
{
[TestFixture]
public class SheetDataTests
{
[Test]
public void Calculations()
{
var sheetData = new SheetData(4, 4);
void Test(string cell, string expression, string expected)
{
sheetData[cell].Expression = expression;
sheetData.Recalculate();
Assert.AreEqual(expected, sheetData.GetCellValue(cell));
}
// simple multiply retrived upper and lower case
Test("A1", "=4*2", "8");
Test("a1", "=4*2", "8");
// make sure functions are working, max in this case
Test("a2", "=max(4, 5)", "5");
// make sure cell references are working
Test("a3", "=a1+a2", "13");
// complex formulas are working
Test("a4", "=((4+5)/3+7)/5", "2");
// complex formulas with references are working
Test("b1", "=(a4+a3)*.5", "7.5");
// constants work, like pi
Test("b2", "=pi", "3.141592653589793");
// check that we get string data back unmodified
Test("b3", "hello", "hello");
}
}
2022-07-15 17:28:39 -07:00
[TestFixture, Category("MatterControl.UI.Automation"), Parallelizable(ParallelScope.Children)]
2021-06-06 09:07:18 -07:00
public class PrimitiveAndSheetsTests
{
2021-07-22 10:02:43 -07:00
[SetUp]
public void TestSetup()
2021-06-14 08:00:14 -07:00
{
2022-07-15 17:28:39 -07:00
StaticData.RootPath = MatterControlUtilities.StaticDataPath;
MatterControlUtilities.OverrideAppDataLocation(MatterControlUtilities.RootPath);
2021-07-22 10:02:43 -07:00
}
2021-06-14 08:00:14 -07:00
2022-07-15 17:28:39 -07:00
[Test, ChildProcessTest]
2021-07-22 10:02:43 -07:00
public void SheetEditorLayoutAndNavigation()
{
2021-06-14 08:00:14 -07:00
var systemWindow = new SystemWindow(800, 600)
{
Name = "Main Window",
};
2022-08-12 18:05:37 -07:00
InternalTextEditWidget.AddTextWidgetRightClickMenu(ApplicationController.Instance.MenuTheme);
2021-06-14 08:00:14 -07:00
AutomationRunner.TimeToMoveMouse = .1;
var sheetData = new SheetData(5, 5);
var undoBuffer = new UndoBuffer();
var theme = ApplicationController.Instance.Theme;
var sheetEditor = new SheetEditorWidget(sheetData, null, undoBuffer, theme);
2021-06-14 08:00:14 -07:00
systemWindow.AddChild(sheetEditor);
AutomationRunner.ShowWindowAndExecuteTests(systemWindow, testRunner =>
{
2022-03-22 15:54:19 -07:00
testRunner.Delay(1);
2021-06-14 08:00:14 -07:00
return Task.CompletedTask;
},
2000);
}
2022-07-15 17:28:39 -07:00
[Test, ChildProcessTest]
2021-06-10 08:49:15 -07:00
public async Task DimensionsWorkWhenNoSheet()
2021-06-06 09:07:18 -07:00
{
await MatterControlUtilities.RunTest((testRunner) =>
{
2022-02-03 17:21:51 -08:00
testRunner.OpenPartTab();
2021-06-06 09:07:18 -07:00
2021-06-06 22:18:29 -07:00
var primitive = "Cube";
var primitiveName = "Row Item " + primitive;
testRunner.DoubleClickByName(primitiveName);
2021-06-06 09:07:18 -07:00
// Get View3DWidget
2022-07-15 17:28:39 -07:00
View3DWidget view3D = testRunner.GetWidgetByName("View3DWidget", out var window, 3) as View3DWidget;
2021-06-06 09:07:18 -07:00
var scene = view3D.Object3DControlLayer.Scene;
2021-06-06 22:18:29 -07:00
testRunner.WaitForName(primitive);
Assert.AreEqual(1, scene.Children.Count, "Should have 1 part");
var cube = testRunner.GetObjectByName(primitive, out _) as CubeObject3D;
Assert.AreEqual(20, cube.Width.Value(cube), .001);
2021-06-06 09:07:18 -07:00
// Select scene object
2021-06-06 22:18:29 -07:00
testRunner.Select3DPart(primitive);
// Scale it wider
testRunner.DragDropByName("ScaleWidthRight",
"ScaleWidthRight",
offsetDrag: new Point2D(0, 0),
offsetDrop: new Point2D(0, 10));
Assert.Greater(cube.Width.Value(cube), 20.0);
testRunner.ClickByName("3D View Undo");
Assert.AreEqual(20, cube.Width.Value(cube), .0001);
2021-06-06 22:18:29 -07:00
// try scaling by text entry
testRunner.ClickByName("ScaleWidthLeft")
.ClickByName("XValueDisplay")
2022-07-15 17:28:39 -07:00
//.Assert(() => testRunner.GetWidgetByName("XValueDisplay", out var _).ContainsFocus, "Focus") // Sometimes, when the moves over to XValueDisplay, XValueDisplay just isn't there.
2021-06-10 08:49:15 -07:00
.Type("35")
2022-07-15 17:28:39 -07:00
//.Assert(() => ((CustomWidgets.InlineEditControl)testRunner.GetWidgetByName("XValueDisplay", out var _)).Value == 35, "text")
2021-06-10 08:49:15 -07:00
.Type("{Enter}");
2022-07-15 17:28:39 -07:00
//.WaitFor(() => 35 == cube.Width.Value(cube));
/*if (35 != cube.Width.Value(cube))
{
System.Diagnostics.Debugger.Launch();
System.Diagnostics.Debugger.Break();
}*/
// NOTE: Happened once: Expected: 35, But was: 20.0d
// This can happen when running only this test, and alt-tabbing frequently.
// Failure again after platform focus fix.
// This can happen when running only this test, and not alt-tabbing frequently.
// Failure can happen in original .NET Framework MatterControl testing too.
// Possible cause is OnMouseMove(MatterHackers.Agg.UI.MouseEventArgs) (MatterHackers.MatterControl.PartPreviewWindow.Object3DControlsLayer) not updating the hover control in time.
2021-06-10 08:49:15 -07:00
Assert.AreEqual(35, cube.Width.Value(cube));
testRunner.ClickByName("3D View Undo");
Assert.AreEqual(20, cube.Width.Value(cube), .0001);
2021-06-10 08:49:15 -07:00
// try scaling by text entry of an equation
testRunner.ClickByName("Width Field")
.Type("=40 + 5")
.Type("{Enter}");
Assert.AreEqual(45, cube.Width.Value(cube));
// Select Nothing
testRunner.ClickByName("View3DWidget");
2021-06-11 11:23:15 -07:00
testRunner.SelectNone();
2021-06-10 08:49:15 -07:00
Assert.AreEqual(null, scene.SelectedItem);
// and re-select the object
2021-06-11 11:23:15 -07:00
testRunner.SelectAll();
2021-06-10 08:49:15 -07:00
Assert.AreEqual(1, scene.Children.Count);
Assert.AreEqual(cube, scene.SelectedItem);
// now that has an equation in the width it should not have an x edge controls
Assert.IsFalse(testRunner.NameExists("ScaleWidthRight", .2));
testRunner.ClickByName("3D View Undo");
Assert.AreEqual(20, cube.Width.Value(cube), .0001);
2021-06-10 08:49:15 -07:00
return Task.CompletedTask;
}, overrideWidth: 1300, maxTimeToRun: 60);
}
2022-07-15 17:28:39 -07:00
[Test, ChildProcessTest]
2021-06-10 08:49:15 -07:00
public async Task ScaleObjectWorksWithAndWithoutSheet()
{
await MatterControlUtilities.RunTest((testRunner) =>
{
2022-02-03 17:21:51 -08:00
testRunner.OpenPartTab();
2021-06-10 08:49:15 -07:00
var primitive = "Cube";
var primitiveName = "Row Item " + primitive;
testRunner.DoubleClickByName(primitiveName);
// Get View3DWidget
View3DWidget view3D = testRunner.GetWidgetByName("View3DWidget", out _, 3) as View3DWidget;
var scene = view3D.Object3DControlLayer.Scene;
testRunner.WaitForName(primitive);
Assert.AreEqual(1, scene.Children.Count, "Should have 1 part");
var cube = testRunner.GetObjectByName(primitive, out _) as CubeObject3D;
Assert.AreEqual(20, cube.Width.Value(cube));
2021-06-11 11:23:15 -07:00
// Select scene object and add a scale
testRunner.Select3DPart(primitive)
.ClickByName("Scale Inner SplitButton")
.ClickByName("Width Edit")
.Type("25")
.Type("{Enter}")
.Delay();
2021-06-10 08:49:15 -07:00
2021-06-11 11:23:15 -07:00
var scale = testRunner.GetObjectByName("Scale", out _) as ScaleObject3D_3;
var scaleAabb = scale.GetAxisAlignedBoundingBox(Matrix4X4.Identity);
Assert.AreEqual(25, scaleAabb.XSize);
2021-06-10 08:49:15 -07:00
2021-06-11 11:23:15 -07:00
// add a scale to the object
2021-06-06 09:07:18 -07:00
return Task.CompletedTask;
}, overrideWidth: 1300, maxTimeToRun: 60);
}
2021-07-22 10:02:43 -07:00
2022-07-15 17:28:39 -07:00
[Test, ChildProcessTest]
2021-07-22 10:02:43 -07:00
public void SheetEditorNavigationTests()
{
var systemWindow = new SystemWindow(800, 600)
{
Name = "Main Window",
};
2022-08-12 18:05:37 -07:00
InternalTextEditWidget.AddTextWidgetRightClickMenu(ApplicationController.Instance.MenuTheme);
2021-07-22 10:02:43 -07:00
AutomationRunner.TimeToMoveMouse = .1;
var theme = ApplicationController.Instance.Theme;
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Stretch,
};
systemWindow.AddChild(container);
var sheetData = new SheetData(5, 5);
var undoBuffer = new UndoBuffer();
var sheetEditorWidget = new SheetEditorWidget(sheetData, null, undoBuffer, theme);
2021-07-22 10:02:43 -07:00
container.AddChild(sheetEditorWidget);
systemWindow.RunTest(testRunner =>
{
2021-09-14 17:18:48 -07:00
//testRunner.Delay(60);
2021-07-22 10:02:43 -07:00
return Task.CompletedTask;
},
2000);
}
}
public static class RunnerX
{
public static Task RunTest(this SystemWindow systemWindow, AutomationTest automationTest, int timeout)
{
return AutomationRunner.ShowWindowAndExecuteTests(systemWindow, automationTest, timeout);
}
2021-06-06 09:07:18 -07:00
}
}