This commit is contained in:
John Lewin 2017-02-01 10:20:50 -08:00
parent 7844d9126c
commit d34c42487f
3 changed files with 131 additions and 4 deletions

View file

@ -118,6 +118,10 @@
<Project>{195cbe56-e654-437b-ab05-3be1b9452497}</Project>
<Name>Agg.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\..\Submodules\agg-sharp\VectorMath\VectorMath.csproj">
<Project>{D3E41B4E-BFBB-44CA-94C8-95C00F754FDD}</Project>
<Name>VectorMath</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />

View file

@ -1,16 +1,13 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.UI.Tests;
using MatterHackers.GuiAutomation;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.PrinterEmulator;
using MatterHackers.VectorMath;
using NUnit.Framework;
namespace MatterHackers.MatterControl.Tests.Automation
@ -113,5 +110,112 @@ namespace MatterHackers.MatterControl.Tests.Automation
await MatterControlUtilities.RunTest(testToRun, maxTimeToRun: 300);
}
private EventHandler unregisterEvents;
[Test, Apartment(ApartmentState.STA)]
public async Task TuningAdjustmentsResetToOne()
{
AutomationTest testToRun = (testRunner) =>
{
SystemWindow systemWindow;
testRunner.WaitForName("Cancel Wizard Button", 1);
using (var emulatorDisposable = testRunner.LaunchAndConnectToPrinterEmulator())
{
SolidSlider slider;
Assert.IsTrue(ProfileManager.Instance.ActiveProfile != null);
testRunner.SwitchToSettingsAndControls();
testRunner.ClickByName("Controls Tab", 1);
testRunner.ClickByName("Start Print Button", 1);
var container = testRunner.GetWidgetByName("ManualPrinterControls.ControlsContainer", out systemWindow, 5);
// Scroll the widget into view
var scrollable = container.Parents<ManualPrinterControls>().First().Parents<ScrollableWidget>().First();
var width = scrollable.Width;
double targetExtrusionRate = 1.5;
double targetFeedRate = 2;
// Workaround needed to scroll to the bottom of the Controls panel
//scrollable.ScrollPosition = new Vector2();
scrollable.ScrollPosition = new Vector2(0, 30);
// Workaround to force layout to fix problems with size of Tuning Widgets after setting ScrollPosition manually
scrollable.Width = width - 1;
scrollable.Width = width;
// Workaround for MatterHackers/MCCentral#1157 - wait for slicing to complete before setting tuning values
testRunner.Wait(5);
testRunner.ClickByName("Extrusion Multiplier NumberEdit");
testRunner.Wait(.2);
testRunner.Type(targetExtrusionRate.ToString());
testRunner.Wait(.2);
testRunner.ClickByName("Feed Rate NumberEdit");
testRunner.Wait(.2);
testRunner.Type(targetFeedRate.ToString());
testRunner.Wait(.2);
// Force focus away from the feed rate field
testRunner.ClickByName("Controls Tab", 1);
testRunner.Wait(.2);
// Assert the changes took effect on the UI
slider = testRunner.GetWidgetByName("Extrusion Multiplier Slider", out systemWindow, 5) as SolidSlider;
Assert.AreEqual(targetExtrusionRate, slider.Value);
slider = testRunner.GetWidgetByName("Feed Rate Slider", out systemWindow, 5) as SolidSlider;
Assert.AreEqual(targetFeedRate, slider.Value);
testRunner.Wait(.2);
// Assert the changes took effect on the model
Assert.AreEqual(targetExtrusionRate, PrinterConnectionAndCommunication.Instance.ExtrusionRatio);
Assert.AreEqual(targetFeedRate, PrinterConnectionAndCommunication.Instance.FeedRateRatio);
var resetEvent = new AutoResetEvent(false);
// Release reset event on PrintFinished
PrinterConnectionAndCommunication.Instance.PrintFinished.RegisterEvent((s, e) => resetEvent.Set(), ref unregisterEvents);
resetEvent.WaitOne();
// Finish the print
testRunner.WaitForName("Done Button", 30);
testRunner.WaitForName("Print Again Button", 1);
// Restart the print
testRunner.ClickByName("Print Again Button", 1);
testRunner.Wait(2);
testRunner.CancelPrint();
// Assert we've reset to 1
Assert.AreEqual(1, PrinterConnectionAndCommunication.Instance.FeedRateRatio);
Assert.AreEqual(1, PrinterConnectionAndCommunication.Instance.ExtrusionRatio);
// Assert the changes took effect on the UI
slider = testRunner.GetWidgetByName("Extrusion Multiplier Slider", out systemWindow, 5) as SolidSlider;
Assert.AreEqual(1, slider.Value);
slider = testRunner.GetWidgetByName("Feed Rate Slider", out systemWindow, 5) as SolidSlider;
Assert.AreEqual(1, slider.Value);
}
return Task.FromResult(0);
};
await MatterControlUtilities.RunTest(testToRun, overrideHeight:900, maxTimeToRun: 90);
}
}
}

View file

@ -207,6 +207,16 @@ namespace MatterHackers.MatterControl.Tests.Automation
return emulator;
}
public static void CancelPrint(this AutomationRunner testRunner)
{
testRunner.ClickByName("Cancel Print Button");
if (testRunner.WaitForName("Yes Button", 1))
{
testRunner.ClickByName("Yes Button");
}
}
public static bool CompareExpectedSliceSettingValueWithActualVaue(string sliceSetting, string expectedValue)
{
string fullPath = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "temp", runName, "Test0", "data", "gcode");
@ -454,6 +464,15 @@ namespace MatterHackers.MatterControl.Tests.Automation
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
public static void SwitchToSettingsAndControls(this AutomationRunner testRunner)
{
if (testRunner.WaitForName("SettingsAndControls", .2))
{
testRunner.ClickByName("SettingsAndControls");
testRunner.Wait(.5);
}
}
public static void SwitchToAdvancedSettings(AutomationRunner testRunner)
{
if (testRunner.WaitForName("SettingsAndControls", .2))