app: added class for fill object on entity page
[abstract.git] / app / test / aaUITestFrame.jsm
blob72be1c11637bd4153cb91a795b2b07c86717d56f
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/nsTestFrame.jsm");
23 /* Page specific class  */
25 example for actions on page
27     {
28         name: "open",
29         data: null //some data for special page 
30     },
31     {
32         name: "close",
33         data: null //some data for special page 
34     },
37 function JSTestPageModuleUI() {
38     var base = JSTestModule();
39     base.addOpenPage = null;
40     base.addClosePage = null;
41     base.parseAction = function(action) {
42         switch(action.name) {
43             case 'open':
44                 this.addOpenPage(action.data);
45                 return true;
46                 break;
47             case 'close':
48                 this.addClosePage(action.data);
49                 return true;
50                 break;
51         }
52         return false;
53     }
54     return base;
56 /* End page specific class */
59 example
61     cid: Components.ID(),
62     contractID: "",
63     name: "",
64     object: {
65         command: ''
66         checkF: null //function to check
67         checkInTest: true or false
68     }
71 function aaJSDoCommandTest(input) {
72     var base = new JSTest();
73     
74     base._name = input.name;
75     base._contractID = input.contractID;
76     base._CID = input.cid;
77     
78     base._command = input.object.command;
79     base._checkInTest = false;
80     if (input.object.checkInTest) {
81         base._checkInTest = input.object.checkInTest;
82     }
83     
84     base._test = function(runner) {
85         if (!this._command) 
86             this.addJSFailure(runner, "JSDoCommandTest::_test - command is not defined");
87         else {
88             runner.doCommand(this._command);
89             if (this._checkInTest && this._check) {
90                 this._check(runner);
91             }
92         }
93     }
94     base._check = input.object.checkF;
95     return base;
99 example
101     cid: Components.ID(),
102     contractID: "",
103     name: "",
104     object: {
105         command: '' || click: ''
106         checkF: null //function to check
107     }
110 function aaJSCommandOpenPageTest(input) {
111     var base = null;
112     if (input.object.command) {
113         base = aaJSDoCommandTest(input);
114         base.aaJSDoCommandTest_test = base._test;
115         base._test = function(runner) {
116             try {
117                 this.aaJSDoCommandTest_test(runner);
118             } catch(e) {
119                 this.addJSFailure(runner, "[aaJSCommandOpenPageTest] cann't do command. Exception: " + e);
120             }
121             runner.watchWindow = getFrame(runner).contentWindow;
122         }
123     } else if(input.object.click) {
124         base = new JSTest();
125         base._CID = input.cid;
126         base._contractID = input.contractID;
127         base._name = input.name;
128         
129         base._clickID = input.object.click;
130         
131         base._test = function(runner) {
132             sendOnClick(getElement(runner, this._clickID));
133             runner.watchWindow = getFrame(runner).contentWindow;
134         }
135         base._check = input.object.checkF;
136     }
137     return base;
141 example for:
142 1. open
144     cid: Components.ID(),
145     object: { 
146         command: "cmd_view_entity"
147     }
149 2. close
151     cid: Components.ID(),
152     object: { 
153         command: "cmd_page1_submit",
154         checkF: null //function for check result page
155     }
157 example for extended actions:
159     {
160         name: fill,
161         data: null //page specific data
162     },
165 function aaJSTestPageModule(pgName) {
166     var base = JSTestPageModuleUI();
167         
168     base._contractIDBase = "@aasii.org/abstract/test/";
169     base._pageName = pgName;
170     base._version = 1;
171     
172     base._contractID = base._contractIDBase + base._pageName + "/page;" + base._version;
173     base._name = "aaPage_" + base._pageName;
174     
175     base.generateContractID = function(inner_str) {
176         return this._contractIDBase + this._pageName + "/" + inner_str + ";" + this._version;
177     }
178     
179     base.JSTestPage_parseAction = base.parseAction;
180     base.parseAction = function(action) {
181         switch(action.name) {
182             case 'fill':
183                 this.addFillTest(action.data);
184                 return true;
185                 break;
186         }
187         return this.JSTestPage_parseAction(action);
188     }
189     base.addCommandPageOpenTest = function(data) {
190         this._add(aaJSCommandOpenPageTest(data));
191     }
192     base.addCommandTest = function(data) {
193         this._add(aaJSDoCommandTest(data));
194     }
195     base.addFillTest = null;
196     base.checkPage = function(runner) {
197         this.addJSFailure(runner, "aaJSTestPage.checkPage - not implemented");
198     }
199     base.addOpenPage = function(data) {
200         data.contractID = this.generateContractID("open" + this._parse_counter + "/" + data.object.command);
201         data.name = "aaPage_" + this._pageName + "_Open" + this._parse_counter + "_" + data.object.command;
202         data.object.checkF = this.checkPage;
203         this.addCommandPageOpenTest(data);
204     }
205     base.addClosePage = function(data) {
206         data.contractID = this.generateContractID("close" + this._parse_counter + "/" + data.object.command);
207         data.name = "aaPage_" + this._pageName + "_Close" + this._parse_counter + "_" + data.object.command;
208         this.addCommandPageOpenTest(data);
209     }
210     return base;
214 example for cids
216     name: 'page1_cids',
217     data: {
218         cid_new: Components.ID(),
219         cid_change: Components.ID(),
220         cid_cancel: Components.ID(),
221         cid_reset: Components.ID(),
222         cid_save: Components.ID()
223     }
226 function aaJSTestPagePage1Module(pageName) {
227     var base = aaJSTestPageModule(pageName);
228     
229     base.aaJSTestPageModule_parseAction = base.parseAction;
230     
231     base.newCID = null;
232     base.changeCID = null;
233     base.cancelCID = null;
234     base.resetCID = null;
235     base.saveCID = null;
236     
237     base.checkNew = null;
238     base.checkChange = null;
239     base.checkCancel = null;
240     base.checkReset = null;
241     base.checkSave = null;
242     
243     base.checkSubmit = null;
244     base.checkDiscard = null;
245     
246     base._NewCommand = 'cmd_page1_new';
247     base._ChangeCommand = 'cmd_page1_change';
248     base._CancelCommand = 'cmd_page1_cancel';
249     base._ResetCommand = 'cmd_page1_reset';
250     base._SaveCommand = 'cmd_page1_save';
251     
252     base._SubmitCommand = 'cmd_page1_submit';
253     base._DiscardCommand = 'cmd_page1_discard';
254     
255     base.parseAction = function(action) {
256         switch(action.name) {
257             case 'page1_cids':
258                 this.addCids(action.data);
259                 return true;
260                 break;
261         }
262         return this.aaJSTestPageModule_parseAction(action);
263     }
264     base.addCids = function(data) {
265         if (data.cid_new) this.newCID = data.cid_new;
266         if (data.cid_change) this.changeCID = data.cid_change;
267         if (data.cid_cancel) this.cancelCID = data.cid_cancel;
268         if (data.cid_reset) this.resetCID = data.cid_reset;
269         if (data.cid_save) this.saveCID = data.cid_save;
270     }    
271     base.addPage1CommandTest = function(cid, command, checkF) {
272         if (cid in this._map) {
273             this._repeat(this._map[cid]);
274         } else {
275             var data = {};
276             data.cid = cid;
277             data.contractID = this.generateContractID("new_object/" + command);
278             data.name = "aaPage_" + this._pageName + "_" + command;
279             data.object = {};
280             data.object.command = command;
281             data.object.checkF = checkF;
282             data.object.checkInTest = true;
283             //add
284             this.addCommandTest(data);
285         }
286     }
287     
288     base.addCommandNewTest = function() {
289         if (!this.newCID) throw "cid for new button is not defined";
290         this.addPage1CommandTest(this.newCID, this._NewCommand, this.checkNew);
291     }
292     base.addCommandChangeTest = function() {
293         if (!this.changeCID) throw "cid for change button is not defined";
294         this.addPage1CommandTest(this.changeCID, this._ChangeCommand, this.checkChange);
295     }
296     base.addCommandCancelTest = function() {
297         if (!this.cancelCID) throw "cid for cancel button is not defined";
298         this.addPage1CommandTest(this.cancelCID, this._CancelCommand, this.checkCancel);
299     }
300     base.addCommandResetTest = function() {
301         if (!this.resetCID) throw "cid for reset button is not defined";
302         this.addPage1CommandTest(this.resetCID, this._ResetCommand, this.checkReset);
303     }
304     base.addCommandSaveTest = function() {
305         if (!this.saveCID) throw "cid for save button is not defined";
306         this.addPage1CommandTest(this.saveCID, this._SaveCommand, this.checkSave);
307     }
308     return base;
312 input data
314     cid: Components.ID(),
315     contractID: '',
316     name: '',
317     object: //specific object
318     rowFunction: function(view, tree, i, object)
319     foundFunction: function(runner)
322 function aaJSSelectObjectTest(input) {
323     var base = new JSTest();
324     base._CID = input.cid;
325     base._contractID = input.contractID;
326     base._name = input.name;
327     
328     base._checkFunction = input.rowFunction;
329     base._object = input.object;
330     base._foundFunction = input.foundFunction;
331     
332     base._test = function(runner) {
333         var found = false;
334         if (this._checkFunction) {
335             var tree = getElement(runner, page1TreeID);
336             var view = tree.view;
337             for (var i = 0; i < tree.view.rowCount; ++ i) {
338                 if (this._checkFunction(view, tree, i, this._object)) {
339                     tree.view.selection.select(i);
340                     found = true;
341                     if (this._foundFunction) {
342                         this._foundFunction(runner);
343                     }
344                 }
345             }
346         } else {
347             this.addJSFailure(runner, "[aaJSSelectObjectTest] rowFunction is not defined");
348         }
349         if (!found) {
350             this.addJSFailure(runner, "[aaJSSelectObjectTest] cann't find appropriate row");
351         }
352     }
353     
354     base._check = function(runner) {
355     }
356     return base;
360 example for select
362     name: 'select',
363     data: {
364         cid: Components.ID(),
365         object: {
366             //some child class specific object
367         }
368     }
371 function aaJSTestSelectablePagePage1Module(pageName)
373     var base = aaJSTestPagePage1Module(pageName);
374     
375     base._IsPageForSelect = false;
376     
377     base.checkPageWithSubmit = null;
378     base.selectCheckRow = null; //function(view, tree, i, object)
379     
380     base.aaJSTestPagePage1Module_parseAction = base.parseAction;
381     base.aaJSTestPagePage1Module_addOpenPage = base.addOpenPage;
382     
383     base.parseAction = function(action) {
384         switch(action.name) {
385             case 'select':
386                 this.addSelectTest(action.data);
387                 return true;
388                 break;
389         }
390         return this.aaJSTestPagePage1Module_parseAction(action);
391     }
392     base.addSelectTest = function(data) {
393         this._IsPageForSelect = true;
394         data.contractID = this.generateContractID("select_object" + this._parse_counter);
395         data.name = "aaPageSelectObject" + this._parse_counter;
396         data.rowFunction = this.selectCheckRow;
397         //[TEST]
398         data.foundFunction = function(runner) {
399             runner.doCommand('cmd_page1_submit');
400             runner.watchWindow = getFrame(runner).contentWindow;
401         }
402         //[END TEST]
403         this._add(aaJSSelectObjectTest(data));
404     }
405     base.addOpenPage = function(data) {
406         if (this._IsPageForSelect) {
407             data.contractID = this.generateContractID("open" + this._parse_counter + "/" + data.object.command);
408             data.name = "aaPage_" + this._pageName + "_Open" + this._parse_counter + "_" + data.object.command;
409             data.object.checkF = this.checkPageWithSubmit;
410             this.addCommandPageOpenTest(data);
411         } else {
412             this.aaJSTestPagePage1Module_addOpenPage(data);
413         }
414     }
415     return base;
419 example for fill
421     name: "test name",
422     contractID: "contract id",
423     cid: Components.ID(""),
424     object: {
425         tag: 'asdsad'
426     }
429 function aaJSTestEntity(input) {
430     var me = new JSTest();
431     me._name = input.name;
432     me._contractID = input.contractID;
433     me._CID = input.cid;
434     
435     me._tagID = "entity.tag";
436     me._tagValue = input.object.tag;
437     
438     me._test = function(runner) {
439         //get element
440         var box = getElement(runner, this._tagID);
441         //set entity tag
442         box.value = this._tagValue;
443         sendOnInput(box);
444         if (this._check) {
445             this._check(runner);
446         }
447     }
448     me._check = function(runner) {
449         var box = getElement(runner, this._tagID);
450         //check tag entity
451         if (this._tagValue != box.value) {
452             this.addJSFailure(runner, "[Entity page]: tag value is not equal tag textbox value");   
453         }
454     }
455     return me;