forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.transit-tests.ts
93 lines (79 loc) · 3.31 KB
/
jquery.transit-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
///<reference path="../jquery/jquery.d.ts" />
///<reference path="jquery.transit.d.ts" />
class TransitOptions implements JQueryTransitOptions {
opacity: number;
duration: number;
delay: number;
easing: string;
complete: () => void;
scale: any;
}
$(document).ready(function () {
test_opacity();
test_scale();
test_duration();
// Wait for all tests to complete and report results
setTimeout(Assert.Results, 2000);
});
class Assert {
static totalTests: number = 0;
static passedTests: number = 0;
static Results() {
console.log('Tests succeeded - ' + this.passedTests + '/' + this.totalTests + '; Tests failed - ' + (this.totalTests - this.passedTests) + '/' + this.totalTests);
}
static AssertionFailed(actual: any, expected: any, test: string) {
console.log((test || '') + ' assertion failed -- expected ' + expected.toString() + '; actual ' + actual.toString());
}
static Equal(actual: any, expected: any, test?: string) {
this.totalTests++;
if (actual === expected) {
this.passedTests++;
return;
}
this.AssertionFailed(actual, expected, test);
}
static NotEqual(actual: any, expected: any, test?: string) {
this.totalTests++;
if (actual !== expected) {
this.passedTests++;
return;
}
this.AssertionFailed(actual, expected, test);
}
}
function test_signatures() {
var TestObject = $('<div>');
var options = new TransitOptions();
options.opacity = 50;
options.duration = 250;
TestObject.css("scale", 2);
TestObject.transition(options);
TestObject.transition(options, 500);
TestObject.transition(options, 'in');
TestObject.transition(options, function () { var test: boolean = true; });
TestObject.transition(options, 500, 'out');
TestObject.transition(options, 500, 'in-out', function () { var test: boolean = true; });
}
function test_opacity() {
var TestObject = $('<div>');
TestObject.css('opacity', 25);
Assert.Equal(TestObject.attr('style'), 'opacity: 25;', 'Opacity pre-transition test');
TestObject.transition({ opacity: 75, duration: 1, complete: function () { Assert.Equal(TestObject.attr('style'), 'opacity: 75;', 'Opacity transition test'); } });
}
function test_scale() {
var TestObject = $('<div>');
TestObject.css('scale', 0.5);
Assert.Equal(TestObject.attr('style'), 'transform: scale(0.5, 0.5);', 'Scale pre-transition test');
TestObject.transition({ scale: 2, duration: 1, complete: function () { Assert.Equal(TestObject.attr('style'), 'transform: scale(2, 2);', 'Scale transition test'); } });
TestObject.css('scale', [0.5, 1.0]);
Assert.Equal(TestObject.attr('style'), 'transform: scale(0.5, 1);', 'Scale pre-transition test');
TestObject.transition({ scale: [2, 3], duration: 1, complete: function () { Assert.Equal(TestObject.attr('style'), 'transform: scale(2, 3);', 'Scale transition test'); } });
}
function test_duration() {
var TestObject = $('<div>');
TestObject.css('opacity', 25);
Assert.Equal(TestObject.attr('style'), 'opacity: 25;', 'Duration pre-transition test');
TestObject.transition({ opacity: 75, duration: 1000, complete: function () { Assert.Equal(TestObject.attr('style'), 'opacity: 75;', 'Duration post-transition test'); } });
// Test the transitions state partway through and assert that we're not to our final state yet.
setTimeout(function () { Assert.NotEqual(TestObject.attr('style'), 'opacity: 75;', 'Duration intra-transition test'); }, 300);
}