tweak mocha hierarchy so subtests actually run, add checks for proper export button...
[xtuple] / test / extensions / all / grid_box.js
1 /*jshint trailing:true, white:true, indent:2, strict:true, curly:true,
2   immed:true, eqeqeq:true, forin:true, latedef:true,
3   newcap:true, noarg:true, undef:true */
4 /*global XT:true, XM:true, XV:true, process:true, module:true, require:true,
5   describe:true, before:true, enyo:true, it:true, _:true, console:true */
6
7 (function () {
8   "use strict";
9
10   var zombieAuth = require("../../lib/zombie_auth"),
11     common = require("../../lib/common"),
12     smoke = require("../../lib/smoke"),
13     _ = require("underscore"),
14     assert = require("chai").assert;
15
16   describe('Workspace Grid Boxes', function () {
17     this.timeout(45 * 1000);
18
19     before(function (done) {
20       // setup for the date widget
21       var appLoaded = function () {
22         done();
23       };
24
25       zombieAuth.loadApp(appLoaded);
26     });
27
28     it('Test Grid Box Functionality', function () {
29       _.each(XV, function (value, key) {
30         var list,
31           kinds = ['SalesOrderList', 'QuoteList', 'InvoiceList', 'ReturnList', 'ProjectList'];
32         // lists with grid boxes; TODO: find candidates automatically
33         if (_.contains(kinds, key)) {
34           describe('Create Workspace for XV.' + key, function () {
35             it('Create a Workspace', function () {
36               list = "XV." + key;
37               smoke.navigateToNewWorkspace(XT.app, list, function (workspaceContainer) {
38                 var workspace = workspaceContainer.$.workspace,
39                     getExportButton = function (obj) {
40                       var result = null;
41                       if (_.isObject(obj.$)) {
42                         result = obj.$.exportButton ||
43                                  _.find(obj.$, getExportButton);
44                       }
45                       return result;
46                     };
47
48                 _.each(workspace.$, function (component) {
49                   if (XV.inheritsFrom(component, 'XV.GridBox')) {
50                     describe('Checking ' + component.name, function () {
51                       it('checks for the export button', function () {
52                         var exportButton = getExportButton(component);
53                         assert.ok(exportButton);
54                         // TODO: need to populate before we can export
55                         // assert.doesNotThrow(exportButton.doTap());
56                         // TODO: find the generated file & check contents
57                       });
58
59                       it('creates line items for ' + component, function () {
60                         var gridBox = component,
61                             exportButton = getExportButton(gridBox),
62                             gridRow,
63                             startingRows = gridBox.liveModels().length;
64
65                         assert.isFalse(exportButton.disabled,
66                                       'export enabled for fresh data');
67                         gridBox.newItem();
68                         gridRow = gridBox.$.editableGridRow;
69                         assert.equal(gridBox.liveModels().length, startingRows += 1);
70                         assert.isTrue(exportButton.disabled,
71                                        'export disabled for changed data');
72
73                         // Add a new row using the enter key
74                         gridRow.bubble("onkeyup", {keyCode: 13});
75                         assert.equal(gridBox.liveModels().length, startingRows += 1);
76                       });
77                     });
78                   }
79                 });
80               });
81             });
82           });
83         }
84       });
85     });
86   });
87 }());