forked from dexie/Dexie.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests-extendability.js
110 lines (91 loc) · 3.79 KB
/
tests-extendability.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
import Dexie from 'dexie';
import {module, stop, start, asyncTest, equal, ok} from 'QUnit';
module("extendability");
asyncTest("recursive-pause", function () {
var db = new Dexie("TestDB");
db.version(1).stores({
activities: "Oid,Task,Tick,Tock,Type,Flags",
tasks: "Oid,Name,Parent"
});
var Activity = db.activities.defineClass({
Oid: String,
Task: String,
Tick: Number,
Tock: Number,
Type: Number,
Flags: Number
});
db.on('populate', function () {
db.tasks.add({ Oid: "T1", Name: "The root task" });
db.tasks.add({ Oid: "T2", Name: "The child task", Parent: "T1" });
db.activities.add({ Oid: "A1", Task: "T2", Tick: 0, Tock: 10, Type: 1 });
db.activities.add({ Oid: "A2", Task: "T2", Tick: 100, Tock: 110, Type: 1 });
db.activities.add({ Oid: "A3", Task: "T2", Tick: 200, Tock: 210, Type: 2 });
});
db.delete().then(()=>{
return db.open();
}).then(()=>{
return db.transaction("rw", db.activities, db.tasks, function () {
Dexie.Promise.newPSD(function () {
Dexie.currentTransaction._lock();
db.activities.where("Type").equals(2).modify({ Flags: 2 }).finally(function () {
Dexie.currentTransaction._unlock();
});
});
db.activities.where("Flags").equals(2).count(function (count) {
equal(count, 1, "Should have put one entry there now");
});
db.activities.where("Flags").equals(2).each(function (act) {
equal(act.Type, 2, "The entry is correct");
});
});
}).catch(function (e) {
ok(false, e.stack || e);
}).finally(function () {
db.delete().then(start);
});
});
test("protochain", function () {
var Promise=Dexie.Promise;
var root,
branch1,
branch2;
Promise.newPSD(function () {
root = Promise.PSD;
root.constructor = function () { }
root.constructor.prototype = root;
Promise.newPSD(function () {
branch1 = Promise.PSD;
branch1.constructor = function () { }
branch1.constructor.prototype = branch1;
});
Promise.newPSD(function () {
branch2 = Promise.PSD;
branch2.constructor = function () { }
branch2.constructor.prototype = branch2;
});
});
ok(branch1 instanceof root.constructor, "branch1 instanceof root.constructor");
ok(branch2 instanceof root.constructor, "branch2 instanceof root.constructor");
ok(!(root instanceof branch1.constructor), "!(root instanceof branch1.constructor)");
ok(!(root instanceof branch2.constructor), "!(root instanceof branch2.constructor)");
ok(!(branch1 instanceof branch2.constructor), "!(branch1 instanceof branch2.constructor)");
ok(!(branch2 instanceof branch1.constructor), "!(branch2 instanceof branch1.constructor)");
});
test("protochain2", function () {
var derive = Dexie.derive;
function Root() { }
function Branch1() { }
function Branch2() { }
derive(Branch1).from(Root);
derive(Branch2).from(Root);
var root = new Root();
var branch1 = new Branch1();
var branch2 = new Branch2();
ok(branch1 instanceof root.constructor, "branch1 instanceof root.constructor");
ok(branch2 instanceof root.constructor, "branch2 instanceof root.constructor");
ok(!(root instanceof branch1.constructor), "!(root instanceof branch1.constructor)");
ok(!(root instanceof branch2.constructor), "!(root instanceof branch2.constructor)");
ok(!(branch1 instanceof branch2.constructor), "!(branch1 instanceof branch2.constructor)");
ok(!(branch2 instanceof branch1.constructor), "!(branch2 instanceof branch1.constructor)");
});