transition.html revision 2e49faa8717cc2acbd7ab2aac237061848568a6c
<!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;
}
.demo div {
width: 200px;
height: 200px;
}
</style>
</head>
<body class="yui3-skin-sam">
<h1>Transition Tests</h1>
<div class="demo"><div></div></div>
<div class="demo"><div></div></div>
<script type="text/javascript">
YUI({
filter: "raw",
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: 'property onend Tests',
'should run the onend for the property': function() {
var node = Y.one('.demo'),
test = this;
node.transition({
height: {
value: 0,
on: {
end: function() {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('height'));
node.setStyle('height', '');
});
}
}
}
});
test.wait(1000);
}
}));
suite.add(new Y.Test.Case({
name: 'onstart Tests',
'should run the onstart prior to setting target values': function() {
var node = Y.one('.demo'),
test = this,
h = node.getComputedStyle('height'),
onstart = function() {
node.setStyle('height', 0);
};
node.setStyle('height', h);
node.transition({
height: function() {
return h;
},
on: {
start: onstart
}
}, function() {
test.resume(function() {
Y.Assert.areEqual(h, node.getComputedStyle('height'));
node.setStyle('height', '');
});
});
test.wait(1000);
}
}));
suite.add(new Y.Test.Case({
name: 'onend Tests',
'should run the onend after transition completes': function() {
var node = Y.one('.demo'),
test = this;
onend = function() {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('height'));
node.setStyle('height', '');
});
};
node.transition({
height: 0,
on: {
end: onend
}
});
test.wait(1000);
},
'should run the onend before callback': function() {
var node = Y.one('.demo'),
test = this,
h = node.getComputedStyle('height'),
onend = function() {
test.resume(function() {
Y.Assert.areEqual(h, node.getComputedStyle('height'));
node.setStyle('height', h);
test.wait(1000);
});
};
node.setStyle('height', 0);
node.transition({
height: function() {
return h;
},
on: {
end: onend
}
}, function() {
test.resume(function() {
Y.Assert.areEqual(h, node.getComputedStyle('height'));
node.setStyle('height', '');
});
});
test.wait(1000);
}
}));
suite.add(new Y.Test.Case({
name: 'Show Transition Tests',
'should show the node with the default transition': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('display', 'none');
node.setStyle('opacity', '0');
node.show(true);
Y.later(750, null, function() {
test.resume(function() {
Y.Assert.areEqual(1, node.getStyle('opacity'));
Y.Assert.areEqual('block', node.getStyle('display'));
});
});
test.wait(1000);
},
'should show the node with the default transition and fire callback': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('display', 'none');
node.setStyle('opacity', '0');
node.show(true, function() {
test.resume(function() {
Y.Assert.areEqual(1, node.getStyle('opacity'));
Y.Assert.areEqual('block', node.getStyle('display'));
});
});
test.wait(1000);
},
'should show the node with the named transition': function() {
var node = Y.one('.demo'),
test = this,
h = node.getComputedStyle('height'),
w = node.getComputedStyle('width');
node.setStyles({
height: 0,
width: 0
});
node.show('sizeIn');
Y.later(750, null, function() {
test.resume(function() {
Y.Assert.areEqual(h, node.getComputedStyle('height'));
Y.Assert.areEqual(w, node.getComputedStyle('width'));
});
});
test.wait(1000);
},
'should show the node with the named transition using passed config': function() {
var node = Y.one('.demo'),
test = this,
h = node.getComputedStyle('height'),
w = node.getComputedStyle('width');
node.setStyles({
height: 0,
width: 0,
opacity: 0
});
Y.Assert.areEqual(0, node.getComputedStyle('opacity'));
node.show('sizeIn', {
opacity: 1
});
Y.later(750, null, function() {
test.resume(function() {
Y.Assert.areEqual(h, node.getComputedStyle('height'));
Y.Assert.areEqual(w, node.getComputedStyle('width'));
Y.Assert.areEqual(1, node.getComputedStyle('opacity'));
});
});
test.wait(1000);
},
'should show the node with the named transition and fire callback': function() {
var node = Y.one('.demo'),
test = this,
h = node.getComputedStyle('height'),
w = node.getComputedStyle('width');
node.setStyles({
height: 0,
width: 0
});
node.show('sizeIn', function() {
test.resume(function() {
Y.Assert.areEqual(h, node.getComputedStyle('height'));
Y.Assert.areEqual(w, node.getComputedStyle('width'));
});
});
test.wait(1000);
},
'should override the default duration': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('opacity', 0);
node.show({duration: 1}, function(e) {
test.resume(function() {
Y.Assert.areEqual(1, parseInt(e.elapsedTime));
});
});
test.wait(2000);
}
}));
suite.add(new Y.Test.Case({
name: 'Hide Transition Tests',
'should hide the node with the default transition': function() {
var node = Y.one('.demo'),
test = this;
node.hide(true, function() {
test.resume(function() {
Y.Assert.areEqual(0, node.getStyle('opacity'));
Y.Assert.areEqual('none', node.getStyle('display'));
node.setStyle('display', 'block');
node.setStyle('opacity', '1');
});
});
Y.Assert.areEqual('block', node.getStyle('display'));
test.wait(1000);
}
}));
suite.add(new Y.Test.Case({
name: 'Named Transition Tests',
/* serial effects not yet implemented
'should run named effects in serial': function() {
var node = Y.one('.demo'),
test = this;
node.transition(['fadeOut', 'fadeIn'], function(e) {
test.resume(function() {
Y.Assert.areEqual(2, parseInt(e.elapsedTime));
});
});
test.wait(3000);
},
*/
'should run named effect': function() {
var node = Y.one('.demo'),
test = this;
node.transition('fadeOut');
Y.later(750, null, function(e) {
test.resume(function() {
Y.Assert.areEqual(0, node.getStyle('opacity'));
});
});
test.wait(1000);
},
'should run named effect with passed config': function() {
var node = Y.one('.demo'),
test = this;
node.transition('fadeOut', {height: '0px'});
Y.later(750, null, function(e) {
test.resume(function() {
Y.Assert.areEqual(0, node.getStyle('opacity'));
Y.Assert.areEqual('0px', node.getStyle('height'));
//node.setStyle('opacity', 1);
});
});
test.wait(1000);
},
'should run named effect and fire callback': function() {
var node = Y.one('.demo'),
test = this;
node.transition('fadeOut', function(e) {
test.resume(function() {
Y.Assert.areEqual(0, node.getStyle('opacity'));
});
});
test.wait(4000);
},
'should override effect duration': function() {
var node = Y.one('.demo'),
test = this;
node.transition('fadeIn', {duration: 2}, function(e) {
test.resume(function() {
Y.Assert.areEqual(2, parseInt(e.elapsedTime));
Y.Assert.areEqual(1, node.getStyle('opacity'));
});
});
test.wait(3000);
}
}));
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(1000);
});
});
test.wait(1000);
},
'setStyle should not transition 1': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('height', '100px');
Y.Assert.areEqual('100px', node.getComputedStyle('height'));
},
'last transition should win for same property': function() {
var node = Y.one('.demo'),
test = this;
node.transition({
height: '100px'
}, function(e) {
test.resume(function() { // shouldnt fire
Y.Assert.isNull(1);
});
});
node.transition({
height: 0
}, function(e) {
test.resume(function() { // shouldnt fire
Y.Assert.isNull(1);
});
});
node.transition({
height: '100px'
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('100px', node.getComputedStyle('height'));
});
});
test.wait(2000);
},
'setStyle should not transition 2': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('height', '100px');
Y.Assert.areEqual('100px', node.getComputedStyle('height'));
},
'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(2000);
});
});
test.wait(2000);
},
'setStyle should not transition 3': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('height', '100px');
Y.Assert.areEqual('100px', node.getComputedStyle('height'));
},
'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(2000);
});
});
node.transition({
duration: 2,
height: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('height'));
});
});
test.wait(2000);
},
'setStyle should not transition 4': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('height', '100px');
Y.Assert.areEqual('100px', node.getComputedStyle('height'));
},
'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(2000);
});
});
node.transition({
duration: 1,
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('width'));
});
});
test.wait(2000);
},
'setStyle should not transition 5': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('width', '100px');
Y.Assert.areEqual('100px', node.getComputedStyle('width'));
},
'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(2000);
});
});
test.wait(2500);
},
'setStyle should not transition 6': 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 Element Tests',
setUp: function() {
Y.all('.demo').setStyles({
height: '200px',
width: '200px',
opacity: '1'
});
},
'multiple elements should transition together': function() {
var nodes = Y.all('.demo'),
node1 = nodes.item(0),
node2 = nodes.item(1),
test = this;
node1.transition({
duration: 1,
height: 0
});
node2.transition({
height: '100px',
duration: 2
}, function(e) {
test.resume(function () {
Y.Assert.areEqual('0px', node1.getComputedStyle('height'), 'item 1 height');
Y.Assert.areEqual('100px', node2.getComputedStyle('height'), 'item 2 height');
Y.Assert.areEqual(2, parseInt(e.elapsedTime));
});
});
test.wait(2500);
},
'nodelist should transition together': function() {
var test = this,
resumed = false;
Y.all('.demo').transition({duration: 1, opacity: 0}, function(e) {
if (!resumed) {
test.resume(function() {
resumed = true;
var nodes = Y.all('.demo');
Y.Assert.areEqual(0, nodes.item(0).getStyle('opacity'));
Y.Assert.areEqual(1, parseInt(e.elapsedTime));
});
}
});
test.wait(2000);
}
}));
suite.add(new Y.Test.Case({
name: 'Single Transition Tests',
setUp: function() {
Y.all('.demo').setStyles({
height: '200px',
width: '200px',
borderWidth: '5px',
paddingTop: 0,
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(2000);
},
'should end at both final values': function() {
var node = Y.one('.demo'),
test = this;
node.transition({
opacity: {
easing: 'ease-out',
duration: 1.25,
value: 0
},
height: {
delay:1.25,
easing: 'ease-out',
value: 0
}
}, function(e) {
test.resume(function() {
Y.Assert.areEqual('0px', node.getComputedStyle('height'));
Y.Assert.areEqual('0', node.getComputedStyle('opacity'));
});
});
test.wait(2000);
},
'callback should fire when transitioning to current value': function() {
var node = Y.one('.demo'),
test = this;
node.transition({
duration: 1,
height: '200px',
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual(1, parseInt(e.elapsedTime));
Y.Assert.areEqual('200px', node.getComputedStyle('height'));
Y.Assert.areEqual('0px', node.getComputedStyle('width'));
});
});
test.wait(2000);
},
'callback should fire when transitioning to current number value': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('width', 0);
node.transition({
duration: 1,
width: 0
}, function(e) {
test.resume(function() {
Y.Assert.areEqual(1, parseInt(e.elapsedTime));
Y.Assert.areEqual('0px', node.getComputedStyle('width'));
});
});
test.wait(2000);
},
'should end at all final values': function() {
var node = Y.one('.demo'),
test = this;
node.transition({
duration: 1,
width: 0,
height: 0,
opacity: 0,
borderTopWidth: '1px',
foo: 0, // ignore non-supported
paddingTop: '100px'
}, 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'));
Y.Assert.areEqual('100px', node.getComputedStyle('paddingTop'));
Y.Assert.areEqual('1px', node.getStyle('borderTopWidth'));
});
});
test.wait(2000);
},
'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(3000);
},
/* deprecated
'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);
},
*/
'native transform should map to vendor prefix': function() {
var node = Y.one('.demo'),
test = this;
node.transition({
easing: 'ease',
duration: 1,
height: 0,
transform: 'rotate(180deg)'
}, function(e) {
test.resume(function() {
Y.Assert.areEqual(1, parseInt(e.elapsedTime));
node.setStyle('height', '100px');
if (Y.UA.webkit) {
Y.Assert.areEqual('matrix(-1, 0.00000000000000012246467991473532, -0.00000000000000012246467991473532, -1, 0, 0)', node.getComputedStyle('WebkitTransform'));
}
});
});
test.wait(2000);
},
'setStyle should not transition': function() {
var node = Y.one('.demo'),
test = this;
node.setStyle('height', '100px');
Y.Assert.areEqual('100px', node.getComputedStyle('height'));
},
'destroyed node should complete transition': function() {
var node = Y.one('.demo'),
test = this;
node.transition({
easing: 'ease',
duration: 1,
height: 0
}, function(e) {
test.resume(function() {
var node = Y.one('.demo');
Y.Assert.areEqual(1, parseInt(e.elapsedTime));
Y.Assert.areEqual('0px', node.getComputedStyle('height'));
});
});
node.destroy();
test.wait(2000);
}
}));
suite.add(new Y.Test.Case({
name: 'toggleView Tests',
'should force state with boolean first arg': function() {
var node = Y.one('.demo'),
test = this;
node.toggleView(false, function() {
test.resume(function() {
Y.Assert.areEqual(0, node.getStyle('opacity'));
node.destroy();
})
});
test.wait(2000);
}
}));
//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>