Get help with testing, discuss unit testing strategies etc.


Post by fredric berling »

Would be nice to have a convenient waiter function that calls back when Ext.Loader is done (e.g. not makin calls for a while?) .
Ive built my own dirty function that makes a waitFor checking for the ability to return a specific controller from Ext.application (getController). This works fine in my test case now but it would be nice to have a more solid generic function.

Post by mats »

Could you post a simple test showing how you use it?

Post by fredric berling »

I include a Ext.Application file in my preloads (app.js) All controllers and models and views will be loaded using the Ext.Loader. This is our "Portal"

In my test case of opening a "Application" in our Portal, i need the Ext-loader for the portal to be loaded and in a silent stable state before trying to call my "openApplication" function.
StartTest(function(t){
    t.diag("ISAK ADM140");

    ISAK.Test.waitForExtLoader(t, function(){
   
        ISAK.Test.openApplication(t,'ISAK.view.ADM140.UI', true, 'ADM140WIN')
        
    });
});


The waitForExtLoader in my case is dirty and looks like this. I rewrote it to make it readable , but its checking for a a namespace and then for the existans of a controller, and if the controller is loaded it checks for the center tabPanel wich is part of the Viewport.
ISAK.Test.waitForExtLoader = function(t, callback, scope, timeout){
    t.waitFor(function(){
        if (ISAK.UI && ISAK.UI.getController('Menu')) {
            var controller = ISAK.UI.getController('Menu')
            if (controller.getMainTabPanel()) {
                return true
            }
            else {
                return false
            }
        }
        else {
            return false
        }
    }, callback, scope, timeout);
}

I probably schould mention that i point the Ext.Application at the global ISAK.UI in the launch function using this code:
ISAK.UI = this
I don't know any other way of grabbing the application object after launch in any other way.

Post by nickolay »

Am I correct, that you need to wait till the moment, when Ext.Loader load some class?

Something like:
t.waitForExtLoader('ISAK.Application', function () { ... })
Then I think it can look like:
waitForExtLoader : function (className, callback, scope, timeout) {
    this.waitFor(
        function () {
            return Ext.ClassManager.isCreated(className)
        },
        callback, 
        scope, 
        timeout
    )
}
Or am I missing something?

Post by fredric berling »

No not really. I would probably want to wait for all classes to be loaded. I don't want to specify a specific class since its a complete portal with lots of classes.
The controller will in turn load a lot of views and models with are also async , wich might also be important for the test case.

Im kinda looking for the old Ext.onReady but from a Ext.Loader point of view.

I understand that this is only important before i compile with sencha SDK and gets rid of the loader, but testing must be done against the dev environment also.

hmm..Thanks for the heads up on the class manager.

Btw. Im getting the feeling i can't live without this tool .

Post by mats »

How about using this method on Ext.Loader:
onReady( Function fn, Object scope, Boolean withDomReady )
Adds new listener to be executed when all required scripts are fully loaded.

Post by fredric berling »

You make me look stupid. I like that

Post by fredric berling »

Here is what i came pup with. And it works.

Class('YourTestClass', {
    isa     : Siesta.Test.ExtJS,
  
    methods : {
  
        waitForExtLoader : function(callback, scope, timeout) {
            var loaderready = false;
	     this.getExt().Loader.onReady(function(){
                  loaderready = true;
             }, scope, true);
		 	
            this.waitFor(function(){
                 return loaderready;
             }, callback, scope, timeout);
        }
    }
})
Last edited by fredric berling on Fri Oct 14, 2011 4:51 pm, edited 1 time in total.

Post by mats »

nicely done! :) Got my email?

Post by fredric berling »

If it was the one about subscription, i have forwarded it to people with money

Post Reply