transition.html revision 49b2441cfaf50222c256670b81ff734d8be3f9a4
881N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
881N/A<html>
881N/A<head>
881N/A<title>Transition tests</title>
881N/A<link type="text/css" rel="stylesheet" href="/build/logreader/assets/skins/sam/logreader.css">
881N/A<script type="text/javascript" src="/build/yui/yui.js"></script>
881N/A<style>
881N/A#demo {
881N/A background: #ccc;
881N/A border: 5px solid green;
881N/A width: 200px;
881N/A height: 200px;
881N/A}
881N/A</style>
881N/A</head>
881N/A<body class="yui3-skin-sam">
881N/A <h1>Transition Tests</h1>
881N/A <div id="demo"></div>
881N/A
881N/A<script type="text/javascript">
881N/AYUI({
881N/A filter: "debug",
881N/A logInclude: { TestRunner: true }
881N/A}).use('transition', 'test', 'console', function (Y) {
881N/A Y.namespace('Tests');
881N/A Y.Tests.Transition = (function(){
881N/A var suite = new Y.Test.Suite('Transition Tests');
881N/A
881N/A suite.add(new Y.Test.Case({
881N/A name: 'Single Transition Tests',
881N/A setUp: function() {
881N/A var node = Y.one('#demo');
881N/A if (node) {
881N/A node.setStyles({
881N/A height: '200px',
881N/A width: '200px',
881N/A opacity: '1'
881N/A });
881N/A }
},
'should end at final value': function() {
var node = Y.one('#demo'),
test = this;
node.transition({
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('width'));
});
});
test.wait(4000);
},
'should end at final values': function() {
var node = Y.one('#demo'),
test = this;
node.transition({
duration: 1,
width: 0,
height: 0,
opacity: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual(1, parseInt(e.elapsedTime));
Y.Assert.areEqual('0px', node.getComputedStyle('width'));
Y.Assert.areEqual('0px', node.getComputedStyle('height'));
Y.Assert.areEqual('0', node.getComputedStyle('opacity'));
});
});
test.wait(4000);
},
'callback should fire after longest duration': function() {
var node = Y.one('#demo'),
test = this;
node.transition({
easing: 'ease-in',
duration: 1,
opacity: {
value: 0,
duration: 2
},
height: 0,
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual(2, parseInt(e.elapsedTime));
node.setStyle('height', '100px');
node.setStyle('opacity', '1');
Y.Assert.areEqual(1, node.getStyle('opacity'));
});
});
test.wait(4000);
},
'transition:end should fire after longest duration': function() {
var node = Y.one('#demo'),
test = this,
config = {
easing: 'ease-in',
duration: 1,
opacity: {
value: 0,
duration: 2
},
height: 0,
width: 0
};
node.once('transition:end', function(e) {
test.resume(function() {
Y.Assert.areEqual(2, parseInt(e.elapsedTime));
Y.Assert.areSame(config, e.config);
node.setStyle('height', '100px');
node.setStyle('opacity', '1');
Y.Assert.areEqual(1, node.getStyle('opacity'));
});
});
node.transition(config);
test.wait(4000);
},
'setStyle should not transition': function() {
var node = Y.one('#demo'),
test = this;
node.setStyle('height', '100px');
Y.Assert.areEqual('100px', node.getComputedStyle('height'));
}
}));
suite.add(new Y.Test.Case({
name: 'Multiple Transition Tests',
setUp: function() {
Y.one('#demo').setStyles({
height: '200px',
width: '200px',
opacity: '1'
});
},
'all chained callbacks should fire': function() {
var node = Y.one('#demo'),
test = this;
node.transition({
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('width'));
node.transition({
height: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('height'));
});
});
test.wait();
});
});
test.wait(4000);
},
'last transition should win for same property': function() {
var node = Y.one('#demo'),
test = this;
node.transition({
opacity: 1
}, function(e) {
test.resume(function() { // shouldnt fire
Y.Assert.isNull(1);
});
});
node.transition({
opacity: 0
}, function(e) {
test.resume(function() { // shouldnt fire
Y.Assert.isNull(1);
});
});
node.transition({
opacity: 1
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('1', node.getComputedStyle('opacity'));
});
});
test.wait(4000);
},
'all serial callbacks should fire': function() {
var node = Y.one('#demo'),
test = this;
node.transition({
duration: 2,
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('width'));
});
});
node.transition({
duration: 1,
height: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('height'));
test.wait(4000);
});
});
test.wait(4000);
},
'all serial callbacks should fire (duration)': function() {
var node = Y.one('#demo'),
test = this;
node.transition({
duration: 1,
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('width'));
test.wait(4000);
});
});
node.transition({
duration: 2,
height: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('height'));
});
});
test.wait(4000);
},
'parallel transition should steal attribute': function() {
var node = Y.one('#demo'),
test = this;
node.transition({
width: 0
}, function(e) { // should never fire
test.resume(function() {
Y.Assert.isNull(1);
test.wait(4000);
});
});
node.transition({
duration: 1,
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('width'));
});
});
test.wait(4000);
},
'parallel transition should shorten duration': function() {
var node = Y.one('#demo'),
test = this;
node.transition({
easing: 'ease-in',
duration: 2,
opacity: {
value: 0,
duration: 3
},
height: 0,
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual(2, parseInt(e.elapsedTime));
});
});
node.transition({
duration: 1,
opacity: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0', node.getComputedStyle('opacity'));
Y.Assert.areEqual(1, parseInt(e.elapsedTime));
test.wait(4000);
});
});
test.wait(4000);
}
}));
//return it
return suite;
})();
new Y.Console({
verbose : true,
height: 600,
newestOnTop : false
}).render();
//add to the testrunner and run
Y.Test.Runner.add(Y.Tests.Transition);
Y.Test.Runner.run();
/*if (parent && parent != window) {
YAHOO.tool.TestManager.load();
} else {
YAHOO.tool.TestRunner.run();
}*/
});
</script>
</body>
</html>