Get help with testing, discuss unit testing strategies etc.


Post by jflowers45 »

I have a test that
1. selects two items on a grid
2. executes a right click which opens a context menu,
3. clicks one of the items in the menu.

Here's a rough idea of the code:
 function(next) {
                    var items = grid.getStore().getData().items;
                    grid.getView().getSelectionModel().select([items[0],items[1]]);
                    next();
                },
                
                { waitFor: 1000}, //right click sporadically fails if I don't put this in ... 
                { rightclick: function() { return t.getCell(grid,0, 2); } },
 { click: ">>menuitem[text=Bulk Copy]", desc: "Click Bulk Copy"}
Without the waitFor:1000 (or some magic number), It sporadically fails to execute the right click and instead simply shows the message "waiting for [Object object]".

I have tried waiting for a selection change on the selectionModel, and I also tried doing a waitForTop, and neither of those solved the problem, but the arbitrary wait statement does if the # of seconds to wait is long enough.

Any ideas? I hate the idea of leaving a magic number in there but I'm out of things to try. I went into siesta-all.js to try and console.log things but I got as far as the processMouseActionSteps function at which point I didn't really know how to keep tracing in a meaningful way.

Thanks!

Post by mats »

Yeah magic number should be removed. Any chance you can boil this down to a very simple small test case that we can run and inspect?

Post by jflowers45 »

My first attempt at creating a simple test case outside of our app failed to cause an error, but it did spark some thought. Two more bits of info that may help:

1) Immediately prior to all of this i'm executing a remote filter

2) if I console.log the value of the cell that I'm trying to right click before I wait for the magic number, and then I log it again after I wait for the magic number, it returns different ID's. Before waiting it returns ext-element-180, and after waiting one second it returns ext-element-181.

So - why would calls to t.getCell(grid,0,2) return something different if the only thing that has happened is a 1 second wait? Sounds like a race condition ... but I've tried looking at / listening to every relevant event I can think of and I've got nothing. I did make sure that the value of the grid variable isn't changing, and I am waiting on the refresh event on the store to make sure the remote sort has already completed.

Code with addition of remote sort and console logs added. It appears that the selection of the two rows had nothing to do with it, so I removed that bit.
{
                waitForEvent: function() { return [grid.getStore(), 'datachanged']; },
                desc:"filter to validated items",
                trigger:function() {
                    grid.getStore().filter([{property:"STATUS",value:"VALIDATED", operator: "like"}]);
                }
            },

 function(next) {
                console.log('cell before magic number', t.getCell(grid,0,2));
                next();
            },
            { waitFor: 1000},
            function(next) {
                console.log('cell after magic number, returns NEW dom ID! ', t.getCell(grid,0,2));
                next();
            },
            { rightclick: function() { return t.getCell(grid,0,2); }},
Any ideas would be much appreciated!

Post by nickolay »

I guess, there's simply some delayed grid row refresh somewhere in Ext sources. May be try waiting for "rowupdated" event from the grid view?

Possible other solution would be to use CSS query instead of exact DOM element, since CSS query will be resolving even if original element goes out of DOM..

Post Reply