address code review comments and jshint the test
[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     describe('Test Grid Boxes', function () {
29       it('Test Grid Box Functionality', function () {
30
31         _.each(XV, function (value, key) {
32           var list,
33             kinds = ['SalesOrderList', 'QuoteList', 'InvoiceList', 'ReturnList', 'ProjectList'];
34           // lists with grid boxes; TODO: find candidates automatically
35           if (_.contains(kinds, key)) {
36
37             describe('Create Workspace for XV.' + key, function () {
38               it('Create a Workspace', function () {
39                 list = "XV." + key;
40                 smoke.navigateToNewWorkspace(XT.app, list, function (workspaceContainer) {
41                   var workspace = workspaceContainer.$.workspace;
42                   _.each(workspace.$, function (component) {
43                     if (XV.inheritsFrom(component, 'XV.GridBox')) {
44
45                       describe('Test creating line items for ' + component, function () {
46                         it('Create line items', function () {
47                           var gridBox = component, gridRow,
48                             startingRows = gridBox.liveModels().length;
49
50                           gridBox.newItem();
51                           gridRow = gridBox.$.editableGridRow;
52                           // verify that there is an increase in rows
53                           assert.equal(gridBox.liveModels().length, startingRows += 1);
54
55                           // Add a new row using the enter key
56                           gridRow.bubble("onkeyup", {keyCode: 13});
57                           // verify again that a row has been added
58                           assert.equal(gridBox.liveModels().length, startingRows += 1);
59                         });
60
61                         it('Check export', function () {
62                           var getExportButton = function (obj) {
63                             var result = null;
64                             if (_.isObject(obj.$)) {
65                               result = obj.$.exportButton ||
66                                        _.find(obj.$, getExportButton);
67                             }
68                             return result;
69                           };
70
71                           var gridBox = component,
72                               exportButton = getExportButton(gridBox);
73                           assert.ok(exportButton);
74                           // TODO: need to populate before we can export
75                           // assert.doesNotThrow(exportButton.doTap());
76                           // TODO: find the generated file & check contents
77                         });
78                       });
79                     }
80                   });
81                 });
82               });
83             });
84           }
85         });
86       });
87     });
88   });
89 }());