Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular-scenario e2e testing - waiting for key events to complete before proceeding

How are people writing angular e2e tests that involve triggering a sequence of UI events? The async nature of scenario seems to make it difficult.

details: I'm writing tests for an app that has a lot of key handling to help speed editing of a specialised form. I've pulled together a keyboard extension to the scenario dsl (see below) but only the first key event of a test has any effect. i.e.

keyboard().keydown(null, 'keydown', 40, false, true); // ctrl-down
expect(element('*:focus').text()).toEqual('00:04');
keyboard().keydown(null, 'keydown', 40, false, true); // ctrl-down
expect(element('*:focus').text()).toEqual('');  // but equals 00:04

The second keydown doesn't do anything, because it doesn't find a *:focus to route the key to (although there is one on the screen). Confusing.

angular.scenario.dsl('keyboard', function() { 
    var chain  = {}; 
    chain.keydown = function(selector, keyEvent, keyCode, shift, ctrl) { 
        return this.addFutureAction("keyEvent", function($window, $document, done) { 
            var jQuery = $window.$; 
            var e = jQuery.Event(keyEvent);
            e.keyCode = keyCode; // # Some key code value
            e.altKey = false;
            e.ctrlKey = ctrl;
            e.shiftKey = shift;
            if (selector == null) selector = '*:focus';
            var j = jQuery(selector);
            if (j == null) j = jQuery('body');
            j.trigger(e);
            done(); 
        }); 
    }; 
    return function() { 
        return chain; 
    }; 
}); 
like image 506
hemul Avatar asked Dec 04 '12 14:12

hemul


1 Answers

User seem to have abandoned this question, but as I said, this is probably an issue with his keydown event handler.

Made a Plnker here with exactly the same code and everything work as expected.

like image 196
Caio Cunha Avatar answered Nov 03 '22 01:11

Caio Cunha