Skip to content

Commit

Permalink
fixes #2532401 - dial: added automated example tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jconniff committed Jun 15, 2012
1 parent 44e6fee commit 07e3958
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 3 deletions.
70 changes: 70 additions & 0 deletions src/dial/docs/assets/dial-basic-tests.js
@@ -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' ] });


/*,
*/
70 changes: 70 additions & 0 deletions src/dial/docs/assets/dial-image-background-tests.js
@@ -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' ] });


/*,
*/
75 changes: 75 additions & 0 deletions src/dial/docs/assets/dial-image-surrounding-tests.js
@@ -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' ] });


/*,
*/
6 changes: 3 additions & 3 deletions src/dial/docs/assets/dial-interactive-tests.js
Expand Up @@ -39,14 +39,14 @@ YUI.add('dial-interactive-tests', function(Y) {

'dial keyboard major increment changes value and scene': function() {
input.key(33); // up
Assert.areEqual('10.00', output.getContent(), 'Failed to initialize dial to zero');
Assert.areEqual('10.00', output.getContent(), 'Key "pageup" failed to increment value by major value');
Assert.areEqual('-5490px', Y.one('#scene').getStyle('top'), 'Failed to move scene when 1 major keyboard increment');
},

'dial keyboard minor increment': function() {
input.key(37); // left
input.key(37); // left
Assert.areEqual('-5510px', Y.one('#scene').getStyle('top'), 'Failed to move scene when 2 minor keyboard increments');
Assert.areEqual('-5510px', Y.one('#scene').getStyle('top'), '2 key arrow lefts failed to move scene 2 minor keyboard increments');
},

'scene goes to Hubble when Hubble link is clicked.': function() {
Expand All @@ -63,7 +63,7 @@ YUI.add('dial-interactive-tests', function(Y) {

'dial keyboard end goes to max (Hubble) value': function() {
input.key(35); // end
Assert.areEqual('559.00', output.getContent(), 'Home key failed to set dial to min');
Assert.areEqual('559.00', output.getContent(), 'End key failed to set dial to min');
Assert.areEqual('0px', Y.one('#scene').getStyle('top'), 'Failed to move scene to show Hubble');
},

Expand Down
70 changes: 70 additions & 0 deletions src/dial/docs/assets/dial-text-input-tests.js
@@ -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' ] });


/*,
*/
73 changes: 73 additions & 0 deletions src/dial/docs/assets/duck-tests.js
@@ -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' ] });


/*,
*/

0 comments on commit 07e3958

Please sign in to comment.