app: added tests for resource page workflow
[abstract.git] / app / test / aaUITestFrame.jsm
blob1690cb3f3f299ae8e0e591255117212886f5d204
1 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=javascript: */
2 /*
3 * Copyright (C) 2009 Sergey Yanovich <ynvich@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 Components.utils.import("resource:///modules/aaUITestUtils.jsm");
22 Components.utils.import("resource:///modules/aaTestVC.jsm");
24 var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
25   .getService(Components.interfaces.mozIJSSubScriptLoader);
26 loader.loadSubScript("resource:///modules/nsTestFrame.jsm");
28 /* Page specific class  */
30 example for actions on page
32     {
33         name: "open",
34         data: null //some data for special page 
35     },
36     {
37         name: "close",
38         data: null //some data for special page 
39     },
42 function JSTestPageModuleUI() {
43     var base = JSTestModule();
44     base.addOpenPage = null;
45     base.addClosePage = null;
46     base.parseAction = function(action) {
47         switch(action.name) {
48             case 'open':
49                 this.addOpenPage(action.data);
50                 return true;
51                 break;
52             case 'close':
53                 this.addClosePage(action.data);
54                 return true;
55                 break;
56         }
57         return false;
58     }
59     return base;
61 /* End page specific class */
64 example
66     cid: Components.ID(),
67     contractID: "",
68     name: "",
69     object: {
70         command: ''
71         checkF: null //function to check
72         checkInTest: true or false
73     }
76 function aaJSDoCommandTest(input) {
77     var base = new JSTest();
78     
79     base._name = input.name;
80     base._contractID = input.contractID;
81     base._CID = input.cid;
82     
83     base._command = input.object.command;
84     base._checkInTest = false;
85     if (input.object.checkInTest) {
86         base._checkInTest = input.object.checkInTest;
87     }
88     
89     base._test = function(runner) {
90         if (!this._command) 
91             this.addJSFailure(runner, "JSDoCommandTest::_test - command is not defined");
92         else {
93             runner.doCommand(this._command);
94             if (this._checkInTest && this._check) {
95                 this._check(runner);
96             }
97         }
98     }
99     base._check = function (runner) {
100       if (input.object.checkF)
101         return input.object.checkF(runner, this);
102     }
103     return base;
107 example
109     cid: Components.ID(),
110     contractID: "",
111     name: "",
112     object: {
113         command: '' || click: ''
114         checkF: null //function to check
115     }
118 function aaJSCommandOpenPageTest(input) {
119     var base = null;
120     if (input.object.command) {
121         base = aaJSDoCommandTest(input);
122         base.aaJSDoCommandTest_test = base._test;
123         base._test = function(runner) {
124             try {
125                 this.aaJSDoCommandTest_test(runner);
126             } catch(e) {
127                 this.addJSFailure(runner, "[aaJSCommandOpenPageTest] cann't do command. Exception: " + e);
128             }
129             runner.watchWindow = getFrame(runner).contentWindow;
130         }
131     } else if(input.object.click) {
132         base = new JSTest();
133         base._CID = input.cid;
134         base._contractID = input.contractID;
135         base._name = input.name;
136         
137         base._clickID = input.object.click;
138         
139         base._test = function(runner) {
140             sendOnClick(getElement(runner, this._clickID));
141             runner.watchWindow = getFrame(runner).contentWindow;
142         }
143         base._check = function (runner) {
144           if (input.object.checkF)
145             return input.object.checkF(runner, this);
146         }
147     }
148     return base;
152 example for:
153 1. open
155     cid: Components.ID(),
156     object: { 
157         command: "cmd_view_entity"
158     }
160 2. close
162     cid: Components.ID(),
163     object: { 
164         command: "cmd_page1_submit",
165         checkF: null //function for check result page
166     }
168 example for extended actions:
170     {
171         name: fill,
172         data: null //page specific data
173     },
176 function aaJSTestPageModule(pgName) {
177     var base = JSTestPageModuleUI();
178         
179     base._contractIDBase = "@aasii.org/abstract/test/";
180     base._pageName = pgName;
181     base._version = 1;
182     
183     base._contractID = base._contractIDBase + base._pageName + "/page;" + base._version;
184     base._name = "aaPage_" + base._pageName;
185     
186     base.generateContractID = function(inner_str) {
187         return this._contractIDBase + this._pageName + "/" + inner_str + ";" + this._version;
188     }
189     
190     base.JSTestPage_parseAction = base.parseAction;
191     base.parseAction = function(action) {
192         switch(action.name) {
193             case 'fill':
194                 this.addFillTest(action.data);
195                 return true;
196                 break;
197         }
198         return this.JSTestPage_parseAction(action);
199     }
200     base.addCommandPageOpenTest = function(data) {
201         this._add(aaJSCommandOpenPageTest(data));
202     }
203     base.addCommandTest = function(data) {
204         this._add(aaJSDoCommandTest(data));
205     }
206     base.addFillTest = null;
207     base.checkPage = function(runner, errorHandler) {
208       errorHandler.addJSFailure(runner, "aaJSTestPage.checkPage - not implemented");
209     }
210     base.addOpenPage = function(data) {
211         data.contractID = this.generateContractID("open" + this._parse_counter + "/" + data.object.command);
212         data.name = "aaPage_" + this._pageName + "_Open" + this._parse_counter + "_" + data.object.command;
213         data.object.checkF = this.checkPage;
214         this.addCommandPageOpenTest(data);
215     }
216     base.addClosePage = function(data) {
217         data.contractID = this.generateContractID("close" + this._parse_counter + "/" + data.object.command);
218         data.name = "aaPage_" + this._pageName + "_Close" + this._parse_counter + "_" + data.object.command;
219         this.addCommandPageOpenTest(data);
220     }
221     
222     //utils methods
223     base.annoElemAttrIsEqual = function(runner, topElem, elem, attr, val) {
224       return getAnnoElement(runner, topElem, elem).getAttribute(attr) == val;
225     }
226     base.elemAttrIsEqual = function(runner, elem, attr, val) {
227       return getElement(runner, elem).getAttribute(attr) == val;
228     }
229     //end utils methods
230     return base;
234 example for cids
236     name: 'page1_cids',
237     data: {
238         cid_new: Components.ID(),
239         cid_change: Components.ID(),
240         cid_cancel: Components.ID(),
241         cid_reset: Components.ID(),
242         cid_save: Components.ID()
243     }
245 example for commands actions
247     name: 'new_cmd',
248     data: { //user specific command
249       cid: Components.ID(),
250       checkF: function(runner)
251     }
254     name: 'change_cmd',
255     data: { //user specific command
256       cid: Components.ID(),
257       checkF: function(runner)
258     }
261     name: 'cancel_cmd',
262     data: { //user specific command
263       cid: Components.ID(),
264       checkF: function(runner)
265     }
268     name: 'reset_cmd',
269     data: { //user specific command
270       cid: Components.ID(),
271       checkF: function(runner)
272     }
275     name: 'save_cmd',
276     data: { //user specific command
277       cid: Components.ID(),
278       checkF: function(runner)
279     }
282 function aaJSTestPagePage1Module(pageName) {
283     var base = aaJSTestPageModule(pageName);
284     
285     base.aaJSTestPageModule_parseAction = base.parseAction;
286     
287     base.addedCommandCounts = 0;
288     
289     base.newCID = null;
290     base.changeCID = null;
291     base.cancelCID = null;
292     base.resetCID = null;
293     base.saveCID = null;
294     
295     base._NewCommand = 'cmd_page1_new';
296     base._ChangeCommand = 'cmd_page1_change';
297     base._CancelCommand = 'cmd_page1_cancel';
298     base._ResetCommand = 'cmd_page1_reset';
299     base._SaveCommand = 'cmd_page1_save';
300     
301     base._SubmitCommand = 'cmd_page1_submit';
302     base._DiscardCommand = 'cmd_page1_discard';
303     
304     base.parseAction = function(action) {
305         switch(action.name) {
306             case 'page1_cids':
307                 this.addCids(action.data);
308                 return true;
309                 break;
310             case 'new_cmd':
311                 this.addCommandNewTest(action.data);
312                 return true;
313                 break;
314             case 'change_cmd':
315                 this.addCommandChangeTest(action.data);
316                 return true;
317                 break;
318             case 'cancel_cmd':
319                 this.addCommandCancelTest(action.data);
320                 return true;
321                 break;
322             case 'reset_cmd':
323                 this.addCommandResetTest(action.data);
324                 return true;
325                 break;
326             case 'save_cmd':
327                 this.addCommandSaveTest(action.data);
328                 return true;
329                 break;
330         }
331         return this.aaJSTestPageModule_parseAction(action);
332     }
333     base.addCids = function(data) {
334         if (data.cid_new) this.newCID = data.cid_new;
335         if (data.cid_change) this.changeCID = data.cid_change;
336         if (data.cid_cancel) this.cancelCID = data.cid_cancel;
337         if (data.cid_reset) this.resetCID = data.cid_reset;
338         if (data.cid_save) this.saveCID = data.cid_save;
339     }    
340     base.addPage1CommandTest = function(cid, command, checkF) {
341         if (cid in this._map) {
342             this._repeat(this._map[cid]);
343         } else {
344             var data = {};
345             data.cid = cid;
346             this.addedCommandCounts += 1;
347             data.contractID = this.generateContractID("new_object/" + command + this.addedCommandCounts);
348             data.name = "aaPage_" + this._pageName + "_" + command + this.addedCommandCounts;
349             data.object = {};
350             data.object.command = command;
351             data.object.checkF = checkF;
352             data.object.checkInTest = true;
353             //add
354             this.addCommandTest(data);
355         }
356     }
357     
358     base.addCommandNewTest = function(data) {
359         if (!this.newCID) throw "cid for new button is not defined";
360         this.addPage1CommandTest(data ? data.cid : this.newCID, this._NewCommand, data ? data.checkF : this.checkNew);
361     }
362     base.addCommandChangeTest = function(data) {
363         if (!this.changeCID) throw "cid for change button is not defined";
364         this.addPage1CommandTest(data ? data.cid : this.changeCID, this._ChangeCommand, data ? data.checkF : this.checkChange);
365     }
366     base.addCommandCancelTest = function(data) {
367         if (!this.cancelCID) throw "cid for cancel button is not defined";
368         this.addPage1CommandTest(data ? data.cid : this.cancelCID, this._CancelCommand, data ? data.checkF : this.checkCancel);
369     }
370     base.addCommandResetTest = function(data) {
371         if (!this.resetCID) throw "cid for reset button is not defined";
372         this.addPage1CommandTest(data ? data.cid : this.resetCID, this._ResetCommand, data ? data.checkF : this.checkReset);
373     }
374     base.addCommandSaveTest = function(data) {
375         if (!this.saveCID) throw "cid for save button is not defined";
376         this.addPage1CommandTest(data ? data.cid : this.saveCID, this._SaveCommand, data ? data.checkF : this.checkSave);
377     }
379     base.checkPage1CrossPageButtons = function (runner, errorHandler, submitted) {
380       var elemEquals = base.annoElemAttrIsEqual(runner, "header", "header.discard", "collapsed", "true");
381       if ((submitted && elemEquals) || (!submitted && !elemEquals))
382         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPage1CrossPageButtons] header.discard button should not be visible");
383       elemEquals = base.annoElemAttrIsEqual(runner, "header", "header.submit", "collapsed", "true");
384       if ((submitted && elemEquals) || (!submitted && !elemEquals))
385         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPage1CrossPageButtons] header.submit button should not be visible");
386       elemEquals = base.elemAttrIsEqual(runner, "cmd_page1_discard", "disabled", "true");
387       if ((submitted && elemEquals) || (!submitted && !elemEquals))
388         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPage1CrossPageButtons] cmd_page1_discard command should be disabled");
389       elemEquals = base.elemAttrIsEqual(runner, "cmd_page1_submit", "disabled", "true");
390       if ((submitted && elemEquals) || (!submitted && !elemEquals))
391         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPage1CrossPageButtons] entity_submit command should be disabled");
392     }
393     base.checkPageDefaultManipulationState = function (runner, errorHandler) {
394       var tree = getElement(runner, "page1.tree");
395       if (!tree)
396         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] page1.tree not found");
397       if (base.annoElemAttrIsEqual(runner, "viewer", "page1.browse", "collapsed", "true"))
398         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] page1.browse toolbar should be visible");
399       if (!base.annoElemAttrIsEqual(runner, "viewer", "page1.edit", "collapsed", "true"))
400         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] page1.edit toolbar should not be visible");
401       if (!base.annoElemAttrIsEqual(runner, "viewer", "page1.save", "disabled", "true"))
402         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] page1.save button should be disabled");
404       if (base.elemAttrIsEqual(runner, "cmd_page1_new", "disabled", "true"))
405         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] cmd_page1_new command should not be disabled");
406       if (base.elemAttrIsEqual(runner, "cmd_page1_cancel", "disabled", "true"))
407         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] cmd_page1_cancel command should not be disabled");
408       if (!base.elemAttrIsEqual(runner, "cmd_page1_reset", "disabled", "true"))
409         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] cmd_page1_new command should be disabled");
410       if (!base.elemAttrIsEqual(runner, "cmd_page1_save", "disabled", "true"))
411         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] cmd_page1_save command should be disabled");
414       if ((tree && tree.view.selection.currentIndex < 0) || !tree) {
415         if (!base.annoElemAttrIsEqual(runner, "viewer", "page1.change", "disabled", "true"))
416           errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] page1.change button should be disabled");
417         if (!base.elemAttrIsEqual(runner, "cmd_page1_change", "disabled", "true"))
418           errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] cmd_page1_change command should be disabled");
419       } else if (tree && tree.view.selection.currentIndex >= 0) {
420         if (base.annoElemAttrIsEqual(runner, "viewer", "page1.change", "disabled", "true"))
421           errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] page1.change button should not be disabled");
422         if (base.elemAttrIsEqual(runner, "cmd_page1_change", "disabled", "true"))
423           errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageDefaultManipulationState] cmd_page1_change command should not be disabled");
424       }
425     }
426     base.checkPageNewManipulationState = function (runner, errorHandler) {
427       if (!base.annoElemAttrIsEqual(runner, "viewer", "page1.browse", "collapsed", "true"))
428         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageNewManipulationState] page1.browse toolbar should not be visible");
429       if (!base.annoElemAttrIsEqual(runner, "viewer", "page1.change", "disabled", "true"))
430         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageNewManipulationState] page1.change button should be disabled");
431       if (base.annoElemAttrIsEqual(runner, "viewer", "page1.edit", "collapsed", "true"))
432         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageNewManipulationState] page1.edit toolbar should be visible");
433       if (!base.annoElemAttrIsEqual(runner, "viewer", "page1.save", "disabled", "true"))
434         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageNewManipulationState] page1.save button should be disabled");
435       
436       if (!base.elemAttrIsEqual(runner, "cmd_page1_new", "disabled", "true"))
437         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageNewManipulationState] cmd_page1_new command should be disabled");
438       if (!base.elemAttrIsEqual(runner, "cmd_page1_change", "disabled", "true"))
439         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageNewManipulationState] cmd_page1_change command should be disabled");
440       if (base.elemAttrIsEqual(runner, "cmd_page1_cancel", "disabled", "true"))
441         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageNewManipulationState] cmd_page1_cancel command should not be disabled");
442       if (base.elemAttrIsEqual(runner, "cmd_page1_reset", "disabled", "true"))
443         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageNewManipulationState] cmd_page1_new command should not be disabled");
444       if (!base.elemAttrIsEqual(runner, "cmd_page1_save", "disabled", "true"))
445         errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageNewManipulationState] cmd_page1_save command should be disabled");
446     }
447     base.checkPage_Page1Buttons = function (runner, errorHandler) {
448       base.checkPage1CrossPageButtons(runner, errorHandler, false);
449       base.checkPageDefaultManipulationState(runner, errorHandler);
450     }
451     base.checkPage = function (runner, errorHandler) {
452       base.checkPage_Page1Buttons(runner, errorHandler);
453       base.checkPageSpecificData(runner, errorHandler, "default");
454     }
455     base.checkNew = function (runner, errorHandler) {
456       base.checkPageNewManipulationState(runner, errorHandler);
457       base.checkPageSpecificData(runner, errorHandler, "new");
458     }
459     base.checkChange = function (runner, errorHandler) {
460       base.checkPageNewManipulationState(runner, errorHandler);
461       base.checkPageSpecificData(runner, errorHandler, "change");
462     }
463     base.checkCancel = function (runner, errorHandler) {
464       base.checkPageDefaultManipulationState(runner, errorHandler);
465       base.checkPageSpecificData(runner, errorHandler, "cancel");
466     }
467     base.checkReset = function (runner, errorHandler) {
468       base.checkPageNewManipulationState(runner, errorHandler);
469       base.checkPageSpecificData(runner, errorHandler, "reset");
470     }
471     base.checkSave = function (runner, errorHandler) {
472       base.checkPageDefaultManipulationState(runner, errorHandler);
473       base.checkPageSpecificData(runner, errorHandler, "save");
474     }
475     //state:
476     //  'default' - state of page when opened
477     //  'new' - new button pressed
478     //  'change' - change button pressed
479     //  'save' - save button pressed
480     //  'cancel' - cancel button pressed
481     //  'reset' - reset button pressed
482     base.checkPageSpecificData = function (runner, errorHandler, state) {
483       errorHandler.addJSFailure(runner, "[aaJSTestPagePage1Module.checkPageSpecificData] do not implemented");
484     }
485     return base;
489 input data
491     cid: Components.ID(),
492     contractID: '',
493     name: '',
494     object: //specific object
495     rowFunction: function(view, tree, i, object)
496     checkF: if necessary
499 function aaJSSelectObjectTest(input) {
500     var base = new JSTest();
501     base._CID = input.cid;
502     base._contractID = input.contractID;
503     base._name = input.name;
504     
505     base._checkFunction = input.rowFunction;
506     base._object = input.object;
507     
508     base._test = function(runner) {
509         var found = false;
510         if (this._checkFunction) {
511             var tree = getElement(runner, "page1.tree");
512             var view = tree.view;
513             for (var i = 0; i < tree.view.rowCount; ++ i) {
514                 if (this._checkFunction(view, tree, i, this._object)) {
515                     tree.view.selection.select(i);
516                     found = true;
517                 }
518             }
519         } else {
520             this.addJSFailure(runner, "[aaJSSelectObjectTest] rowFunction is not defined");
521         }
522         if (!found) {
523             this.addJSFailure(runner, "[aaJSSelectObjectTest] cann't find appropriate row");
524         }
525         if (this._check) {
526           this._check(runner);
527         }
528     }
530     base._check = function (runner) {
531       if (input.checkF) {
532         return input.checkF(runner, this);
533       }
534     }
535     return base;
539 example for select
541     name: 'select',
542     data: {
543         cid: Components.ID(),
544         object: {
545             //some child class specific object
546         }
547     }
549 example for extended open command
551   cid: Components.ID(),
552   selectable: true or false, if not exist selectable will be false
553   object: specific object for aaJSDoCommandOpenPage
556 extended state for checkPageSpecificData
557   state: 'selected'
559 function aaJSTestSelectablePagePage1Module(pageName)
561     var base = aaJSTestPagePage1Module(pageName);
562     base._IsPageForSelect = false;
563     
564     base.checkAfterSelect = function (runner, errorHandler) {
565       base.checkPageDefaultManipulationState(runner, errorHandler);
566       base.checkPageSpecificData(runner, errorHandler, "selected");
567     }
568     base.selectCheckRow = function(view, tree, i, object) {
569       return false;
570     }
571     //override base function
572     base.checkPage_Page1Buttons = function (runner, errorHandler) {
573       base.checkPage1CrossPageButtons(runner, errorHandler, base._IsPageForSelect);
574       base.checkPageDefaultManipulationState(runner, errorHandler);
575     }
576     //override base function
577     
578     base.aaJSTestPagePage1Module_parseAction = base.parseAction;
579     base.aaJSTestPagePage1Module_addOpenPage = base.addOpenPage;
580     
581     base.parseAction = function(action) {
582         switch(action.name) {
583             case 'select':
584                 this.addSelectTest(action.data);
585                 return true;
586                 break;
587         }
588         return this.aaJSTestPagePage1Module_parseAction(action);
589     }
590     base.addSelectTest = function(data) {
591         data.contractID = this.generateContractID("select_object" + this._parse_counter);
592         data.name = "aaPageSelectObject" + this._parse_counter;
593         data.rowFunction = this.selectCheckRow;
594         data.checkF = this.checkAfterSelect;
595         this._add(aaJSSelectObjectTest(data));
596     }
597     base.addOpenPage = function(data) {
598         if (data.selectable) {
599           this._IsPageForSelect = data.selectable;
600         }
601         this.aaJSTestPagePage1Module_addOpenPage(data);
602     }
603     return base;
607 example for fill
609     name: "test name",
610     contractID: "contract id",
611     cid: Components.ID(""),
612     object: {
613         tag: 'asdsad'
614     }
617 function aaJSTestEntity(input) {
618     var me = new JSTest();
619     me._name = input.name;
620     me._contractID = input.contractID;
621     me._CID = input.cid;
622     
623     me._tagID = "entity.tag";
624     me._tagValue = input.object.tag;
625     
626     me._test = function(runner) {
627         //get element
628         var box = getElement(runner, this._tagID);
629         //set entity tag
630         box.value = this._tagValue;
631         sendOnInput(box);
632         if (this._check) {
633             this._check(runner);
634         }
635     }
636     me._check = function(runner) {
637         var box = getElement(runner, this._tagID);
638         //check tag entity
639         if (this._tagValue != box.value) {
640             this.addJSFailure(runner, "[Entity page]: tag value is not equal tag textbox value");   
641         }
642     }
643     return me;
647 example for fill
649     cid: Components.ID(""),
650     object: {
651         tag: 'asdsad'
652     }
654 example for select
656     cid: Components.ID(""),
657     object: {
658         tag: 'asdsad'
659     }
662 //add cid manually
663 function aaJSTestPageEntityModule(testNumber) {
664     var base = aaJSTestSelectablePagePage1Module('entity' + testNumber);
665     base.addFillTest = function(data) {
666         //add call new
667         this.addCommandNewTest();
668         //add fill
669         data.contractID = this.generateContractID("create_entity" + this._parse_counter + "_" + data.object.tag);
670         data.name = "aaEntityCreate_" + data.object.tag;
671         this._add(aaJSTestEntity(data));
672         //add call save
673         this.addCommandSaveTest();
674     }
675     base.checkPageSpecificData = function(runner, errorHandler, state) {
676         var tagBox = getElement(runner, 'entity.tag');
677         if (!tagBox)
678           errorHandler.addJSFailure(runner, "[aaJSTestPageEntityModule.checkPageSpecificData] element entity.tag is not found");
679         switch(state) {
680           case 'selected':
681             //check for tagBox value state must be added
682             var tree = getElement(runner, "page1.tree");
683             var view = tree.view;
684             if (tree.view.selection.currentIndex > -1) {
685               if (tree.view.getCellText(tree.view.selection.currentIndex, tree.columns[0]) != tagBox.value) {
686                 errorHandler.addJSFailure(runner, "[aaJSTestPageEntityModule.checkPageSpecificData] selected element is not sync with tagBox.");
687               }
688             } else {
689               errorHandler.addJSFailure(runner, "[aaJSTestPageEntityModule.checkPageSpecificData] currentIndex less then 0.");
690             }
691           case 'cancel':
692           case 'save':
693           case 'default':
694             if (tagBox.getAttribute("readonly") != 'true')
695               errorHandler.addJSFailure(runner, "[aaJSTestPageEntityModule.checkPageSpecificData] element entity.tag is not readonly");
696             break;
697           case 'new':
698             if (tagBox.getAttribute("focused") != 'true')
699               errorHandler.addJSFailure(runner, "[aaJSTestPageEntityModule.checkPageSpecificData] element entity.tag is not focused");
700           case 'reset':
701           case 'change':
702             if (tagBox.getAttribute("readonly") == 'true')
703               errorHandler.addJSFailure(runner, "[aaJSTestPageEntityModule.checkPageSpecificData] element entity.tag is readonly");
704             break;
705         }
706     }
707     base.selectCheckRow = function(view, tree, i, object) {
708         return view.getCellText(i, tree.columns[0]) == object.tag;
709     }
710     return base;
714 example for fill
716     name: "test name",
717     contractID: "contract id",
718     cid: Components.ID(""),
719     object: {
720         isMoney: true or false
721         tag: 'asdsad'
722         code: //if isMoney set to true, that field will be used for set money code;
723     }
726 function aaJSTestNewResource(input) {
727     var me = new JSTest();
728     me._name = input.name;
729     me._contractID = input.contractID;
730     me._CID = input.cid;
731     
732     me.isMoneyID = 'resource.isMoney';
733     me.tagID = 'resource.tag';
734     me.codeID = 'resource.code';
735     
736     me.isMoney = false;
737     me.code = null;
738     me.tag = input.object.tag;
739     if (input.object.isMoney) {
740         me.isMoney = input.object.isMoney;
741         me.code = input.object.code;
742     }
743     
744     me._test = function(runner) {
745         var _tag = getElement(runner, this.tagID);
746         if (!_tag) this.addJSFailure(runner, "[aaJSTestNewResource] tag element not found");
747         else {
748             //if is money
749             if (this.isMoney == true) {
750                 var _isMoney = getElement(runner, this.isMoneyID);
751                 var _code = getElement(runner, this.codeID);
752                 if (!_isMoney) this.addJSFailure(runner, "[aaJSTestNewResource] isMoney element not found");
753                 else {
754                     _isMoney.checked = true;
755                     _isMoney.doCommand();
756                     if (!_code) this.addJSFailure(runner, "[aaJSTestNewResource] code element not found");
757                     else if(_code.getAttribute('readonly') == 'true') {
758                         this.addJSFailure(runner, "[aaJSTestNewResource] code element is readonly");
759                     }
760                     else {
761                         _code.value = this.code;
762                         sendOnInput(_code);
763                     }
764                 }
765             }
766             _tag.value = this.tag;
767             sendOnInput(_tag);
768         }
769         if (this._check) {
770             this._check(runner);
771         }
772     }
773     me._check = function(runner) {
774         var _tag = getElement(runner, this.tagID);
775         if (!_tag) this.addJSFailure(runner, "[aaJSTestNewResource] tag element not found");
776         else {
777             if (_tag.value != this.tag) {
778                 this.addJSFailure(runner, "[aaJSTestNewResource] tag element is not equal: " + this.tag);
779             }
780             //if is money
781             if (this.isMoney == true) {
782                 var _isMoney = getElement(runner, this.isMoneyID);
783                 var _code = getElement(runner, this.codeID);
784                 if (!_isMoney) this.addJSFailure(runner, "[aaJSTestNewResource] isMoney element not found");
785                 else {
786                     if (_isMoney.checked != true) {
787                         this.addJSFailure(runner, "[aaJSTestNewResource] isMoney element is not checked");
788                     }
789                     if (!_code) this.addJSFailure(runner, "[aaJSTestNewResource] code element not found");
790                     else if(_code.getAttribute('readonly') == 'true') {
791                         this.addJSFailure(runner, "[aaJSTestNewResource] code element is readonly");
792                     }
793                     else if(_code.value != this.code){
794                         this.addJSFailure(runner, "[aaJSTestNewResource] code element is not equal: " + this.code);
795                     }
796                 }
797             }
798         }
799     }
800     return me;
804 example for fill
806     cid: Components.ID(""),
807     object: {
808         isMoney: true or false
809         tag: 'asdsad'
810         code: //if isMoney set to true, that field will be used for set money code;
811     }
813 example for select
815     cid: Components.ID(""),
816     object: {
817         isMoney: true or false
818         tag: 'asdsad'
819     }
822 //add cid manually
823 function aaJSTestPageResourceModule(testNumber) {
824     var base = aaJSTestSelectablePagePage1Module('resource' + testNumber);
825     base.addFillTest = function(data) {
826       //add call new
827       this.addCommandNewTest();
828       //add fill
829       data.contractID = this.generateContractID("create_resource" + this._parse_counter + "_" + data.object.tag);
830       data.name = "aaResourceCreate" + this._parse_counter + "_" + data.object.tag;
831       this._add(aaJSTestNewResource(data));
832       //add call save
833       this.addCommandSaveTest();
834     }
835     base.checkPageSpecificData = function (runner, errorHandler, state) {
836       var _tag = getElement(runner, "resource.tag");
837       var _isMoney = getElement(runner, "resource.isMoney");
838       var _code = getElement(runner, "resource.code");
839       var _tree = getElement(runner, "page1.tree");
840       if (!_tag) errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] tag element not found");
841       if (!_isMoney) errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] isMoney element not found");
842       if (!_code) errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] code element not found");
843       if (!_tree) errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] tree element not found");
844       switch (state) {
845         case 'selected':
846           if (_tree.view.selection.currentIndex > -1) {
847             var _fIsMoney = _tree.view.getCellText(_tree.view.selection.currentIndex, _tree.columns[0]) == 'money';
848             if (_fIsMoney) {
849               if (_isMoney.checked != true) {
850                 errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] isMoney element must be checked");
851               }
852             } else {
853               if (_isMoney.checked == true) {
854                 errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] isMoney element must not be checked");
855               }
856             }
857             if (_tree.view.getCellText(_tree.view.selection.currentIndex, _tree.columns[1]) != _tag.value) {
858               errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] tag element not synced");
859             }
860           } else {
861             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] element is not selected");
862           }
863           if (_tag.getAttribute('readonly') != 'true') {
864             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] tag element is not readonly");
865           }
866           if (_code.getAttribute('readonly') != 'true') {
867             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] code element is not readonly");
868           }
869           break;
870         case 'default':
871           if (_isMoney.checked == true) {
872             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] isMoney element is checked");
873           }
874         case 'cancel':
875         case 'save':
876           if (_tag.getAttribute('readonly') != 'true') {
877             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] tag element is not readonly");
878           }
879           if (_code.getAttribute('readonly') != 'true') {
880             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] code element is not readonly");
881           }
882           break;
883         case 'new':
884           if (_isMoney.checked == true) {
885             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] isMoney element is checked");
886           }
887           if (_code.getAttribute('readonly') == 'true') {
888             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] code element is readonly");
889           }
890         case 'reset':
891           if (_tag.getAttribute('readonly') == 'true') {
892             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] tag element is readonly");
893           }
894           break;
895         case 'change':
896           if (_tag.getAttribute('readonly') == 'true') {
897             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] tag element is readonly");
898           }
899           if (_code.getAttribute('readonly') != 'true') {
900             errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] code element is not readonly");
901           }
902           if (_tree.view.selection.currentIndex > -1) {
903             var _fIsMoney = _tree.view.getCellText(_tree.view.selection.currentIndex, _tree.columns[0]) == 'money';
904             if (_fIsMoney) {
905               if (_isMoney.checked != true) {
906                 errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] isMoney element must be checked");
907               }
908             } else {
909               if (_isMoney.checked == true) {
910                 errorHandler.addJSFailure(runner, "[aaJSTestPageResourceModule.checkPageSpecificData] isMoney element must not be checked");
911               }
912             }
913           }
914           break;
915       }
916     }
917     base.selectCheckRow = function(view, tree, i, object) {
918         var type = 'asset';
919         if (object.isMoney) {
920             type = 'money';
921         }
922         return view.getCellText(i, tree.columns[0]) == type &&
923                 view.getCellText(i, tree.columns[1]) == object.tag;
924     }
925     return base;
929 example for fill
931     name: "test name",
932     contractID: "contract id",
933     cid: Components.ID(""),
934     object: {
935         isLight: false,
936         tag: 'asdsad',
937         direction: 0(-->) or 1(<--), 
938         rate: 1.0, 
939         isOffBalance: true or false
940     }
942 second version
944     cid: Components.ID(""),
945     object: {
946         isLight: true,
947         tag: 'asdsad',
948         direction: 0(-->) or 1(<--), 
949         rate: 1.0, 
950         isOffBalance: true or false,
951         entity: {
952             tag: ''
953         },
954         giveRes: {
955             isMoney: true or false,
956             tag: ''
957         },
958         takeRes: {
959             isMoney: true or false,
960             tag: ''
961         }
962     }
965 function aaJSTestNewFlow(input) {
966     var me = new JSTest();
967     me._name = input.name;
968     me._contractID = input.contractID;
969     me._CID = input.cid;
970     
971     me._tagID = 'flow.tag';
972     me._rateID = 'flow.rate';
973     me._directionID = 'rate.direction';
974     me._isOffBalanceID = 'flow.isoffbalance';
975     
976     me._tagValue = input.object.tag;
977     me._rateValue = input.object.rate;
978     me._directionValue = input.object.direction;
979     me._isOffBalanceValue = input.object.isOffBalance;
980     me._isLight = false;
981     if (input.object.isLight) {
982         me._isLight = input.object.isLight;
983     }
984     if (me._isLight == true) {
985         me._entity = input.object.entity;
986         me._give = input.object.giveRes;
987         me._take = input.object.takeRes;
988     }
989     
990     me._test = function(runner) {
991         var tagInput = getElement(runner, this._tagID);
992         var rateInput = getElement(runner, this._rateID);
993         var flowIsOffBalance = getElement(runner, this._isOffBalanceID);
994         //fill input values
995         tagInput.value = this._tagValue;
996         sendOnInput(tagInput);
997         
998         getElement(runner, this._directionID).selectedIndex = this._directionValue;
999         
1000         rateInput.value = this._rateValue;
1001         sendOnInput(rateInput);
1002         
1003         //set is off balance
1004         if (true == this._isOffBalanceValue) {
1005             sendOnClick(flowIsOffBalance);
1006         }
1007         
1008         //if is light
1009         if (this._isLight) {
1010             this.addEntity(runner);
1011             this.addGiveResource(runner);
1012             this.addTakeResource(runner);
1013         }
1014         if (this._check) {
1015             this._check(runner);
1016         }
1017     }
1018     me.addEntity = function(runner) {
1019         var loader = Components.classes["@aasii.org/storage/load-entity;1"].createInstance(nsCI.aaISqlRequest);
1020         var entities = getFrame(runner).docShell.QueryInterface(nsCI.nsIWebNavigation).sessionHistory.load(loader);
1021         var enumerator = entities.enumerate();
1022         while(enumerator.hasMoreElements()) {
1023             var entity = enumerator.getNext().QueryInterface(nsCI.aaIEntity);
1024             if (entity.tag == this._entity.tag) {
1025                 var page = getFrame(runner).contentWindow.wrappedJSObject.view;
1026                 page.buffer.QueryInterface(nsCI.aaIFlow).entity =
1027                         entity.QueryInterface(nsCI.aaIEntity);
1028                 break;
1029             }
1030         }
1031     }
1032     me.addGiveResource = function(runner) {
1033         var loader = Components.classes["@aasii.org/storage/load-resource;1"].createInstance(nsCI.aaISqlRequest);
1034         var resources = getFrame(runner).docShell.QueryInterface(nsCI.nsIWebNavigation).sessionHistory.load(loader);
1035         var enumerator = resources.enumerate();
1036         while(enumerator.hasMoreElements()) {
1037             var resource = enumerator.getNext().QueryInterface(nsCI.aaIResource);
1038             if (resource.tag == this._give.tag) {
1039                 if ((this._give.isMoney && resource.type == nsCI.aaIResource.TYPE_MONEY) || 
1040                     (!this._give.isMoney && resource.type == nsCI.aaIResource.TYPE_ASSET)) {
1041                     var page = getFrame(runner).contentWindow.wrappedJSObject.view;
1042                     page.buffer.QueryInterface(nsCI.aaIFlow).giveResource =
1043                             resource.QueryInterface(nsCI.aaIResource);
1044                     break;
1045                 }
1046             }
1047         }
1048     }
1049     me.addTakeResource = function(runner) {
1050         var loader = Components.classes["@aasii.org/storage/load-resource;1"].createInstance(nsCI.aaISqlRequest);
1051         var resources = getFrame(runner).docShell.QueryInterface(nsCI.nsIWebNavigation).sessionHistory.load(loader);
1052         var enumerator = resources.enumerate();
1053         while(enumerator.hasMoreElements()) {
1054             var resource = enumerator.getNext().QueryInterface(nsCI.aaIResource);
1055             if (resource.tag == this._take.tag) {
1056                 if ((this._take.isMoney && resource.type == nsCI.aaIResource.TYPE_MONEY) || 
1057                     (!this._take.isMoney && resource.type == nsCI.aaIResource.TYPE_ASSET)) {
1058                     var page = getFrame(runner).contentWindow.wrappedJSObject.view;
1059                     page.buffer.QueryInterface(nsCI.aaIFlow).takeResource =
1060                             resource.QueryInterface(nsCI.aaIResource);
1061                     break;
1062                 }
1063             }
1064         }
1065     }
1066     me._check = function(runner) {
1067         var tagInput = getElement(runner, this._tagID);
1068         if (!tagInput) {
1069             this.addJSFailure(runner, "[aaJSTestNewFlow._check] cann't find element " + this._tagID);
1070         }
1071         if (tagInput.value != this._tagValue) {
1072             this.addJSFailure(runner, "[aaJSTestNewFlow._check] element " + this._tagID + " is not equal to " + this._tagValue);
1073         }
1074         var rateInput = getElement(runner, this._rateID);
1075         if (!rateInput) {
1076             this.addJSFailure(runner, "[aaJSTestNewFlow._check] cann't find element " + this._rateID);
1077         }
1078         if (rateInput.value != this._rateValue) {
1079             this.addJSFailure(runner, "[aaJSTestNewFlow._check] element " + this._rateID + " is not equal to " + this._rateValue);
1080         }
1081         var flowIsOffBalance = getElement(runner, this._isOffBalanceID);
1082         if (!flowIsOffBalance) {
1083             this.addJSFailure(runner, "[aaJSTestNewFlow._check] cann't find element " + this._isOffBalanceID);
1084         }
1085         if (flowIsOffBalance.checked != this._isOffBalanceValue) {
1086             this.addJSFailure(runner, "[aaJSTestNewFlow._check] element " + this._isOffBalanceID + " is not equal to " + this._isOffBalanceValue);
1087         }
1088         //getElement(runner, this._directionID).selectedIndex = this._directionValue;
1089         if (!getElement(runner, this._directionID)) {
1090             this.addJSFailure(runner, "[aaJSTestNewFlow._check] cann't find element " + this._directionID);
1091         }
1092         if (getElement(runner, this._directionID).selectedIndex != this._directionValue) {
1093             this.addJSFailure(runner, "[aaJSTestNewFlow._check] element " + this._directionID + " is not equal to " + this._directionValue);
1094         }
1095     }
1096     return me;
1100 example for fill
1102 first version
1104     cid: Components.ID(""),
1105     object: {
1106         isLight: false,
1107         tag: 'asdsad',
1108         direction: 0(-->) or 1(<--), 
1109         rate: 1.0, 
1110         isOffBalance: true or false,
1111         entity: {
1112             page: {
1113                 cid: Components.ID(),
1114                 open_cid: Components.ID(),
1115                 close_cid: Components.ID()
1116             }
1117             flow: [
1118                 {//specific flow for entity page
1119                 }
1120             ]
1121         },
1122         giveRes: {
1123             page: {
1124                 cid: Components.ID(),
1125                 open_cid: Components.ID(),
1126                 close_cid: Components.ID()
1127             }
1128             flow: [
1129                 {//specific flow for resource page
1130                 }
1131             ]
1132         },
1133         takeRes: {
1134             page: {
1135                 cid: Components.ID(),
1136                 open_cid: Components.ID(),
1137                 close_cid: Components.ID()
1138             }
1139             flow: [
1140                 {//specific flow for resource page
1141                 }
1142             ]
1143         }
1144     }
1146 second version
1148     cid: Components.ID(""),
1149     object: {
1150         isLight: true,
1151         tag: 'asdsad',
1152         direction: 0(-->) or 1(<--), 
1153         rate: 1.0, 
1154         isOffBalance: true or false,
1155         entity: {
1156             tag: ''
1157         },
1158         giveRes: {
1159             isMoney: true or false,
1160             tag: ''
1161         },
1162         takeRes: {
1163             isMoney: true or false,
1164             tag: ''
1165         }
1166     }
1168 example for select
1170     cid: Components.ID(""),
1171     object: {
1172         tag: 'asdsad'
1173         entity: 'haha' //entity tag
1174     }
1177 //add cid manually
1178 function aaJSTestPageFlowModule(testNumber) {
1179     var base = aaJSTestSelectablePagePage1Module('resource' + testNumber);
1180     base.addFillTest = function(data) {
1181         //add call new
1182         this.addCommandNewTest();
1183         //add fill
1184         data.contractID = this.generateContractID("create_flow" + this._parse_counter + "_" + data.object.tag);
1185         data.name = "aaFlowCreate" + this._parse_counter + "_" + data.object.tag;
1186         this._add(aaJSTestNewFlow(data));
1187         //add entity select
1188         if (!data.object.isLight) {
1189             this.addSelectEntity(data.object.entity);
1190             this.addSelectGiveResource(data.object.giveRes);
1191             this.addSelectTakeResource(data.object.takeRes, data);
1192         }
1193         if (data.object.rules) {
1194             this.addFillRules(data.object.rules);
1195         }
1196         //add call save
1197         this.addCommandSaveTest();
1198     }
1199     base.addSelectEntity = function(entity) {        
1200         var tmp = new Array();
1201         tmp[0] = {
1202             name: 'open',
1203             data: {
1204                 cid: entity.page.open_cid,
1205                 object: {
1206                     command: 'cmd_flow_entity'
1207                 }
1208             }
1209         };
1210         var lng = tmp.length;
1211         for(var i = 0; i < entity.flow.length; i++) {
1212             tmp[lng++] = entity.flow[i];
1213         }
1214         var _entityModule = aaJSTestPageEntityModule(this._tests.length);
1215         _entityModule.createTestsFlow(tmp);
1216         for(var i = 0; i < _entityModule._tests.length; i++) {
1217             this._add(_entityModule._tests[i]);
1218         }
1219         ////////////////////////////////////////////////////
1220     }
1221     base.addSelectGiveResource = function(giveRes) {
1222         var tmp = new Array();
1223         tmp[0] = {
1224             name: 'open',
1225             data: {
1226                 cid: giveRes.page.open_cid,
1227                 object: {
1228                     command: 'cmd_flow_give'
1229                 }
1230             }
1231         };
1232         var lng = tmp.length;
1233         for(var i = 0; i < giveRes.flow.length; i++) {
1234             tmp[lng++] = giveRes.flow[i];
1235         }
1236         var _resource = aaJSTestPageResourceModule(this._tests.length);
1237         _resource.createTestsFlow(tmp);
1238         for(var i = 0; i < _resource._tests.length; i++) {
1239             this._add(_resource._tests[i]);
1240         }
1241     }
1242     base.addSelectTakeResource = function(takeRes, data) {
1243         var tmp = new Array();
1244         tmp[0] = {
1245             name: 'open',
1246             data: {
1247                 cid: takeRes.page.open_cid,
1248                 object: {
1249                     command: 'cmd_flow_take'
1250                 }
1251             }
1252         };
1253         var lng = tmp.length;
1254         for(var i = 0; i < takeRes.flow.length; i++) {
1255             tmp[lng++] = takeRes.flow[i];
1256         }
1257         var _resource = aaJSTestPageResourceModule(this._tests.length);
1258         _resource.createTestsFlow(tmp);
1259         for(var i = 0; i < _resource._tests.length; i++) {
1260             this._add(_resource._tests[i]);
1261         }
1262     }
1263     base.addFillRules = function(rules) {
1264         var tmp = new Array();
1265         tmp[0] = {
1266             name: 'open',
1267             data: {
1268                 cid: rules.page.open_cid,
1269                 object: {
1270                     click: 'flow.rules'
1271                 }
1272             }
1273         };
1274         var lng = tmp.length;
1275         for(var i = 0; i < rules.flow.length; i++) {
1276             tmp[lng++] = rules.flow[i];
1277         }
1278         var _rule = aaJSTestPageRuleModule(this._tests.length);
1279         _rule.createTestsFlow(tmp);
1280         for(var i = 0; i < _rule._tests.length; i++) {
1281             this._add(_rule._tests[i]);
1282         }
1283     }
1284     base.checkPage = function(runner) {
1285         var tagInput = getElement(runner, "flow.tag");
1286         if (!tagInput) {
1287             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element flow.tag");
1288         }
1289         if (tagInput.getAttribute("readonly") != 'true') {
1290             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element flow.tag is not readonly");
1291         }
1292         var rateInput = getElement(runner, "flow.rate");
1293         if (!rateInput) {
1294             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element flow.rate");
1295         }
1296         if (rateInput.getAttribute("readonly") != 'true') {
1297             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element flow.rate is not readonly");
1298         }
1299         var flowIsOffBalance = getElement(runner, "flow.isoffbalance");
1300         if (!flowIsOffBalance) {
1301             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element flow.isoffbalance");
1302         }
1303         if (flowIsOffBalance.getAttribute("readonly") != 'true') {
1304             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element flow.isoffbalance is not readonly");
1305         }
1306         //getElement(runner, this._directionID).selectedIndex = this._directionValue;
1307         if (!getElement(runner, "rate.direction")) {
1308             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element rate.direction");
1309         }
1310         if (getElement(runner, "rate.direction").getAttribute("readonly") != 'true') {
1311             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element rate.direction is not readonly");
1312         }
1313         if (!getElement(runner, "entity.tag")) {
1314             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element entity.tag");
1315         }
1316         if (getElement(runner, "entity.tag").getAttribute("readonly") != 'true') {
1317             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element entity.tag is not readonly");
1318         }
1319         if (!getElement(runner, "give.tag")) {
1320             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element give.tag");
1321         }
1322         if (getElement(runner, "give.tag").getAttribute("readonly") != 'true') {
1323             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element give.tag is not readonly");
1324         }
1325         if (!getElement(runner, "take.tag")) {
1326             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element take.tag");
1327         }
1328         if (getElement(runner, "take.tag").getAttribute("readonly") != 'true') {
1329             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element take.tag is not readonly");
1330         }
1331     }
1332     base.checkNew = function(runner) {
1333         var tagInput = getElement(runner, "flow.tag");
1334         if (!tagInput) {
1335             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element flow.tag");
1336         }
1337         if (tagInput.getAttribute("readonly") == 'true') {
1338             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element flow.tag is readonly");
1339         }
1340         var rateInput = getElement(runner, "flow.rate");
1341         if (!rateInput) {
1342             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element flow.rate");
1343         }
1344         if (rateInput.getAttribute("readonly") == 'true') {
1345             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element flow.rate is readonly");
1346         }
1347         var flowIsOffBalance = getElement(runner, "flow.isoffbalance");
1348         if (!flowIsOffBalance) {
1349             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element flow.isoffbalance");
1350         }
1351         if (flowIsOffBalance.getAttribute("readonly") == 'true') {
1352             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element flow.isoffbalance is readonly");
1353         }
1354         //getElement(runner, this._directionID).selectedIndex = this._directionValue;
1355         if (!getElement(runner, "rate.direction")) {
1356             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element rate.direction");
1357         }
1358         if (getElement(runner, "rate.direction").getAttribute("readonly") == 'true') {
1359             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element rate.direction is readonly");
1360         }
1361         if (!getElement(runner, "entity.tag")) {
1362             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element entity.tag");
1363         }
1364         if (getElement(runner, "entity.tag").getAttribute("readonly") == 'true') {
1365             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element entity.tag is readonly");
1366         }
1367         if (!getElement(runner, "give.tag")) {
1368             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element give.tag");
1369         }
1370         if (getElement(runner, "give.tag").getAttribute("readonly") == 'true') {
1371             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element give.tag is readonly");
1372         }
1373         if (!getElement(runner, "take.tag")) {
1374             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] cann't find element take.tag");
1375         }
1376         if (getElement(runner, "take.tag").getAttribute("readonly") == 'true') {
1377             this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPage] element take.tag is readonly");
1378         }
1379     }
1380     base.checkChange = function(runner) {
1381         this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkChange] do not implemented");
1382     }
1383     base.checkCancel = function(runner) {
1384         this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkCancel] do not implemented");
1385     }
1386     base.checkReset = function(runner) {
1387         this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkReset] do not implemented");
1388     }
1389     base.checkSave = base.checkPage;
1390     base.checkPageWithSubmit = function(runner) {
1391         this.addJSFailure(runner, "[aaJSTestPageFlowModule.checkPageWithSubmit] do not implemented");
1392     }
1393     base.selectCheckRow = function(view, tree, i, object) {
1394         return false;
1395     }
1396     return base;
1400 example for fill
1402     name: "test name",
1403     contractID: "contract id",
1404     cid: Components.ID(""),
1405     object: {
1406         tag: 'shipment1.rule1',
1407         takeFrom: 'storage 1',
1408         giveTo: 'sale 1',
1409         rate: 27.0,
1410         change_fact_side: 0
1411     }
1414 function aaJSTestNewRule(input) {
1415     var me = new JSTest();
1416     me._name = input.name;
1417     me._contractID = input.contractID;
1418     me._CID = input.cid;
1419     
1420     me._tagID = 'rule.tag';
1421     me._takeFromID = 'rule.takefrom';
1422     me._giveToID = 'rule.giveto';
1423     me._rateID = 'rule.rate';
1424     me._change_fact_sideID = 'rule.change.fact.side';
1425     
1426     me._tagValue = input.object.tag;
1427     me._takeFromValue = input.object.takeFrom;
1428     me._giveToValue = input.object.giveTo;
1429     me._rateValue = input.object.rate;
1430     me._change_fact_sideValue = input.object.change_fact_side;
1431     
1432     me._test = function(runner) {
1433         var tag = getElement(runner, this._tagID);
1434         var _rate = getElement(runner, this._rateID);
1435         var _changeFact = getElement(runner, this._change_fact_sideID);
1436         var _giveTo = getElement(runner, this._giveToID);
1437         var _takeFrom = getElement(runner, this._takeFromID);
1438         
1439         tag.value = this._tagValue;
1440         sendOnInput(tag);
1441         
1442         _rate.value = this._rateValue;
1443         sendOnInput(_rate);
1444         
1445         _changeFact.selectedIndex = this._change_fact_sideValue;
1446         //find combobox item
1447         if (this._giveToValue) {
1448             var gToItem = _giveTo.getElementsByAttribute("label", this._giveToValue);
1449             if (gToItem && gToItem.length > 0) {
1450                 _giveTo.selectedItem = gToItem[0];
1451             }
1452         }
1453         if (this._takeFromValue) {
1454             var tFromItem = _takeFrom.getElementsByAttribute("label", this._takeFromValue);
1455             if (tFromItem && tFromItem.length > 0) {
1456                 _takeFrom.selectedItem = tFromItem[0];
1457             }
1458         }
1459         if (this._check) {
1460             this._check(runner);
1461         }
1462     }
1463     me._check = function(runner) {
1464         var tag = getElement(runner, this._tagID);
1465         if (tag.value != this._tagValue) {
1466             this.addJSFailure(runner, "[aaJSTestNewRule._check] tag value is not equal to set; Value: " + tag.value);
1467         }
1468         var _rate = getElement(runner, this._rateID);
1469         if (_rate.value != this._rateValue) {
1470             this.addJSFailure(runner, "[aaJSTestNewRule._check] rate value is not equal to set; Value: " + _rate.value);
1471         }
1472         var _changeFact = getElement(runner, this._change_fact_sideID);
1473         if (_changeFact.selectedIndex != this._change_fact_sideValue) {
1474             this.addJSFailure(runner, "[aaJSTestNewRule._check] change_fact_side value is not equal to set; Value: " + _changeFact.selectedIndex);
1475         }
1476         var _giveTo = getElement(runner, this._giveToID);
1477         if (_giveTo.selectedItem.label != this._giveToValue) {
1478             this.addJSFailure(runner, "[aaJSTestNewRule._check] _giveTo value is not equal to set; Value: " + _giveTo.selectedItem.label);
1479         }
1480         var _takeFrom = getElement(runner, this._takeFromID);
1481         if (_takeFrom.selectedItem.label != this._takeFromValue) {
1482             this.addJSFailure(runner, "[aaJSTestNewRule._check] _takeFrom value is not equal to set; Value: " + _takeFrom.selectedItem.label);
1483         }
1484     }
1485     return me;
1489 example for fill
1491     cid: Components.ID(""),
1492     object: {
1493         tag: 'shipment1.rule1',
1494         takeFrom: 'storage 1',
1495         giveTo: 'sale 1',
1496         rate: 27.0,
1497         change_fact_side: 0
1498     }
1500 do not selectable
1502 //add cid manually
1503 function aaJSTestPageRuleModule(testNumber) {
1504     var base = aaJSTestPagePage1Module('rule' + testNumber);
1505     base.addFillTest = function(data) {
1506         //add call new
1507         this.addCommandNewTest();
1508         //add fill
1509         data.contractID = this.generateContractID("create_rule" + this._parse_counter + "_" + data.object.tag);
1510         data.name = "aaRuleCreate" + this._parse_counter + "_" + data.object.tag;
1511         this._add(aaJSTestNewRule(data));
1512         //add call save
1513         this.addCommandSaveTest();
1514     }
1515     base.checkPage = function(runner) {
1516         var tag = getElement(runner, "rule.tag");
1517         if (tag.getAttribute('readonly') != 'true') {
1518             this.addJSFailure(runner, "[aaJSTestNewRule._check] tag is not readonly");
1519         }
1520         var _rate = getElement(runner, "rule.rate");
1521         if (_rate.getAttribute('readonly') != 'true') {
1522             this.addJSFailure(runner, "[aaJSTestNewRule._check] rate is not readonly");
1523         }
1524         var _changeFact = getElement(runner, "rule.change.fact.side");
1525         if (_changeFact.getAttribute('readonly') != 'true') {
1526             this.addJSFailure(runner, "[aaJSTestNewRule._check] change_fact_side is not readonly");
1527         }
1528         var _giveTo = getElement(runner, "rule.giveto");
1529         if (_giveTo.getAttribute('readonly') != 'true') {
1530             this.addJSFailure(runner, "[aaJSTestNewRule._check] _giveTo is not readonly");
1531         }
1532         var _takeFrom = getElement(runner, "rule.takefrom");
1533         if (_takeFrom.getAttribute('readonly') != 'true') {
1534             this.addJSFailure(runner, "[aaJSTestNewRule._check] _takeFrom is not readonly");
1535         }
1536     }
1537     base.checkNew = function(runner) {
1538         var tag = getElement(runner, "rule.tag");
1539         if (tag.getAttribute('readonly') == 'true') {
1540             this.addJSFailure(runner, "[aaJSTestNewRule._check] tag is readonly");
1541         }
1542         var _rate = getElement(runner, "rule.rate");
1543         if (_rate.getAttribute('readonly') == 'true') {
1544             this.addJSFailure(runner, "[aaJSTestNewRule._check] rate is readonly");
1545         }
1546         var _changeFact = getElement(runner, "rule.change.fact.side");
1547         if (_changeFact.getAttribute('readonly') == 'true') {
1548             this.addJSFailure(runner, "[aaJSTestNewRule._check] change_fact_side is readonly");
1549         }
1550         var _giveTo = getElement(runner, "rule.giveto");
1551         if (_giveTo.getAttribute('readonly') == 'true') {
1552             this.addJSFailure(runner, "[aaJSTestNewRule._check] _giveTo is readonly");
1553         }
1554         var _takeFrom = getElement(runner, "rule.takefrom");
1555         if (_takeFrom.getAttribute('readonly') == 'true') {
1556             this.addJSFailure(runner, "[aaJSTestNewRule._check] _takeFrom is readonly");
1557         }
1558     }
1559     base.checkChange = function(runner) {
1560         this.addJSFailure(runner, "[aaJSTestPageRuleModule.checkChange] not implemented");
1561     }
1562     base.checkCancel = function(runner) {
1563         this.addJSFailure(runner, "[aaJSTestPageRuleModule.checkCancel] not implemented");
1564     }
1565     base.checkReset = function(runner) {
1566         this.addJSFailure(runner, "[aaJSTestPageRuleModule.checkReset] not implemented");
1567     }
1568     base.checkSave = base.checkPage;
1569     base.checkPageWithSubmit = function(runner) {
1570         this.addJSFailure(runner, "[aaJSTestPageRuleModule.checkPageWithSubmit] not implemented");
1571     }
1572     return base;