Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #2532401 - dial: added automated example tests
- Loading branch information
Showing
6 changed files
with
361 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
YUI.add('dial-basic-tests', function(Y) { | ||
|
||
// copied this from event-key-test.js to add tests for changing value by keyboard | ||
Y.Node.prototype.key = function (code, mods, type) { | ||
var simulate = Y.Event.simulate, | ||
el = this._node, | ||
config = Y.merge(mods || {}, { keyCode: code, charCode: code }); | ||
|
||
if (typeof code === "string") { | ||
code = code.charCodeAt(0); | ||
} | ||
|
||
if (type) { | ||
simulate(el, type, config); | ||
} else { | ||
simulate(el, 'keydown', config); | ||
simulate(el, 'keyup', config); | ||
simulate(el, 'keypress', config); | ||
} | ||
}; | ||
// END copied this from event-key-test.js to add tests for changing value by keyboard | ||
|
||
var suite = new Y.Test.Suite('dial-basic example test suite'), | ||
Assert = Y.Assert, | ||
output = Y.one('.yui3-dial .yui3-dial-value-string'), | ||
input = Y.one('.yui3-dial .yui3-dial-ring'); | ||
|
||
suite.add(new Y.Test.Case({ | ||
name: 'Example tests', | ||
|
||
'example dial initial value check': function() { | ||
Assert.areEqual('30', output.getContent(), 'Failed to initialize dial to correct value'); | ||
}, | ||
|
||
'dial keyboard major increment changes value': function() { | ||
input.key(33); // up | ||
Assert.areEqual('40', output.getContent(), 'Key "Page up" failed to increment by major value'); | ||
}, | ||
|
||
'dial keyboard minor increment': function() { | ||
input.key(37); // left | ||
input.key(37); // left | ||
Assert.areEqual('38', output.getContent(), 'Key "Left" failed to decrement by minor value'); | ||
}, | ||
|
||
'dial keyboard home goes to min value': function() { | ||
input.key(36); // home | ||
Assert.areEqual('-220', output.getContent(), 'Home key failed to set dial to min'); | ||
}, | ||
|
||
'dial keyboard end goes to max value': function() { | ||
input.key(35); // end | ||
Assert.areEqual('220', output.getContent(), 'End key failed to set dial to max'); | ||
}, | ||
|
||
'dial returns to initial value when center button is clicked.': function() { | ||
Y.one('.yui3-dial .yui3-dial-center-button').simulate("mousedown"); | ||
Assert.areEqual('30', output.getContent(), 'Failed to move scene to altitude zero on center button click'); | ||
} | ||
|
||
})); | ||
|
||
Y.Test.Runner.add(suite); | ||
|
||
}, '', { requires: [ 'dial', 'node-event-simulate' ] }); | ||
|
||
|
||
/*, | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
YUI.add('dial-image-background-tests', function(Y) { | ||
|
||
// copied this from event-key-test.js to add tests for changing value by keyboard | ||
Y.Node.prototype.key = function (code, mods, type) { | ||
var simulate = Y.Event.simulate, | ||
el = this._node, | ||
config = Y.merge(mods || {}, { keyCode: code, charCode: code }); | ||
|
||
if (typeof code === "string") { | ||
code = code.charCodeAt(0); | ||
} | ||
|
||
if (type) { | ||
simulate(el, type, config); | ||
} else { | ||
simulate(el, 'keydown', config); | ||
simulate(el, 'keyup', config); | ||
simulate(el, 'keypress', config); | ||
} | ||
}; | ||
// END copied this from event-key-test.js to add tests for changing value by keyboard | ||
|
||
var suite = new Y.Test.Suite('dial-image-background example test suite'), | ||
Assert = Y.Assert, | ||
output = Y.one('.yui3-dial .yui3-dial-value-string'), | ||
input = Y.one('.yui3-dial .yui3-dial-ring'); | ||
|
||
suite.add(new Y.Test.Case({ | ||
name: 'Example tests', | ||
|
||
'example dial initial value check': function() { | ||
Assert.areEqual('30', output.getContent(), 'Failed to initialize dial to correct value'); | ||
}, | ||
|
||
'dial keyboard major increment changes value': function() { | ||
input.key(33); // up | ||
Assert.areEqual('40', output.getContent(), 'Key "Page up" failed to increment by major value'); | ||
}, | ||
|
||
'dial keyboard minor increment': function() { | ||
input.key(37); // left | ||
input.key(37); // left | ||
Assert.areEqual('38', output.getContent(), 'Key "Left" failed to decrement by minor value'); | ||
}, | ||
|
||
'dial keyboard home goes to min value': function() { | ||
input.key(36); // home | ||
Assert.areEqual('-220', output.getContent(), 'Home key failed to set dial to min'); | ||
}, | ||
|
||
'dial keyboard end goes to max value': function() { | ||
input.key(35); // end | ||
Assert.areEqual('220', output.getContent(), 'End key failed to set dial to max'); | ||
}, | ||
|
||
'dial returns to initial value when center button is clicked.': function() { | ||
Y.one('.yui3-dial .yui3-dial-center-button').simulate("mousedown"); | ||
Assert.areEqual('30', output.getContent(), 'Failed to move scene to altitude zero on center button click'); | ||
} | ||
|
||
})); | ||
|
||
Y.Test.Runner.add(suite); | ||
|
||
}, '', { requires: [ 'dial', 'node-event-simulate' ] }); | ||
|
||
|
||
/*, | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
YUI.add('dial-image-surrounding-tests', function(Y) { | ||
|
||
// copied this from event-key-test.js to add tests for changing value by keyboard | ||
Y.Node.prototype.key = function (code, mods, type) { | ||
var simulate = Y.Event.simulate, | ||
el = this._node, | ||
config = Y.merge(mods || {}, { keyCode: code, charCode: code }); | ||
|
||
if (typeof code === "string") { | ||
code = code.charCodeAt(0); | ||
} | ||
|
||
if (type) { | ||
simulate(el, type, config); | ||
} else { | ||
simulate(el, 'keydown', config); | ||
simulate(el, 'keyup', config); | ||
simulate(el, 'keypress', config); | ||
} | ||
}; | ||
// END copied this from event-key-test.js to add tests for changing value by keyboard | ||
|
||
var suite = new Y.Test.Suite('dial-image-surrounding example test suite'), | ||
Assert = Y.Assert, | ||
output = Y.one('.yui3-dial .yui3-dial-value-string'), | ||
input = Y.one('.yui3-dial .yui3-dial-ring'); | ||
|
||
suite.add(new Y.Test.Case({ | ||
name: 'Example tests', | ||
|
||
'example has 1 initial images': function() { | ||
var imgs = Y.all('.example img'); | ||
Assert.areEqual(1, imgs.size(), 'Failed to render all images'); | ||
}, | ||
|
||
'example dial initial value check': function() { | ||
Assert.areEqual('0', output.getContent(), 'Failed to initialize dial to correct value'); | ||
}, | ||
|
||
'dial keyboard major increment changes value': function() { | ||
input.key(33); // up | ||
Assert.areEqual('10', output.getContent(), 'Key "Page up" failed to increment by major value'); | ||
}, | ||
|
||
'dial keyboard minor increment': function() { | ||
input.key(37); // left | ||
input.key(37); // left | ||
Assert.areEqual('8', output.getContent(), 'Key "Left" failed to decrement by minor value'); | ||
}, | ||
|
||
'dial keyboard home goes to min value': function() { | ||
input.key(36); // home | ||
Assert.areEqual('-90', output.getContent(), 'Home key failed to set dial to min'); | ||
}, | ||
|
||
'dial keyboard end goes to max value': function() { | ||
input.key(35); // end | ||
Assert.areEqual('90', output.getContent(), 'End key failed to set dial to max'); | ||
}, | ||
|
||
'dial returns to initial value when center button is clicked.': function() { | ||
Y.one('.yui3-dial .yui3-dial-center-button').simulate("mousedown"); | ||
Assert.areEqual('0', output.getContent(), 'Failed to move scene to altitude zero on center button click'); | ||
} | ||
|
||
})); | ||
|
||
Y.Test.Runner.add(suite); | ||
|
||
}, '', { requires: [ 'dial', 'node-event-simulate' ] }); | ||
|
||
|
||
/*, | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
YUI.add('dial-text-input-tests', function(Y) { | ||
|
||
// copied this from event-key-test.js to add tests for changing value by keyboard | ||
Y.Node.prototype.key = function (code, mods, type) { | ||
var simulate = Y.Event.simulate, | ||
el = this._node, | ||
config = Y.merge(mods || {}, { keyCode: code, charCode: code }); | ||
|
||
if (typeof code === "string") { | ||
code = code.charCodeAt(0); | ||
} | ||
|
||
if (type) { | ||
simulate(el, type, config); | ||
} else { | ||
simulate(el, 'keydown', config); | ||
simulate(el, 'keyup', config); | ||
simulate(el, 'keypress', config); | ||
} | ||
}; | ||
// END copied this from event-key-test.js to add tests for changing value by keyboard | ||
|
||
var suite = new Y.Test.Suite('dial-text-input example test suite'), | ||
Assert = Y.Assert, | ||
output = Y.one('.example #myTextInput'), | ||
input = Y.one('.yui3-dial .yui3-dial-ring'); | ||
|
||
suite.add(new Y.Test.Case({ | ||
name: 'Example tests', | ||
|
||
'example dial initial value check': function() { | ||
Assert.areEqual('30', output.get('value'), 'Failed to initialize dial to correct value'); | ||
}, | ||
|
||
'dial keyboard major increment changes value': function() { | ||
input.key(33); // up | ||
Assert.areEqual('40', output.get('value'), 'Key "Page up" failed to increment by major value'); | ||
}, | ||
|
||
'dial keyboard minor increment': function() { | ||
input.key(37); // left | ||
input.key(37); // left | ||
Assert.areEqual('38', output.get('value'), 'Key "Left" failed to decrement by minor value'); | ||
}, | ||
|
||
'dial keyboard home goes to min value': function() { | ||
input.key(36); // home | ||
Assert.areEqual('-220', output.get('value'), 'Home key failed to set dial to min'); | ||
}, | ||
|
||
'dial keyboard end goes to max value': function() { | ||
input.key(35); // end | ||
Assert.areEqual('220', output.get('value'), 'End key failed to set dial to max'); | ||
}, | ||
|
||
'dial returns to initial value when center button is clicked.': function() { | ||
Y.one('.yui3-dial .yui3-dial-center-button').simulate("mousedown"); | ||
Assert.areEqual('30', output.get('value'), 'Failed to move scene to altitude zero on center button click'); | ||
} | ||
|
||
})); | ||
|
||
Y.Test.Runner.add(suite); | ||
|
||
}, '', { requires: [ 'dial', 'node-event-simulate' ] }); | ||
|
||
|
||
/*, | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
YUI.add('duck-tests', function(Y) { | ||
|
||
// copied this from event-key-test.js to add tests for changing value by keyboard | ||
Y.Node.prototype.key = function (code, mods, type) { | ||
var simulate = Y.Event.simulate, | ||
el = this._node, | ||
config = Y.merge(mods || {}, { keyCode: code, charCode: code }); | ||
|
||
if (typeof code === "string") { | ||
code = code.charCodeAt(0); | ||
} | ||
|
||
if (type) { | ||
simulate(el, type, config); | ||
} else { | ||
simulate(el, 'keydown', config); | ||
simulate(el, 'keyup', config); | ||
simulate(el, 'keypress', config); | ||
} | ||
}; | ||
// END copied this from event-key-test.js to add tests for changing value by keyboard | ||
|
||
var suite = new Y.Test.Suite('duck example test suite'), | ||
Assert = Y.Assert, | ||
output = Y.one('.yui3-dial .yui3-dial-value-string'), | ||
input = Y.one('.yui3-dial .yui3-dial-ring'); | ||
|
||
suite.add(new Y.Test.Case({ | ||
name: 'Example tests', | ||
|
||
'example dial initial value check': function() { | ||
Assert.areEqual('13000', output.getContent(), 'Failed to initialize dial value'); | ||
}, | ||
|
||
'dial keyboard major increment changes value and sprite position': function() { | ||
input.key(33); // up | ||
Assert.areEqual('13002', output.getContent(), 'Key "pageup" failed to increment value by major value'); | ||
Assert.areEqual('-600px 0px', Y.one('#duck').getStyle('backgroundPosition'), 'Failed to move duck sprite to right spot'); | ||
}, | ||
|
||
'dial keyboard left arrow equal minor decrement': function() { | ||
input.key(37); // left | ||
Assert.areEqual('13001', output.getContent(), '1 key arrow left failed decrement value by 1 minorStep'); | ||
Assert.areEqual('-300px 0px', Y.one('#duck').getStyle('backgroundPosition'), 'Failed to move duck sprite to right spot'); | ||
}, | ||
|
||
'dial keyboard home goes to min value': function() { | ||
input.key(36); // home | ||
Assert.areEqual('0', output.getContent(), 'key Home failed set value to min'); | ||
Assert.areEqual('0px 0px', Y.one('#duck').getStyle('backgroundPosition'), 'Failed to move duck sprite to min spot'); | ||
}, | ||
|
||
'dial keyboard end goes to max value': function() { | ||
input.key(35); // end | ||
Assert.areEqual('26000', output.getContent(), 'key End failed to set dial to min'); | ||
Assert.areEqual('0px 0px', Y.one('#duck').getStyle('backgroundPosition'), 'Failed to move duck sprite to max spot'); | ||
}, | ||
|
||
'duck sprite goes to original spot when center button is clicked.': function() { | ||
Y.one('.yui3-dial .yui3-dial-center-button').simulate("mousedown"); | ||
Assert.areEqual('13000', output.getContent(), 'Failed to move duck sprite to original spot on center button click'); | ||
} | ||
|
||
})); | ||
|
||
Y.Test.Runner.add(suite); | ||
|
||
}, '', { requires: [ 'dial', 'node-event-simulate' ] }); | ||
|
||
|
||
/*, | ||
*/ |