1. #1
    Sencha User
    Join Date
    Mar 2011
    Location
    Munich, Germany
    Posts
    37
    Vote Rating
    2
    baboen is on a distinguished road

      0  

    Default [SOLVED]If Store is finished loading the data (for BDD test - Jasmine)

    [SOLVED]If Store is finished loading the data (for BDD test - Jasmine)


    Hi everyone,
    I'm new to ExtJs. first of all, sorry for this very noob question, but I've googled it up & down and also search on the forum but couldn't find the exact problem as mine.

    Currently I'm writing a test file for my widgets component which is created by ExtJS 4 and I'm testing using Jasmine framework.
    The idea is to get if the store is finished loading. or in other words:
    "x.store.isLoading != true"

    I need this function working because I must validate the "finished" or "fully loaded" store's data. Only after finished loading the store data, then I could determine the whole data completely, in this case the length should be 1-2 if the person has a tested_phone. The phone numbers is generated by querying a JSON to the server, the query will be fired soon as the event of contactPersonPicker.on(change).
    the contactPersonPicker's ID is needed because it is the extraParams of this query.
    So, What I actually do is this:

    Code:
    it("input person and validate if it pass the new parameter",
        function()
        {  var shippingForm = Srm.App.mainPanel.items.get(1).ticketForm.shippingForm;
            var contactPersonPicker= shippingForm.contactPersonPicker;
            var contactNumberPicker= shippingForm.contactNumberPicker;
            
            contactPersonPicker.store.add(person);
             contactPersonPicker.setValue(person.data.id); 
    /*the bold italic code will fire an event: contactNumberPicker.store.load({extraParams: perID)
     the perID is actually the person.data.id in this case
    */
            
            if(contactNumberPicker.store.isLoading()==true)
            do{
                if(contactNumberPicker.store.isLoading() == false)
                {   if(tested_phone[0] != null)
                    {   contactNumberPicker.store.getUpdatedRecords();
                        expect(contactNumberPicker.store.data.length).toBeGreaterThan(0);
                        expect(contactNumberPicker.store.data.length).toBeLessThan(3);
                        console.log(contactNumberPicker.store.data.length);
                    }
                    else
                        expect(contactNumberPicker.store.data.length).toEqual(0);
                }
            }while(contactNumberPicker.store.isLoading() == true);
    ....
    This will result my browser to hangs (tested on FF 4 and FF 3.6) and in the firebug it'll catch a script that will make the whole page goes bussy. Before I wrote it this way:

    Code:
    it("input person and validate if it pass the new parameter",
        function()
        {  var shippingForm = Srm.App.mainPanel.items.get(1).ticketForm.shippingForm;
            var contactPersonPicker= shippingForm.contactPersonPicker;
            var contactNumberPicker= shippingForm.contactNumberPicker;
            
            contactPersonPicker.store.add(person);
             contactPersonPicker.setValue(person.data.id);
     /*the bold italic code will fire an event: contactNumberPicker.store.load({extraParams: perID)
     the perID is actually the person.data.id in this case
    */
    
                    if(tested_phone[0] != null)
                    {   contactNumberPicker.store.getUpdatedRecords();
                        expect(contactNumberPicker.store.data.length).toBeGreaterThan(0);
                        expect(contactNumberPicker.store.data.length).toBeLessThan(3);
                        console.log(contactNumberPicker.store.data.length);
                    }
                    else
                        expect(contactNumberPicker.store.data.length).toEqual(0);
       
    ....
    the second code will result contactNumberPicker.store.data.length = 0, because it'll execute the statement immideately and not waiting for the load to finished loading.

    Any suggestion how to make this work? Remember, I can't see the code directly or even change it, as I don't have sufficient access to the code itself (the models). These elements & functions I gained by inspecting the DOM and also ExtJS4 docs.

    Thx before

  2. #2
    Sencha User
    Join Date
    Mar 2011
    Location
    Munich, Germany
    Posts
    37
    Vote Rating
    2
    baboen is on a distinguished road

      0  

    Default (solved)

    (solved)


    Sorry for asking this noob question because this problem has haunted me for 2 days... but now, it's solved, thx anyway for reading

    I use the .on(load) function, before it fires the ajax:

    Code:
            contactNumberPicker.store.on('load',
            function()
            {       if(tested_phone[0] != null)
                    {   contactNumberPicker.store.getUpdatedRecords();
                        expect(contactNumberPicker.store.data.length).toBeGreaterThan(0);
                        expect(contactNumberPicker.store.data.length).toBeLessThan(3);
                        console.log("the contact number length: "+contactNumberPicker.store.data.length);
                    }
                    else
                        expect(contactNumberPicker.store.data.length).toEqual(0);
            }
            ,this);
            contactPersonPicker.store.add(person);
            contactPersonPicker.setValue(person.data.id);

Similar Threads

  1. ExtJS Jasmine unit test reporter?
    By Scott Murawski in forum Community Discussion
    Replies: 4
    Last Post: 9 Dec 2011, 12:53 PM
  2. need help with loading data into a template from a data store
    By 720 in forum Ext Designer: Help & Discussion
    Replies: 1
    Last Post: 10 Aug 2010, 7:43 AM
  3. How can I know if a tree has finished loading?
    By kvbisme in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 16 Apr 2008, 8:49 AM
  4. Ext.data.Store - loading data and remembering page state
    By bowmanmc in forum Ext 1.x: Help & Discussion
    Replies: 6
    Last Post: 15 Aug 2007, 10:02 AM

Tags for this Thread