unit test for delete item written
authorjulesstp <julianmcarlin@gmail.com>
Wed, 6 Aug 2014 16:10:13 +0000 (12:10 -0400)
committerjulesstp <julianmcarlin@gmail.com>
Wed, 6 Aug 2014 16:10:13 +0000 (12:10 -0400)
lib/enyo-x/source/views/child_workspace.js
test/extensions/sales/sales_order_workspace.js

index c014f03..fc11236 100644 (file)
@@ -152,7 +152,7 @@ trailing:true, white:true*/
       return this.inherited(arguments);
     },
     /**
-      Delete the model of the selected item and remove it from the list
+      Popup confirmation, Delete the model of the selected item and remove it from the list.
     */
     deleteItem: function () {
       var model = this.getCollection().at(this.getModelIndex()),
index dc8b261..ae7e752 100644 (file)
@@ -2,7 +2,8 @@
   immed:true, eqeqeq:true, forin:true, latedef:true,
   newcap:true, noarg:true, undef:true */
 /*global XT:true, XM:true, XV:true, describe:true, it:true, setTimeout:true,
-  console:true, before:true, after:true, module:true, require:true */
+  console:true, before:true, after:true, module:true, require:true, setInterval:true,
+  clearInterval:true */
 
 (function () {
   "use strict";
@@ -44,7 +45,7 @@
     };
 
   describe('Sales Order Workspace', function () {
-    this.timeout(20 * 1000);
+    this.timeout(30 * 1000);
 
     //
     // We'll want to have TTOYS, BTRUCK1, and WH1 onhand and ready for the test to work.
             });
         */
       });
+      it('deleting an item through SalesOrderLineWorkspace should remove it from the line item ' +
+        'list', function (done) {
+        var lineItemBox = workspace.$.salesOrderLineItemBox,
+          model = lineItemBox.value.models[0],
+          startModelLength = lineItemBox.liveModels().length,
+          moduleContainer = XT.app.$.postbooks;
+
+        /** Open the first model's salesOrderLineWorkspace...
+            Copied from gridBox buttonTapped function (expandGridRowButton) 
+        */
+        lineItemBox.doChildWorkspace({
+          workspace: lineItemBox.getWorkspace(),
+          collection: lineItemBox.getValue(),
+          index: lineItemBox.getValue().indexOf(model)
+        });
+
+        /** The line item's workspace model has been deleted (DESTROYED_CLEAN). 
+            Client is now in SalesOrderWorkspace.
+        */
+        var statusChanged = function () {
+          assert.notEqual(startModelLength, lineItemBox.liveModels().length);
+          done();
+        };
+        model.once("status:DESTROYED_CLEAN", statusChanged);
+
+        // Function to keep checking for notifyPopup showing and then tap yes. 
+        // This will fire right after the delete below.
+        var notifyPopupInterval = setInterval(function () {
+          if (!moduleContainer.$.notifyPopup.showing) { return; }
+
+          clearInterval(notifyPopupInterval);
+          moduleContainer.notifyTap(null, { originator: { name: "notifyYes" }});
+        }, 100);
+        // Delete the item in the workspace
+        moduleContainer.getActive().deleteItem();
+      });
+
       it('save, then delete order', function (done) {
         assert.isTrue((workspace.value.status === XM.Model.READY_DIRTY ||
           workspace.value.status === XM.Model.READY_NEW));