forked from nervetattoo/jquery-autosave
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.autosave.test.js
117 lines (116 loc) · 4.05 KB
/
jquery.autosave.test.js
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
$(function() {
/**
* Tests
*/
test("full form submit", function() {
stop();
$("form#one").autosave({
success: function(data) {
start();
equals('foo', data.a, "Expecting value foo for a(input#1)");
equals('foo', data.b, "Expecting value foo for b(input#2)");
equals('foobar', data.c, "Expecting value foobar for c(textarea)");
ok(!("foo" in data), 'Button should not be included');
},
send: defaultAutosaveSendVisualizer
});
// Set some value on form
$("form#one input").val('foo');
$("form#one textarea").val('foobar');
$("form#one").trigger('submit');
});
test("full form submit by button click", function() {
stop();
$("form#one").autosave({
success: function(data) {
start();
equals('foo', data.a, "Expecting value foo for a(input#1)");
equals('foo', data.b, "Expecting value foo for b(input#2)");
equals('foobar', data.c, "Expecting value foobar for c(textarea)");
ok(("foo" in data), 'Button should be included');
}
});
// Set some value on form
$("form#one input").val('foo');
$("form#one textarea").val('foobar');
$("form#one button").trigger('click');
});
test("input and button list by input change", function() {
stop();
$("#one input,#one button").autosave({
grouped:true,
success: function(data) {
start();
equals(data.a, 'foo', "Expecting value foo for a(input#1)");
equals(data.b, 'foo', "Expecting value foo for b(input#2)");
ok(!("foo" in data), 'Button should not be included');
}
});
// Set some value on form
$("#one input").val('foo');
$("#one input:first-child").trigger('change');
});
test("input and button list by button click", function() {
stop();
$("#one input,#one button").autosave({
grouped:true,
success: function(data) {
start();
equals(data.a, 'foo', "Expecting value foo for a(input#1)");
equals(data.b, 'foo', "Expecting value foo for b(input#2)");
ok(("foo" in data), 'Button should not be included');
}
});
// Set some value on form
$("#one input").val('foo');
$("#one button").trigger('click');
});
test("single element submit", function() {
stop();
var nodes = $("form#one input");
var node = $("form#one input[name=a]");
nodes.autosave({
success: function(data) {
start();
equals(data.a, 'foo', "Expecting value foo");
stop();
}
});
// Set some value on form
nodes.val('foo');
node.trigger('change');
});
test("grouped element submit", function() {
stop();
var nodes = $("form#one input");
var node = $("form#one input[name=a]");
nodes.autosave({
grouped: true,
success: function(data) {
start();
equals(data.b, 'foo', "Expecting value foo for b");
equals(data.b, 'foo', "Expecting value foo for a");
stop();
}
});
// Set some value on form
nodes.val('foo');
node.trigger('change');
});
test("non grouped element submit", function() {
stop();
var nodes = $("form#one input");
var node = $("form#one input[name=a]");
nodes.autosave({
success: function(data) {
start();
equals(data.a,'foo', "Expecting value foo for a");
ok(!("b" in data), "b should not be in data");
stop();
}
});
// Set some value on form
nodes.val('foo');
node.trigger('change');
});
});