transition.html revision 85a258143f630b36522d3d1835a8e5a916dbad2c
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Transition tests</title>
<link type="text/css" rel="stylesheet" href="/build/logreader/assets/skins/sam/logreader.css">
<script type="text/javascript" src="/build/yui/yui.js"></script>
<style>
#demo {
background: #ccc;
border: 5px solid green;
width: 200px;
height: 200px;
}
</style>
</head>
<body class="yui3-skin-sam">
<h1>Transition Tests</h1>
<div id="demo"></div>
<script type="text/javascript">
YUI({
filter: "debug",
logInclude: { TestRunner: true }
}).use('transition', 'test', 'console', function (Y) {
Y.namespace('Tests');
Y.Tests.Transition = (function(){
var suite = new Y.Test.Suite('Transition Tests');
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);
}
}));
suite.add(new Y.Test.Case({
name: 'Single Transition Tests',
setUp: function() {
var node = Y.one('#demo');
if (node) {
node.setStyles({
height: '200px',
width: '200px',
opacity: '1'
});
}
},
'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({
width: 0,
height: 0,
opacity: 0
}, function(e) {
test.resume(function() {
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'));
}
}));
//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>