Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Side by Side Diff: polymer_1.0.4/bower_components/firebase-element/test/firebase-collection.html

Issue 1205703007: Add polymer 1.0 to npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Renamed folder to 1.0.4 Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!doctype html>
2 <!--
3 @license
4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt
6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt
8 Code distributed by Google as part of the polymer project is also
9 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
10 -->
11 <html>
12 <head>
13 <title>firebase-collection</title>
14
15 <script src="../../webcomponentsjs/webcomponents.js"></script>
16 <script src="../../web-component-tester/browser.js"></script>
17 <script src="../../test-fixture/test-fixture-mocha.js"></script>
18
19 <link rel="import" href="../../polymer/polymer.html">
20 <link rel="import" href="../../promise-polyfill/promise-polyfill.html">
21 <link rel="import" href="../../test-fixture/test-fixture.html">
22 <link rel="import" href="test-helpers.html">
23 <link rel="import" href="../firebase-collection.html">
24 </head>
25 <body>
26 <test-fixture id="TrivialCollection">
27 <template>
28 <firebase-collection
29 location="https://fb-element-demo.firebaseio.com/test/trivial"
30 log>
31 </firebase-collection>
32 </template>
33 </test-fixture>
34 <test-fixture id="PrimitiveCollection">
35 <template>
36 <firebase-collection
37 location="https://fb-element-demo.firebaseio.com/test/primitives"
38 order-by-value
39 log>
40 </firebase-collection>
41 </template>
42 </test-fixture>
43 <test-fixture id="ChangingChildren">
44 <template>
45 <firebase-collection
46 location="https://fb-element-demo.firebaseio.com/test/changing_children"
47 order-by-child="foo"
48 log>
49 </firebase-collection>
50 </template>
51 </test-fixture>
52
53 <test-fixture id="SyncingCollections">
54 <template>
55 <firebase-collection
56 location="https://fb-element-demo.firebaseio.com/test/syncing"
57 log>
58 </firebase-collection>
59 <firebase-collection
60 location="https://fb-element-demo.firebaseio.com/test/syncing"
61 order-by-child="foo"
62 log>
63 </firebase-collection>
64 </template>
65 </test-fixture>
66
67 <script>
68 suite('<firebase-document>', function() {
69 var firebase;
70
71 suite('basic usage', function() {
72 setup(function() {
73 firebase = fixture('TrivialCollection');
74 });
75
76 teardown(function() {
77 firebase.disconnect();
78 });
79
80 test('exposes data as an array', function(done) {
81 waitForEvent(firebase, 'firebase-child-added').then(function() {
82 expect(firebase.data).to.be.an('array');
83 done();
84 }).catch(function(e) {
85 done(e);
86 });
87 });
88
89 test('receives data from Firebase location', function(done) {
90 waitForEvent(firebase, 'data-changed').then(function() {
91 expect(firebase.data[0].value).to.be.equal(true);
92 done();
93 }).catch(function(e) {
94 done(e);
95 });
96 });
97 });
98
99 suite('ordered primitives', function() {
100 setup(function() {
101 firebase = fixture('PrimitiveCollection');
102 });
103
104 teardown(function() {
105 firebase.disconnect();
106 });
107
108 test('converts primitives into objects with a value key', function(done) {
109 waitForEvent(firebase, 'firebase-child-added').then(function() {
110 expect(firebase.data[0]).to.be.an('object');
111 done();
112 }).catch(function(e) {
113 done(e);
114 });
115 });
116
117 test('orders primitives by value', function(done) {
118 waitForEvent(firebase, 'firebase-value').then(function() {
119 var lastValue = -Infinity;
120 expect(firebase.data.length).to.be.greaterThan(0);
121 firebase.data.forEach(function(item) {
122 expect(item.value).to.not.be.lessThan(lastValue);
123 lastValue = item.value;
124 });
125 done();
126 }).catch(function(e) {
127 done(e);
128 });
129 });
130
131 suite('adding a value locally', function() {
132 setup(function(done) {
133 waitForEvent(firebase, 'firebase-value').then(function() {
134 done();
135 }).catch(function(e) {
136 done(e);
137 });
138 });
139
140 test('can be done with `add`', function(done) {
141 var length = firebase.data.length;
142 var newValue = firebase.data[firebase.data.length - 1].value + 1;
143 var key;
144
145 waitForEvent(firebase, 'firebase-child-added').then(function() {
146 expect(firebase.data.length).to.be.equal(length + 1);
147 expect(firebase.data[firebase.data.length - 1].value).to.be.equal( newValue);
148 done();
149 }).catch(function(e) {
150 done(e);
151 }).then(function() {
152 firebase.removeByKey(key);
153 });
154
155 key = firebase.add(newValue).key();
156 });
157 });
158 });
159
160 suite('a child changes', function() {
161 setup(function(done) {
162 firebase = fixture('ChangingChildren');
163 waitForEvent(firebase, 'firebase-value').then(function() {
164 done();
165 }).catch(function(e) {
166 done(e)
167 });
168 });
169
170 test('updates the child key in place with the new value', function(done) {
171 var childrenKeys = [];
172
173 waitForEvent(firebase, 'firebase-value').then(function() {
174 var middleValue = firebase.getByKey(childrenKeys[1]);
175 var changes;
176
177 expect(middleValue.foo).to.be.equal(1);
178 expect(middleValue.bar).to.be.equal(1);
179
180 changes = waitForEvent(firebase, 'firebase-child-changed');
181
182 firebase.set('data.' + firebase.data.indexOf(middleValue) + '.bar', 2);
183
184 return changes;
185 }).then(function() {
186 var middleValue = firebase.getByKey(childrenKeys[1]);
187
188 expect(middleValue.foo).to.be.equal(1);
189 expect(middleValue.bar).to.be.equal(2);
190
191 done();
192 }).catch(function(e) {
193 done(e);
194 }).then(function() {
195 childrenKeys.forEach(function(key) {
196 firebase.removeByKey(key);
197 });
198 });
199
200 childrenKeys = [0, 1, 2].map(function(value, index) {
201 return firebase.add({
202 foo: value,
203 bar: index
204 }).key();
205 });
206 });
207 });
208
209 suite('syncing collections', function() {
210 var localFirebase;
211 var remoteFirebase;
212
213 setup(function(done) {
214 firebase = fixture('SyncingCollections');
215 localFirebase = firebase[0];
216 remoteFirebase = firebase[1];
217 Promise.all([
218 waitForEvent(localFirebase, 'firebase-value'),
219 waitForEvent(remoteFirebase, 'firebase-value')
220 ]).then(function() {
221 done();
222 }).catch(function(e) {
223 done(e);
224 });
225 });
226
227 test('syncs a new item at the correct index', function(done) {
228 var data = {
229 foo: 100
230 };
231 var key;
232
233 waitForEvent(remoteFirebase, 'firebase-value').then(function() {
234 var value = remoteFirebase.getByKey(key);
235 var lowValue = remoteFirebase.getByKey('lowValue');
236 var highValue = remoteFirebase.getByKey('highValue');
237
238 var index = remoteFirebase.data.indexOf(value);
239 var lowIndex = remoteFirebase.data.indexOf(lowValue);
240 var highIndex = remoteFirebase.data.indexOf(highValue);
241
242 expect(value).to.be.okay;
243 expect(index).to.be.lessThan(highIndex);
244 expect(index).to.be.greaterThan(lowIndex);
245 done();
246 }).catch(function(e) {
247 done(e);
248 }).then(function() {
249 localFirebase.removeByKey(key);
250 });
251
252 key = localFirebase.add(data).key();
253 });
254 });
255 });
256 </script>
257
258 </body>
259 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698