This repository was archived by the owner on May 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathfirebase-document.html
More file actions
124 lines (105 loc) · 3.61 KB
/
firebase-document.html
File metadata and controls
124 lines (105 loc) · 3.61 KB
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
<!doctype html>
<!--
@license
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file or at
https://github.com/firebase/polymerfire/blob/master/LICENSE
-->
<html>
<head>
<meta charset="UTF-8">
<title>firebase-document tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../polymerfire.html">
<link rel="import" href="../../app-storage/test/app-storage-compatibility-suite.html">
<link rel="import" href="../firebase-app.html">
<link rel="import" href="../firebase-document.html">
</head>
<body>
<firebase-app
name="test"
api-key="AIzaSyDTP-eiQezleFsV2WddFBAhF_WEzx_8v_g"
auth-domain="polymerfire-test.firebaseapp.com"
database-url="https://polymerfire-test.firebaseio.com">
</firebase-app>
<test-fixture id="BasicStorage">
<template>
<firebase-document app-name="test" path="/compat"></firebase-document>
</template>
</test-fixture>
<test-fixture id="SyncingStorage">
<template>
<firebase-document app-name="test" path="/compat"></firebase-document>
<firebase-document app-name="test" path="/compat"></firebase-document>
</template>
</test-fixture>
<script>
HTMLImports.whenReady(function() {
testAppStorageDocumentCompatibility({
tagName: 'firebase-document',
awaitUpdate: function(element) {
return new Promise(function(resolve) {
element.ref.on('value', function onValue() {
element.ref.off('value', onValue);
Polymer.Base.async(resolve, 1);
});
});
},
fetchStoredValue: window.foo = function(storagePath) {
return new Promise(function(resolve) {
var ref = firebase.app('test').database().ref(storagePath);
ref.on('value', function(snapshot) {
ref.off('value');
resolve(snapshot.val());
});
});
}
});
function pushFirebaseValue(path, value) {
return firebase.app('test').database().ref(path).push(value);
}
function clearFirebaseValue(path) {
return firebase.app('test').database().ref(path).set(null);
}
var makeObject;
var root;
setup(function() {
var objectId = 0;
makeObject = function(value) {
return {
val: value || objectId++
};
};
return pushFirebaseValue('/test', { ignore: 'me' }).then(function(snapshot) {
root = '/test/' + snapshot.key;
});
});
suite('exists attribute', function() {
var query;
setup(function() {
query = fixture('BasicStorage');
query.path = root + '/list';
return query.transactionsComplete;
});
test('exists is null when we change the path', function() {
query.path = '/myNewPath';
expect(query.exists).to.be.equal(null);
});
test('exists is true when we have data false when we remove it.', function() {
var object = makeObject();
return pushFirebaseValue(query.path, object).then(function() {
expect(query.exists).to.be.equal(true);
}).then(function(){
clearFirebaseValue(query.path);
}).then(function() {
expect(query.exists).to.be.equal(false);
});
});
});
});
</script>
</body>
</html>