1
/* Copyright (c) 2009, Canonical Ltd. All rights reserved. */
3
YUI().use('lazr.anim', 'lazr.testing.runner', 'node',
4
'event', 'event-simulate', 'console', function(Y) {
6
var Assert = Y.Assert; // For easy access to isTrue(), etc.
8
var suite = new Y.Test.Suite("Anim Tests");
10
suite.add(new Y.Test.Case({
15
this.workspace = Y.one('#workspace');
17
Y.one(document.body).appendChild(Y.Node.create(
18
'<div id="workspace">'
19
+ '<table id="anim-table">'
20
+ '<tr id="anim-table-tr">'
21
+ '<td id="anim-table-td1" style="background: #eeeeee">foo</td>'
22
+ '<td id="anim-table-td2" style="background: #eeeeee">bar</td>'
23
+ '</tr></table></div>'));
24
this.workspace = Y.one('#workspace');
28
tearDown: function() {
29
this.workspace.get('parentNode').removeChild(this.workspace);
32
test_resolveNodeListFrom_selector: function() {
33
var nodelist = Y.lazr.anim.resolveNodeListFrom('#anim-table-td1');
34
var nodelist_nodes = (nodelist._nodes !== undefined);
35
Assert.isTrue(nodelist_nodes, 'Not a nodelist from a selector');
38
test_resolveNodeListFrom_node: function() {
39
var node = Y.one('#anim-table-td1');
40
var nodelist = Y.lazr.anim.resolveNodeListFrom(node);
41
var nodelist_nodes = (nodelist._nodes !== undefined);
42
Assert.isTrue(nodelist_nodes, 'Not a nodelist from a Node');
45
test_resolveNodeListFrom_node_list: function() {
46
var nodelist = Y.all('#anim-table td');
47
var nodelist = Y.lazr.anim.resolveNodeListFrom(nodelist);
48
var nodelist_nodes = (nodelist._nodes !== undefined);
49
Assert.isTrue(nodelist_nodes, 'Not a nodelist from a NodeList');
52
test_resolveNodeListFrom_anythine_else: function() {
55
var nodelist = Y.lazr.anim.resolveNodeListFrom(
56
{crazy: true, broken: 'definitely'});
60
Assert.isFalse(succeed, "Somehow, we're cleverer than we thought.");
63
test_green_flash_td1: function() {
64
// works as expected on a single node,
65
// without coercion into a NodeList here
66
var node = Y.one('#anim-table-td1');
67
var bgcolor = node.getStyle('backgroundColor');
68
var anim = Y.lazr.anim.green_flash(
70
to: {backgroundColor: bgcolor},
74
this.wait(function() {
77
node.getStyle('backgroundColor'),
78
'background colors do not match'
84
test_green_flash_td1_by_selector: function() {
85
// works as expected on a single node selector,
86
// without coercion into a NodeList here
87
var node = Y.one('#anim-table-td1');
88
var bgcolor = node.getStyle('backgroundColor');
89
var anim = Y.lazr.anim.green_flash(
90
{node: '#anim-table-td1',
91
to: {backgroundColor: bgcolor},
95
this.wait(function() {
98
node.getStyle('backgroundColor'),
99
'background colors do not match'
105
test_green_flash_multi: function() {
106
// works with a native NodeList as well
107
var nodelist = Y.all('#anim-table td');
109
var backgrounds = [];
110
Y.each(nodelist, function(n) {
111
backgrounds.push({bg: n.getStyle('backgroundColor'), node: n});
113
var anim = Y.lazr.anim.green_flash(
115
to: {backgroundColor: red},
119
this.wait(function() {
121
backgrounds[0].node.getStyle('backgroundColor'),
123
'background of 0 has mysteriously jumped to the end color.'
126
backgrounds[1].node.getStyle('backgroundColor'),
128
'background of 1 has mysteriously jumped to the end color.'
131
backgrounds[0].node.getStyle('backgroundColor'),
133
'background of 0 has not changed at all.'
136
backgrounds[1].node.getStyle('backgroundColor'),
138
'background of 1 has not changed at all.'
144
test_green_flash_multi_by_selector: function() {
145
// works with a native NodeList as well
146
var nodelist = Y.all('#anim-table td');
148
var backgrounds = [];
149
Y.each(nodelist, function(n) {
150
backgrounds.push({bg: n.getStyle('backgroundColor'), node: n});
152
var anim = Y.lazr.anim.green_flash(
153
{node: '#anim-table td',
154
to: {backgroundColor: red},
158
this.wait(function() {
160
backgrounds[0].node.getStyle('backgroundColor'),
162
'background of 0 has mysteriously jumped to the end color.'
165
backgrounds[1].node.getStyle('backgroundColor'),
167
'background of 1 has mysteriously jumped to the end color.'
170
backgrounds[0].node.getStyle('backgroundColor'),
172
'background of 0 has not changed at all.'
175
backgrounds[1].node.getStyle('backgroundColor'),
177
'background of 1 has not changed at all.'
184
Y.lazr.testing.Runner.add(suite);
185
Y.lazr.testing.Runner.run();