UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

132 lines (99 loc) 4.13 kB
StartTest(function (t) { document.body.innerHTML = '<input type="text" id="foo">'; document.getElementById('foo').focus() t.it('Click with ctrl key, with ctrl + shift', function (t) { var recorder = new Siesta.Recorder.ExtJS({ ignoreSynthetic : false }); recorder.attach(window); recorder.start(); t.chain( { click : [ 1, 50 ], options : { ctrlKey : true } }, // avoid merge of the clicks to doubleclick t.simulator.type == 'native' ? { waitFor : 500 } : null, { click : [ 1, 50 ], options : { ctrlKey : true, altKey : true } }, function () { var steps = recorder.getRecordedActionsAsSteps(); recorder.stop(); t.isDeeply( steps, [ { action : "click", target : [ 1, 50 ], options : { ctrlKey : true } }, { action : "click", target : [ 1, 50 ], options : { ctrlKey : true, altKey : true } } ] ) } ); }) t.it('Modifier key change should create new action - SHIFT', function (t) { var recorder = new Siesta.Recorder.ExtJS({ ignoreSynthetic : false }); recorder.attach(window); var KeyCodes = Siesta.Test.UserAgent.KeyCodes().keys var el = document.body; t.chain( { click : '#foo' }, function (next) { recorder.start(); next() }, { type : 'f' }, { type : 'A', options : { shiftKey : true } }, { type : 'n' }, function() { var steps = recorder.getRecordedActions(); t.is(steps.length, 3) t.is(steps[0].value, 'f') t.is(steps[1].value, 'A') t.is(steps[2].value, 'n') } ) }) t.it('Typing CTRL+C, then regular text should create 2 actions', function (t) { var recorder = new Siesta.Recorder.ExtJS({ ignoreSynthetic : false }); recorder.attach(window); recorder.start(); var KeyCodes = Siesta.Test.UserAgent.KeyCodes().keys t.chain( { type : 'c', options : { ctrlKey : true }, target : "#foo" }, { type : 'foo', target : "#foo" }, function() { var steps = recorder.getRecordedActions(); t.is(steps.length, 2) // need to lower case, because of difference between synthetic / native, where in one case the "c" will be "C" t.is(steps[ 0 ].value.toLowerCase(), 'c') t.is(steps[ 1 ].value, 'foo') t.isDeeply(steps[ 0 ].options, { ctrlKey : true }) } ) }) t.it('Pressing just a modifier key should not record anything', function (t) { var recorder = new Siesta.Recorder.ExtJS({ ignoreSynthetic : false }); recorder.attach(window); recorder.start(); var KeyCodes = Siesta.Test.UserAgent.KeyCodes().keys t.chain( { type : '[SHIFT]' }, // { type : '[ALT]'}, { type : '[CTRL]' }, function () { var steps = recorder.getRecordedActions(); t.is(steps.length, 0) } ) }) t.it('Typing SHIFT+TAB, should work', function (t) { var recorder = new Siesta.Recorder.ExtJS({ ignoreSynthetic : false }); recorder.attach(window); recorder.start(); var KeyCodes = Siesta.Test.UserAgent.KeyCodes().keys t.chain( { type : 'foo' }, { type : '[TAB]', options : { shiftKey : true } }, function() { var steps = recorder.getRecordedActions(); t.is(steps.length, 2) t.is(steps[ 0 ].value, 'foo') t.is(steps[ 1 ].value, '[TAB]') t.isDeeply(steps[ 1 ].options, { shiftKey : true }) } ) }) })