2017-05-21 18:02:53 -07:00
/ *
Copyright ( c ) 2017 , Lars Brubaker , John Lewin
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
1. Redistributions of source code must retain the above copyright notice , this
list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
and / or other materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies ,
either expressed or implied , of the FreeBSD Project .
* /
using System.IO ;
using System.Threading ;
using System.Threading.Tasks ;
using MatterHackers.Agg.UI ;
using MatterHackers.MatterControl.PrintQueue ;
using NUnit.Framework ;
namespace MatterHackers.MatterControl.Tests.Automation
{
2018-02-01 09:05:24 -08:00
[TestFixture, Ignore("Product code still needs to be implemented"), Category("MatterControl.UI.Automation"), RunInApplicationDomain, Apartment(ApartmentState.STA)]
2017-05-21 18:02:53 -07:00
public class LibraryActionTests
{
2017-06-14 09:58:25 -07:00
[Test]
2017-05-21 18:02:53 -07:00
public async Task ClickOnExportButton ( )
{
2017-10-30 23:05:38 -07:00
await MatterControlUtilities . RunTest ( testRunner = >
2017-05-21 18:02:53 -07:00
{
// Tests that clicking the queue export button with a single item selected opens export item window
2018-10-10 13:33:16 -07:00
testRunner . AddAndSelectPrinter ( ) ;
2017-05-21 18:02:53 -07:00
//Make sure that the export window does not exist
bool exportWindowExists1 = testRunner . WaitForName ( "Export Item Window" , 0 ) ;
Assert . IsTrue ( exportWindowExists1 = = false , "Export window does not exist" ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Queue Export Button" ) ;
2017-05-21 18:02:53 -07:00
SystemWindow containingWindow ;
GuiWidget exportWindow = testRunner . GetWidgetByName ( "Export Item Window" , out containingWindow , 5 ) ;
Assert . IsTrue ( exportWindow ! = null , "Export window does exist" ) ;
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-10-30 23:05:38 -07:00
} , queueItemFolderToAdd : QueueTemplate . Three_Queue_Items ) ;
2017-05-21 18:02:53 -07:00
}
/// <summary>
/// Confirms the Export to Zip feature compresses and exports to a zip file and that file imports without issue
/// </summary>
/// <returns></returns>
2017-06-14 09:58:25 -07:00
[Test]
2017-05-21 18:02:53 -07:00
public async Task ExportToZipImportFromZip ( )
{
2017-10-30 23:05:38 -07:00
await MatterControlUtilities . RunTest ( testRunner = >
2017-05-21 18:02:53 -07:00
{
// Ensure output file does not exist
string exportZipPath = MatterControlUtilities . GetTestItemPath ( "TestExportZip.zip" ) ;
if ( File . Exists ( exportZipPath ) )
{
File . Delete ( exportZipPath ) ;
}
2018-10-10 13:33:16 -07:00
testRunner . AddAndSelectPrinter ( ) ;
2017-05-21 18:02:53 -07:00
Assert . AreEqual ( 4 , QueueData . Instance . ItemCount , "Queue should initially have 4 items" ) ;
// Invoke Queue -> Export to Zip dialog
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Queue... Menu" ) ;
2017-05-21 18:02:53 -07:00
testRunner . Delay ( . 2 ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( " Export to Zip Menu Item" ) ;
2017-05-21 18:02:53 -07:00
testRunner . Delay ( 2 ) ;
testRunner . Type ( exportZipPath ) ;
testRunner . Delay ( 2 ) ;
testRunner . Type ( "{Enter}" ) ;
2017-12-15 20:24:58 -08:00
testRunner . WaitFor ( ( ) = > File . Exists ( exportZipPath ) ) ;
2017-05-21 18:02:53 -07:00
Assert . IsTrue ( File . Exists ( exportZipPath ) , "Queue was exported to zip file, file exists on disk at expected path" ) ;
// Import the exported zip file and confirm the Queue Count increases by 3
2018-04-07 11:21:02 -07:00
testRunner . InvokeLibraryAddDialog ( ) ;
2017-05-21 18:02:53 -07:00
testRunner . Delay ( 1 ) ;
testRunner . Type ( exportZipPath ) ;
testRunner . Delay ( 1 ) ;
testRunner . Type ( "{Enter}" ) ;
2017-12-15 20:24:58 -08:00
testRunner . WaitFor ( ( ) = > QueueData . Instance . ItemCount = = 8 ) ;
2017-05-21 18:02:53 -07:00
Assert . AreEqual ( 8 , QueueData . Instance . ItemCount , "All parts imported successfully from exported zip" ) ;
testRunner . Delay ( . 3 ) ;
try
{
if ( File . Exists ( exportZipPath ) )
{
File . Delete ( exportZipPath ) ;
}
}
catch { }
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-10-30 23:05:38 -07:00
} , queueItemFolderToAdd : QueueTemplate . Three_Queue_Items ) ;
2017-05-21 18:02:53 -07:00
}
2017-11-15 13:27:12 -08:00
[Test, Ignore("Test now works as expected but product does not implement expected functionality")]
2017-05-21 18:02:53 -07:00
public async Task QueueExportIsDisabledIfEmpty ( )
{
2017-10-30 23:05:38 -07:00
await MatterControlUtilities . RunTest ( testRunner = >
2017-05-21 18:02:53 -07:00
{
2018-10-10 13:33:16 -07:00
testRunner . AddAndSelectPrinter ( ) ;
2017-05-21 18:02:53 -07:00
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Queue... Menu" ) ;
2017-05-21 18:02:53 -07:00
2017-10-18 09:24:46 -07:00
var exportButton = testRunner . GetWidgetByName ( " Export to Zip Menu Item" , out _ , 5 ) ;
2017-05-21 18:02:53 -07:00
Assert . IsNotNull ( exportButton , "Export button should exist" ) ;
Assert . IsTrue ( exportButton . Enabled , "Export button should be enabled" ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( " Remove All Menu Item" ) ;
2017-05-21 18:02:53 -07:00
testRunner . Delay ( 1 ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Queue... Menu" ) ;
2017-12-15 19:28:25 -08:00
testRunner . WaitFor ( ( ) = > ! exportButton . Enabled , 4 ) ;
2017-05-21 18:02:53 -07:00
Assert . IsFalse ( exportButton . Enabled , "Export button should be disabled after Queue Menu -> Remove All" ) ;
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-10-30 23:05:38 -07:00
} ) ;
2017-05-21 18:02:53 -07:00
}
2017-11-15 13:27:12 -08:00
[Test, Ignore("Not Finished")]
2017-05-21 18:02:53 -07:00
public async Task ClickCreatePartSheetButton ( )
{
2017-10-30 23:05:38 -07:00
await MatterControlUtilities . RunTest ( testRunner = >
2017-05-21 18:02:53 -07:00
{
2018-10-10 13:33:16 -07:00
testRunner . AddAndSelectPrinter ( ) ;
2017-05-21 18:02:53 -07:00
testRunner . ChangeToQueueContainer ( ) ;
bool queueEmpty = true ;
int queueItemCount = QueueData . Instance . ItemCount ;
if ( queueItemCount = = 3 )
{
queueEmpty = false ;
}
Assert . IsTrue ( queueEmpty = = false ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( "Queue... Menu" ) ;
2017-05-21 18:02:53 -07:00
testRunner . Delay ( . 2 ) ;
2017-06-14 09:56:51 -07:00
testRunner . ClickByName ( " Create Part Sheet Menu Item" ) ;
2017-05-21 18:02:53 -07:00
testRunner . Delay ( 2 ) ;
string pathToSavePartSheet = MatterControlUtilities . GetTestItemPath ( "CreatePartSheet" ) ;
string validatePartSheetPath = Path . Combine ( ".." , ".." , ".." , "TestData" , "QueueItems" , "CreatePartSheet.pdf" ) ;
testRunner . Type ( pathToSavePartSheet ) ;
testRunner . Delay ( 1 ) ;
testRunner . Type ( "{Enter}" ) ;
testRunner . Delay ( 1 ) ;
testRunner . Delay ( 5 ) ;
bool partSheetCreated = File . Exists ( validatePartSheetPath ) ;
testRunner . Delay ( 2 ) ;
Assert . IsTrue ( partSheetCreated = = true ) ;
if ( File . Exists ( validatePartSheetPath ) )
{
File . Delete ( validatePartSheetPath ) ;
}
2017-06-04 08:35:29 -07:00
return Task . CompletedTask ;
2017-10-30 23:05:38 -07:00
} , queueItemFolderToAdd : QueueTemplate . Three_Queue_Items ) ;
2017-05-21 18:02:53 -07:00
}
}
}