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;
};
});
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With