@firebase/database-compat 0.1.1-2021823172527 → 0.1.2-canary.0b3ca78eb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -8
- package/dist/database-compat/src/index.d.ts +0 -9
- package/dist/database-compat/src/index.node.d.ts +0 -53
- package/dist/database-compat/src/index.standalone.d.ts +52 -0
- package/dist/index.esm2017.js +5 -6
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +2 -3
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.js +10 -77
- package/dist/index.js.map +1 -1
- package/dist/index.standalone.js +15150 -0
- package/dist/index.standalone.js.map +1 -0
- package/dist/node-esm/database-compat/src/api/Database.d.ts +72 -0
- package/dist/node-esm/database-compat/src/api/Reference.d.ts +201 -0
- package/{karma.conf.js → dist/node-esm/database-compat/src/api/TransactionResult.d.ts} +26 -34
- package/dist/node-esm/database-compat/src/api/internal.d.ts +39 -0
- package/dist/node-esm/database-compat/src/api/onDisconnect.d.ts +27 -0
- package/dist/node-esm/database-compat/src/index.d.ts +32 -0
- package/dist/node-esm/database-compat/src/index.node.d.ts +14 -0
- package/dist/node-esm/database-compat/src/index.standalone.d.ts +52 -0
- package/{src/util/util.ts → dist/node-esm/database-compat/src/util/util.d.ts} +17 -25
- package/dist/node-esm/database-compat/src/util/validation.d.ts +18 -0
- package/{src/api/TransactionResult.ts → dist/node-esm/database-compat/test/browser/crawler_support.test.d.ts} +17 -34
- package/dist/node-esm/database-compat/test/database.test.d.ts +17 -0
- package/dist/node-esm/database-compat/test/datasnapshot.test.d.ts +17 -0
- package/dist/node-esm/database-compat/test/helpers/events.d.ts +34 -0
- package/dist/node-esm/database-compat/test/helpers/util.d.ts +42 -0
- package/dist/node-esm/database-compat/test/info.test.d.ts +17 -0
- package/dist/node-esm/database-compat/test/order.test.d.ts +17 -0
- package/dist/node-esm/database-compat/test/order_by.test.d.ts +17 -0
- package/dist/node-esm/database-compat/test/promise.test.d.ts +17 -0
- package/dist/node-esm/database-compat/test/query.test.d.ts +17 -0
- package/dist/node-esm/database-compat/test/servervalues.test.d.ts +17 -0
- package/dist/node-esm/database-compat/test/transaction.test.d.ts +17 -0
- package/dist/node-esm/index.js +868 -0
- package/dist/node-esm/index.js.map +1 -0
- package/dist/node-esm/package.json +1 -0
- package/package.json +34 -9
- package/standalone/package.json +7 -0
- package/.eslintrc.js +0 -64
- package/rollup.config.js +0 -125
- package/src/api/Database.ts +0 -123
- package/src/api/Reference.ts +0 -790
- package/src/api/internal.ts +0 -91
- package/src/api/onDisconnect.ts +0 -112
- package/src/index.node.ts +0 -142
- package/src/index.ts +0 -88
- package/src/util/validation.ts +0 -59
- package/test/browser/crawler_support.test.ts +0 -206
- package/test/database.test.ts +0 -306
- package/test/datasnapshot.test.ts +0 -249
- package/test/helpers/events.ts +0 -258
- package/test/helpers/util.ts +0 -177
- package/test/info.test.ts +0 -222
- package/test/order.test.ts +0 -592
- package/test/order_by.test.ts +0 -530
- package/test/promise.test.ts +0 -261
- package/test/query.test.ts +0 -4670
- package/test/servervalues.test.ts +0 -152
- package/test/transaction.test.ts +0 -1534
- package/tsconfig.json +0 -11
package/test/order.test.ts
DELETED
|
@@ -1,592 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2017 Google LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { expect } from 'chai';
|
|
19
|
-
|
|
20
|
-
import { EventAccumulator } from '../../database/test/helpers/EventAccumulator';
|
|
21
|
-
import { Reference } from '../src/api/Reference';
|
|
22
|
-
|
|
23
|
-
import { eventTestHelper } from './helpers/events';
|
|
24
|
-
import { getRandomNode } from './helpers/util';
|
|
25
|
-
|
|
26
|
-
describe('Order Tests', () => {
|
|
27
|
-
// Kind of a hack, but a lot of these tests are written such that they'll fail if run before we're
|
|
28
|
-
// connected to Firebase because they do a bunch of sets and then a listen and assume that they'll
|
|
29
|
-
// arrive in that order. But if we aren't connected yet, the "reconnection" code will send them
|
|
30
|
-
// in the opposite order.
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
return new Promise<void>(resolve => {
|
|
33
|
-
const ref = getRandomNode() as Reference;
|
|
34
|
-
let connected = false;
|
|
35
|
-
ref.root.child('.info/connected').on('value', s => {
|
|
36
|
-
connected = s.val() === true;
|
|
37
|
-
if (connected) {
|
|
38
|
-
resolve();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('Push a bunch of data, enumerate it back; ensure order is correct.', async () => {
|
|
45
|
-
const node = getRandomNode() as Reference;
|
|
46
|
-
for (let i = 0; i < 10; i++) {
|
|
47
|
-
node.push().set(i);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const snap = await node.once('value');
|
|
51
|
-
|
|
52
|
-
let expected = 0;
|
|
53
|
-
snap.forEach(child => {
|
|
54
|
-
expect(child.val()).to.equal(expected);
|
|
55
|
-
expected++;
|
|
56
|
-
});
|
|
57
|
-
expect(expected).to.equal(10);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('Push a bunch of paths, then write; ensure order is correct.', async () => {
|
|
61
|
-
const node = getRandomNode() as Reference;
|
|
62
|
-
const paths = [];
|
|
63
|
-
// Push them first to try to call push() multiple times in the same ms.
|
|
64
|
-
for (let i = 0; i < 20; i++) {
|
|
65
|
-
paths[i] = node.push();
|
|
66
|
-
}
|
|
67
|
-
for (let i = 0; i < 20; i++) {
|
|
68
|
-
paths[i].set(i);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const snap = await node.once('value');
|
|
72
|
-
|
|
73
|
-
let expected = 0;
|
|
74
|
-
snap.forEach(child => {
|
|
75
|
-
expect(child.val()).to.equal(expected);
|
|
76
|
-
expected++;
|
|
77
|
-
});
|
|
78
|
-
expect(expected).to.equal(20);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('Push a bunch of data, reconnect, read it back; ensure order is chronological.', async () => {
|
|
82
|
-
const nodePair = getRandomNode(2) as Reference[];
|
|
83
|
-
let expected;
|
|
84
|
-
|
|
85
|
-
const node = nodePair[0];
|
|
86
|
-
let nodesSet = 0;
|
|
87
|
-
for (let i = 0; i < 10; i++) {
|
|
88
|
-
node.push().set(i, () => {
|
|
89
|
-
++nodesSet;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// read it back locally and make sure it's correct.
|
|
94
|
-
const snap = await node.once('value');
|
|
95
|
-
|
|
96
|
-
expected = 0;
|
|
97
|
-
snap.forEach(child => {
|
|
98
|
-
expect(child.val()).to.equal(expected);
|
|
99
|
-
expected++;
|
|
100
|
-
});
|
|
101
|
-
expect(expected).to.equal(10);
|
|
102
|
-
|
|
103
|
-
// read it back
|
|
104
|
-
let readSnap;
|
|
105
|
-
const ea = new EventAccumulator(() => readSnap);
|
|
106
|
-
nodePair[1].on('value', snap => {
|
|
107
|
-
readSnap = snap;
|
|
108
|
-
ea.addEvent();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
await ea.promise;
|
|
112
|
-
|
|
113
|
-
expected = 0;
|
|
114
|
-
readSnap.forEach(child => {
|
|
115
|
-
expect(child.val()).to.equal(expected);
|
|
116
|
-
expected++;
|
|
117
|
-
});
|
|
118
|
-
expect(expected).to.equal(10);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('Push a bunch of data with explicit priority, reconnect, read it back; ensure order is correct.', async () => {
|
|
122
|
-
const nodePair = getRandomNode(2) as Reference[];
|
|
123
|
-
let expected;
|
|
124
|
-
|
|
125
|
-
const node = nodePair[0];
|
|
126
|
-
let nodesSet = 0;
|
|
127
|
-
for (let i = 0; i < 10; i++) {
|
|
128
|
-
const pushedNode = node.push();
|
|
129
|
-
pushedNode.setWithPriority(i, 10 - i, () => {
|
|
130
|
-
++nodesSet;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// read it back locally and make sure it's correct.
|
|
135
|
-
const snap = await node.once('value');
|
|
136
|
-
expected = 9;
|
|
137
|
-
snap.forEach(child => {
|
|
138
|
-
expect(child.val()).to.equal(expected);
|
|
139
|
-
expected--;
|
|
140
|
-
});
|
|
141
|
-
expect(expected).to.equal(-1);
|
|
142
|
-
|
|
143
|
-
// local SETs are visible immediately, but the second node is in a separate repo, so it is considered remote.
|
|
144
|
-
// We need confirmation that the server has gotten all the data before we can expect to receive it all
|
|
145
|
-
|
|
146
|
-
// read it back
|
|
147
|
-
let readSnap;
|
|
148
|
-
const ea = new EventAccumulator(() => readSnap);
|
|
149
|
-
nodePair[1].on('value', snap => {
|
|
150
|
-
readSnap = snap;
|
|
151
|
-
ea.addEvent();
|
|
152
|
-
});
|
|
153
|
-
await ea.promise;
|
|
154
|
-
|
|
155
|
-
expected = 9;
|
|
156
|
-
readSnap.forEach(child => {
|
|
157
|
-
expect(child.val()).to.equal(expected);
|
|
158
|
-
expected--;
|
|
159
|
-
});
|
|
160
|
-
expect(expected).to.equal(-1);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('Push data with exponential priority and ensure order is correct.', async () => {
|
|
164
|
-
const nodePair = getRandomNode(2) as Reference[];
|
|
165
|
-
let expected;
|
|
166
|
-
|
|
167
|
-
const node = nodePair[0];
|
|
168
|
-
let nodesSet = 0;
|
|
169
|
-
for (let i = 0; i < 10; i++) {
|
|
170
|
-
const pushedNode = node.push();
|
|
171
|
-
pushedNode.setWithPriority(
|
|
172
|
-
i,
|
|
173
|
-
111111111111111111111111111111 / Math.pow(10, i),
|
|
174
|
-
() => {
|
|
175
|
-
++nodesSet;
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// read it back locally and make sure it's correct.
|
|
181
|
-
const snap = await node.once('value');
|
|
182
|
-
expected = 9;
|
|
183
|
-
snap.forEach(child => {
|
|
184
|
-
expect(child.val()).to.equal(expected);
|
|
185
|
-
expected--;
|
|
186
|
-
});
|
|
187
|
-
expect(expected).to.equal(-1);
|
|
188
|
-
|
|
189
|
-
// read it back
|
|
190
|
-
let readSnap;
|
|
191
|
-
const ea = new EventAccumulator(() => readSnap);
|
|
192
|
-
nodePair[1].on('value', snap => {
|
|
193
|
-
readSnap = snap;
|
|
194
|
-
ea.addEvent();
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
await ea.promise;
|
|
198
|
-
|
|
199
|
-
expected = 9;
|
|
200
|
-
readSnap.forEach(child => {
|
|
201
|
-
expect(child.val()).to.equal(expected);
|
|
202
|
-
expected--;
|
|
203
|
-
});
|
|
204
|
-
expect(expected).to.equal(-1);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("Verify nodes without values aren't enumerated.", async () => {
|
|
208
|
-
const node = getRandomNode() as Reference;
|
|
209
|
-
node.child('foo');
|
|
210
|
-
node.child('bar').set('test');
|
|
211
|
-
|
|
212
|
-
let items = 0;
|
|
213
|
-
const snap = await node.once('value');
|
|
214
|
-
snap.forEach(child => {
|
|
215
|
-
items++;
|
|
216
|
-
expect(child.key).to.equal('bar');
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
expect(items).to.equal(1);
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it.skip('Receive child_moved event when priority changes.', async () => {
|
|
223
|
-
const node = getRandomNode() as Reference;
|
|
224
|
-
|
|
225
|
-
// const ea = new EventAccumulator(() => eventHelper.watchesInitializedWaiter);
|
|
226
|
-
|
|
227
|
-
const eventHelper = eventTestHelper([
|
|
228
|
-
[node, ['child_added', 'a']],
|
|
229
|
-
[node, ['value', '']],
|
|
230
|
-
[node, ['child_added', 'b']],
|
|
231
|
-
[node, ['value', '']],
|
|
232
|
-
[node, ['child_added', 'c']],
|
|
233
|
-
[node, ['value', '']],
|
|
234
|
-
[node, ['child_moved', 'a']],
|
|
235
|
-
[node, ['child_changed', 'a']],
|
|
236
|
-
[node, ['value', '']]
|
|
237
|
-
]);
|
|
238
|
-
|
|
239
|
-
// await ea.promise;
|
|
240
|
-
|
|
241
|
-
node.child('a').setWithPriority('first', 1);
|
|
242
|
-
node.child('b').setWithPriority('second', 5);
|
|
243
|
-
node.child('c').setWithPriority('third', 10);
|
|
244
|
-
|
|
245
|
-
expect(eventHelper.waiter()).to.equal(false);
|
|
246
|
-
|
|
247
|
-
node.child('a').setPriority(15);
|
|
248
|
-
|
|
249
|
-
expect(eventHelper.waiter()).to.equal(true);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it.skip('Can reset priority to null.', async () => {
|
|
253
|
-
const node = getRandomNode() as Reference;
|
|
254
|
-
|
|
255
|
-
node.child('a').setWithPriority('a', 1);
|
|
256
|
-
node.child('b').setWithPriority('b', 2);
|
|
257
|
-
|
|
258
|
-
// const ea = new EventAccumulator(() => eventHelper.waiter());
|
|
259
|
-
const eventHelper = eventTestHelper([
|
|
260
|
-
[node, ['child_added', 'a']],
|
|
261
|
-
[node, ['child_added', 'b']],
|
|
262
|
-
[node, ['value', '']]
|
|
263
|
-
]);
|
|
264
|
-
|
|
265
|
-
// await ea.promise;
|
|
266
|
-
|
|
267
|
-
eventHelper.addExpectedEvents([
|
|
268
|
-
[node, ['child_moved', 'b']],
|
|
269
|
-
[node, ['child_changed', 'b']],
|
|
270
|
-
[node, ['value', '']]
|
|
271
|
-
]);
|
|
272
|
-
|
|
273
|
-
node.child('b').setPriority(null);
|
|
274
|
-
expect(eventHelper.waiter()).to.equal(true);
|
|
275
|
-
|
|
276
|
-
expect((await node.once('value')).child('b').getPriority()).to.equal(null);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('Inserting a node under a leaf node preserves its priority.', () => {
|
|
280
|
-
const node = getRandomNode() as Reference;
|
|
281
|
-
|
|
282
|
-
let snap = null;
|
|
283
|
-
node.on('value', s => {
|
|
284
|
-
snap = s;
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
node.setWithPriority('a', 10);
|
|
288
|
-
node.child('deeper').set('deeper');
|
|
289
|
-
expect(snap.getPriority()).to.equal(10);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('Verify order of mixed numbers / strings / no priorities.', async () => {
|
|
293
|
-
const nodePair = getRandomNode(2) as Reference[];
|
|
294
|
-
const nodeAndPriorities = [
|
|
295
|
-
'alpha42',
|
|
296
|
-
'zed',
|
|
297
|
-
'noPriorityC',
|
|
298
|
-
null,
|
|
299
|
-
'num41',
|
|
300
|
-
500,
|
|
301
|
-
'noPriorityB',
|
|
302
|
-
null,
|
|
303
|
-
'num80',
|
|
304
|
-
4000.1,
|
|
305
|
-
'num50',
|
|
306
|
-
4000,
|
|
307
|
-
'num10',
|
|
308
|
-
24,
|
|
309
|
-
'alpha41',
|
|
310
|
-
'zed',
|
|
311
|
-
'alpha20',
|
|
312
|
-
'horse',
|
|
313
|
-
'num20',
|
|
314
|
-
123,
|
|
315
|
-
'num70',
|
|
316
|
-
4000.01,
|
|
317
|
-
'noPriorityA',
|
|
318
|
-
null,
|
|
319
|
-
'alpha30',
|
|
320
|
-
'tree',
|
|
321
|
-
'num30',
|
|
322
|
-
300,
|
|
323
|
-
'num60',
|
|
324
|
-
4000.001,
|
|
325
|
-
'alpha10',
|
|
326
|
-
'0horse',
|
|
327
|
-
'num42',
|
|
328
|
-
500,
|
|
329
|
-
'alpha40',
|
|
330
|
-
'zed',
|
|
331
|
-
'num40',
|
|
332
|
-
500
|
|
333
|
-
];
|
|
334
|
-
|
|
335
|
-
let setsCompleted = 0;
|
|
336
|
-
for (let i = 0; i < nodeAndPriorities.length; i++) {
|
|
337
|
-
const n = nodePair[0].child(nodeAndPriorities[i++] as string);
|
|
338
|
-
n.setWithPriority(1, nodeAndPriorities[i], () => {
|
|
339
|
-
setsCompleted++;
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const expectedOutput =
|
|
344
|
-
'noPriorityA, noPriorityB, noPriorityC, num10, num20, num30, num40, num41, num42, num50, num60, num70, num80, alpha10, alpha20, alpha30, alpha40, alpha41, alpha42, ';
|
|
345
|
-
|
|
346
|
-
const snap = await nodePair[0].once('value');
|
|
347
|
-
|
|
348
|
-
let output = '';
|
|
349
|
-
snap.forEach(n => {
|
|
350
|
-
output += n.key + ', ';
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
expect(output).to.equal(expectedOutput);
|
|
354
|
-
|
|
355
|
-
let eventsFired = false;
|
|
356
|
-
output = '';
|
|
357
|
-
nodePair[1].on('value', snap => {
|
|
358
|
-
snap.forEach(n => {
|
|
359
|
-
output += n.key + ', ';
|
|
360
|
-
});
|
|
361
|
-
expect(output).to.equal(expectedOutput);
|
|
362
|
-
eventsFired = true;
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
it('Verify order of integer keys.', async () => {
|
|
367
|
-
const ref = getRandomNode() as Reference;
|
|
368
|
-
const keys = ['foo', 'bar', '03', '0', '100', '20', '5', '3', '003', '9'];
|
|
369
|
-
|
|
370
|
-
let setsCompleted = 0;
|
|
371
|
-
for (let i = 0; i < keys.length; i++) {
|
|
372
|
-
const child = ref.child(keys[i]);
|
|
373
|
-
child.set(true, () => {
|
|
374
|
-
setsCompleted++;
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const expectedOutput = '0, 3, 03, 003, 5, 9, 20, 100, bar, foo, ';
|
|
379
|
-
|
|
380
|
-
const snap = await ref.once('value');
|
|
381
|
-
let output = '';
|
|
382
|
-
snap.forEach(n => {
|
|
383
|
-
output += n.key + ', ';
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
expect(output).to.equal(expectedOutput);
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it('Ensure prevName is correct on child_added event.', () => {
|
|
390
|
-
const node = getRandomNode() as Reference;
|
|
391
|
-
|
|
392
|
-
let added = '';
|
|
393
|
-
node.on('child_added', (snap, prevName) => {
|
|
394
|
-
added += snap.key + ' ' + prevName + ', ';
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
node.set({ a: 1, b: 2, c: 3 });
|
|
398
|
-
|
|
399
|
-
expect(added).to.equal('a null, b a, c b, ');
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
it('Ensure prevName is correct when adding new nodes.', () => {
|
|
403
|
-
const node = getRandomNode() as Reference;
|
|
404
|
-
|
|
405
|
-
let added = '';
|
|
406
|
-
node.on('child_added', (snap, prevName) => {
|
|
407
|
-
added += snap.key + ' ' + prevName + ', ';
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
node.set({ b: 2, c: 3, d: 4 });
|
|
411
|
-
|
|
412
|
-
expect(added).to.equal('b null, c b, d c, ');
|
|
413
|
-
|
|
414
|
-
added = '';
|
|
415
|
-
node.child('a').set(1);
|
|
416
|
-
expect(added).to.equal('a null, ');
|
|
417
|
-
|
|
418
|
-
added = '';
|
|
419
|
-
node.child('e').set(5);
|
|
420
|
-
expect(added).to.equal('e d, ');
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
it('Ensure prevName is correct when adding new nodes with JSON.', () => {
|
|
424
|
-
const node = getRandomNode() as Reference;
|
|
425
|
-
|
|
426
|
-
let added = '';
|
|
427
|
-
node.on('child_added', (snap, prevName) => {
|
|
428
|
-
added += snap.key + ' ' + prevName + ', ';
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
node.set({ b: 2, c: 3, d: 4 });
|
|
432
|
-
|
|
433
|
-
expect(added).to.equal('b null, c b, d c, ');
|
|
434
|
-
|
|
435
|
-
added = '';
|
|
436
|
-
node.set({ a: 1, b: 2, c: 3, d: 4 });
|
|
437
|
-
expect(added).to.equal('a null, ');
|
|
438
|
-
|
|
439
|
-
added = '';
|
|
440
|
-
node.set({ a: 1, b: 2, c: 3, d: 4, e: 5 });
|
|
441
|
-
expect(added).to.equal('e d, ');
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
it('Ensure prevName is correct when moving nodes.', () => {
|
|
445
|
-
const node = getRandomNode() as Reference;
|
|
446
|
-
|
|
447
|
-
let moved = '';
|
|
448
|
-
node.on('child_moved', (snap, prevName) => {
|
|
449
|
-
moved += snap.key + ' ' + prevName + ', ';
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
node.child('a').setWithPriority('a', 1);
|
|
453
|
-
node.child('b').setWithPriority('b', 2);
|
|
454
|
-
node.child('c').setWithPriority('c', 3);
|
|
455
|
-
node.child('d').setWithPriority('d', 4);
|
|
456
|
-
|
|
457
|
-
node.child('d').setPriority(0);
|
|
458
|
-
expect(moved).to.equal('d null, ');
|
|
459
|
-
|
|
460
|
-
moved = '';
|
|
461
|
-
node.child('a').setPriority(4);
|
|
462
|
-
expect(moved).to.equal('a c, ');
|
|
463
|
-
|
|
464
|
-
moved = '';
|
|
465
|
-
node.child('c').setPriority(0.5);
|
|
466
|
-
expect(moved).to.equal('c d, ');
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
it('Ensure prevName is correct when moving nodes by setting whole JSON.', () => {
|
|
470
|
-
const node = getRandomNode() as Reference;
|
|
471
|
-
|
|
472
|
-
let moved = '';
|
|
473
|
-
node.on('child_moved', (snap, prevName) => {
|
|
474
|
-
moved += snap.key + ' ' + prevName + ', ';
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
node.set({
|
|
478
|
-
a: { '.value': 'a', '.priority': 1 },
|
|
479
|
-
b: { '.value': 'b', '.priority': 2 },
|
|
480
|
-
c: { '.value': 'c', '.priority': 3 },
|
|
481
|
-
d: { '.value': 'd', '.priority': 4 }
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
node.set({
|
|
485
|
-
d: { '.value': 'd', '.priority': 0 },
|
|
486
|
-
a: { '.value': 'a', '.priority': 1 },
|
|
487
|
-
b: { '.value': 'b', '.priority': 2 },
|
|
488
|
-
c: { '.value': 'c', '.priority': 3 }
|
|
489
|
-
});
|
|
490
|
-
expect(moved).to.equal('d null, ');
|
|
491
|
-
|
|
492
|
-
moved = '';
|
|
493
|
-
node.set({
|
|
494
|
-
d: { '.value': 'd', '.priority': 0 },
|
|
495
|
-
b: { '.value': 'b', '.priority': 2 },
|
|
496
|
-
c: { '.value': 'c', '.priority': 3 },
|
|
497
|
-
a: { '.value': 'a', '.priority': 4 }
|
|
498
|
-
});
|
|
499
|
-
expect(moved).to.equal('a c, ');
|
|
500
|
-
|
|
501
|
-
moved = '';
|
|
502
|
-
node.set({
|
|
503
|
-
d: { '.value': 'd', '.priority': 0 },
|
|
504
|
-
c: { '.value': 'c', '.priority': 0.5 },
|
|
505
|
-
b: { '.value': 'b', '.priority': 2 },
|
|
506
|
-
a: { '.value': 'a', '.priority': 4 }
|
|
507
|
-
});
|
|
508
|
-
expect(moved).to.equal('c d, ');
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
it('Case 595: Should not get child_moved event when deleting prioritized grandchild.', () => {
|
|
512
|
-
const f = getRandomNode() as Reference;
|
|
513
|
-
let moves = 0;
|
|
514
|
-
f.on('child_moved', () => {
|
|
515
|
-
moves++;
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
f.child('test/foo').setWithPriority(42, '5');
|
|
519
|
-
f.child('test/foo2').setWithPriority(42, '10');
|
|
520
|
-
f.child('test/foo').remove();
|
|
521
|
-
f.child('test/foo2').remove();
|
|
522
|
-
|
|
523
|
-
expect(moves).to.equal(0, 'Should *not* have received any move events.');
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
it('Can set value with priority of 0.', () => {
|
|
527
|
-
const f = getRandomNode() as Reference;
|
|
528
|
-
|
|
529
|
-
let snap = null;
|
|
530
|
-
f.on('value', s => {
|
|
531
|
-
snap = s;
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
f.setWithPriority('test', 0);
|
|
535
|
-
|
|
536
|
-
expect(snap.getPriority()).to.equal(0);
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
it('Can set object with priority of 0.', () => {
|
|
540
|
-
const f = getRandomNode() as Reference;
|
|
541
|
-
|
|
542
|
-
let snap = null;
|
|
543
|
-
f.on('value', s => {
|
|
544
|
-
snap = s;
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
f.setWithPriority({ x: 'test', y: 7 }, 0);
|
|
548
|
-
|
|
549
|
-
expect(snap.getPriority()).to.equal(0);
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
it('Case 2003: Should get child_moved for any priority change, regardless of whether it affects ordering.', () => {
|
|
553
|
-
const f = getRandomNode() as Reference;
|
|
554
|
-
const moved = [];
|
|
555
|
-
f.on('child_moved', snap => {
|
|
556
|
-
moved.push(snap.key);
|
|
557
|
-
});
|
|
558
|
-
f.set({
|
|
559
|
-
a: { '.value': 'a', '.priority': 0 },
|
|
560
|
-
b: { '.value': 'b', '.priority': 1 },
|
|
561
|
-
c: { '.value': 'c', '.priority': 2 },
|
|
562
|
-
d: { '.value': 'd', '.priority': 3 }
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
expect(moved).to.deep.equal([]);
|
|
566
|
-
f.child('b').setWithPriority('b', 1.5);
|
|
567
|
-
expect(moved).to.deep.equal(['b']);
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
it('Case 2003: Should get child_moved for any priority change, regardless of whether it affects ordering (2).', () => {
|
|
571
|
-
const f = getRandomNode() as Reference;
|
|
572
|
-
const moved = [];
|
|
573
|
-
f.on('child_moved', snap => {
|
|
574
|
-
moved.push(snap.key);
|
|
575
|
-
});
|
|
576
|
-
f.set({
|
|
577
|
-
a: { '.value': 'a', '.priority': 0 },
|
|
578
|
-
b: { '.value': 'b', '.priority': 1 },
|
|
579
|
-
c: { '.value': 'c', '.priority': 2 },
|
|
580
|
-
d: { '.value': 'd', '.priority': 3 }
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
expect(moved).to.deep.equal([]);
|
|
584
|
-
f.set({
|
|
585
|
-
a: { '.value': 'a', '.priority': 0 },
|
|
586
|
-
b: { '.value': 'b', '.priority': 1.5 },
|
|
587
|
-
c: { '.value': 'c', '.priority': 2 },
|
|
588
|
-
d: { '.value': 'd', '.priority': 3 }
|
|
589
|
-
});
|
|
590
|
-
expect(moved).to.deep.equal(['b']);
|
|
591
|
-
});
|
|
592
|
-
});
|