-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
152 lines (141 loc) · 5.64 KB
/
index.html
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Syncopate Test</title>
<script src="storage.js" type="text/javascript" charset="utf-8"></script>
<script src="qunit.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" title="no title" charset="utf-8"/>
</head>
<body>
<h1 id="qunit-header">Syncopate Test</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<script type="text/javascript" charset="utf-8">
var s = new Storage("test");
// s.logging = true;
module("Syncopate");
asyncTest("dropTable and createTable", function() {
expect(3);
s.dropTable("boxes", function() {
ok("dropped boxes");
s.dropTable("containers", function() {
ok("dropped containers");
s.createTable("boxes", {label: "string", contents: "string"}, function() {
ok("boxes table created");
start();
});
});
});
});
asyncTest("run finding no rows", function() {
s.run("SELECT COUNT(*) FROM boxes", function(res) {
var count = res.rows.item(0)["COUNT(*)"];
equals(count, 0);
start();
});
});
asyncTest("run finding a row after inserting", function() {
s.run("INSERT INTO boxes (label, contents) VALUES('Box A', 'Contents of Box A')", function(res) {
s.run("SELECT COUNT(*) FROM boxes", function(res) {
var count = res.rows.item(0)["COUNT(*)"];
equals(count, 1);
start();
});
});
});
asyncTest("renameTable should ensure count fails on original table name, works on new name", function() {
s.renameTable("boxes", "containers", function() {
s.count("boxes", {}, function(c) {}, function() {
ok("count from boxes failed");
s.count("containers", {}, function(c) {
equals(c, 1);
start();
});
});
});
});
asyncTest("addColumn followed by a write should ensure previously-nonexistant col exists when read", function() {
expect(3);
s.read("containers", null, null, function(rows) {
var record = rows[0];
equals(record.number, null);
s.addColumn("containers", "number", "number", function() {
ok("added number col to containers table");
record.number = 7;
s.write("containers", record, function() {
s.read("containers", null, null, function(rows) {
equals(rows[0].number, 7);
start();
});
});
});
});
});
asyncTest("3 writes, a conditional count and conditional read", function() {
expect(5);
var containerA = {label: "Example Container", contents: "stuff inside the container", number: 13};
s.write("containers", containerA, function() {
ok("wrote example container");
var containerB = {label: "Another Example", contents: "stuff inside the other", number: 23};
s.write("containers", containerB, function() {
ok("wrote another example container");
s.count("containers", {label: ["like", "%Example%"]}, function(c) {
equals(c, 2);
s.read("containers", {number: [">", 10]}, {order: "number"}, function(rows) {
equals(rows.length, 2);
equals(rows[1].number, 23);
start();
});
});
});
});
});
asyncTest("using update to change multiple rows", function() {
expect(2);
s.count("containers", {label: "updated label"}, function(c) {
equals(c, 0);
s.update("containers", {label: "updated label"}, {number: [">", 10]}, function() {
s.count("containers", {label: "updated label"}, function(c) {
equals(c, 2);
start();
});
});
});
});
asyncTest("erasing a row conditionally", function() {
expect(3);
s.count("containers", null, function(c) {
equals(c, 3);
s.erase("containers", {label: "updated label"}, function() {
ok("erased rows");
s.count("containers", null, function(c) {
equals(c, 1);
start();
});
});
});
});
asyncTest("finding a row just inserted by using the IN operator w/ array syntax", function() {
var labelValues = ["Fruit", "Nuts", "Nunchuku"];
s.write("containers", {label: labelValues[Math.floor(Math.random() * 3)], contents: "Contents of Container"}, function() {
s.count("containers", {label: ['IN', labelValues]}, function(c) {
equals(c, 1);
start();
});
});
});
asyncTest("finding a row just inserted by using the IN operator w/ string syntax", function() {
var labelValues = ["Fruit", "Nuts", "Nunchuku"];
s.write("containers", {label: labelValues[Math.floor(Math.random() * 3)], contents: "Contents of Container"}, function() {
s.count("containers", {label: ['IN', "('" + labelValues.join("','") + "')"]}, function(c) {
equals(c, 2);
start();
});
});
});
</script>
</body>
</html>