1
/* Copyright (c) 2009, Canonical Ltd. All rights reserved. */
7
}).use('lazr.anim', 'lazr.testing.runner', 'node',
8
'event', 'event-simulate', 'console', function(Y) {
10
var Assert = Y.Assert; // For easy access to isTrue(), etc.
12
var suite = new Y.Test.Suite("Anim Tests");
14
suite.add(new Y.Test.Case({
19
this.workspace = Y.one('#workspace');
21
Y.one(document.body).appendChild(Y.Node.create(
22
'<div id="workspace">'
23
+ '<table id="anim-table">'
24
+ '<tr id="anim-table-tr">'
25
+ '<td id="anim-table-td1" style="background: #eeeeee">foo</td>'
26
+ '<td id="anim-table-td2" style="background: #eeeeee">bar</td>'
27
+ '</tr></table></div>'));
28
this.workspace = Y.one('#workspace');
32
tearDown: function() {
33
this.workspace.get('parentNode').removeChild(this.workspace);
36
test_resolveNodeListFrom_selector: function() {
37
var nodelist = Y.lazr.anim.resolveNodeListFrom('#anim-table-td1');
38
var nodelist_nodes = (nodelist._nodes !== undefined);
39
Assert.isTrue(nodelist_nodes, 'Not a nodelist from a selector');
42
test_resolveNodeListFrom_node: function() {
43
var node = Y.one('#anim-table-td1');
44
var nodelist = Y.lazr.anim.resolveNodeListFrom(node);
45
var nodelist_nodes = (nodelist._nodes !== undefined);
46
Assert.isTrue(nodelist_nodes, 'Not a nodelist from a Node');
49
test_resolveNodeListFrom_node_list: function() {
50
var nodelist = Y.all('#anim-table td');
51
var nodelist = Y.lazr.anim.resolveNodeListFrom(nodelist);
52
var nodelist_nodes = (nodelist._nodes !== undefined);
53
Assert.isTrue(nodelist_nodes, 'Not a nodelist from a NodeList');
56
test_resolveNodeListFrom_anythine_else: function() {
59
var nodelist = Y.lazr.anim.resolveNodeListFrom(
60
{crazy: true, broken: 'definitely'});
64
Assert.isFalse(succeed, "Somehow, we're cleverer than we thought.");
67
test_green_flash_td1: function() {
68
// works as expected on a single node,
69
// without coercion into a NodeList here
70
var node = Y.one('#anim-table-td1');
71
var bgcolor = node.getStyle('backgroundColor');
72
var anim = Y.lazr.anim.green_flash(
74
to: {backgroundColor: bgcolor},
78
this.wait(function() {
81
node.getStyle('backgroundColor'),
82
'background colors do not match'
88
test_green_flash_td1_by_selector: function() {
89
// works as expected on a single node selector,
90
// without coercion into a NodeList here
91
var node = Y.one('#anim-table-td1');
92
var bgcolor = node.getStyle('backgroundColor');
93
var anim = Y.lazr.anim.green_flash(
94
{node: '#anim-table-td1',
95
to: {backgroundColor: bgcolor},
99
this.wait(function() {
102
node.getStyle('backgroundColor'),
103
'background colors do not match'
109
test_green_flash_multi: function() {
110
// works with a native NodeList as well
111
var nodelist = Y.all('#anim-table td');
113
var backgrounds = [];
114
Y.each(nodelist, function(n) {
115
backgrounds.push({bg: n.getStyle('backgroundColor'), node: n});
117
var anim = Y.lazr.anim.green_flash(
119
to: {backgroundColor: red},
123
this.wait(function() {
125
backgrounds[0].node.getStyle('backgroundColor'),
127
'background of 0 has mysteriously jumped to the end color.'
130
backgrounds[1].node.getStyle('backgroundColor'),
132
'background of 1 has mysteriously jumped to the end color.'
135
backgrounds[0].node.getStyle('backgroundColor'),
137
'background of 0 has not changed at all.'
140
backgrounds[1].node.getStyle('backgroundColor'),
142
'background of 1 has not changed at all.'
148
test_green_flash_multi_by_selector: function() {
149
// works with a native NodeList as well
150
var nodelist = Y.all('#anim-table td');
152
var backgrounds = [];
153
Y.each(nodelist, function(n) {
154
backgrounds.push({bg: n.getStyle('backgroundColor'), node: n});
156
var anim = Y.lazr.anim.green_flash(
157
{node: '#anim-table td',
158
to: {backgroundColor: red},
162
this.wait(function() {
164
backgrounds[0].node.getStyle('backgroundColor'),
166
'background of 0 has mysteriously jumped to the end color.'
169
backgrounds[1].node.getStyle('backgroundColor'),
171
'background of 1 has mysteriously jumped to the end color.'
174
backgrounds[0].node.getStyle('backgroundColor'),
176
'background of 0 has not changed at all.'
179
backgrounds[1].node.getStyle('backgroundColor'),
181
'background of 1 has not changed at all.'
188
Y.lazr.testing.Runner.add(suite);
189
Y.lazr.testing.Runner.run();