From 7290611c0da89652f12f209768a97128d6ee9916 Mon Sep 17 00:00:00 2001 From: christophe-g Date: Sat, 13 Jan 2018 14:01:02 +0100 Subject: [PATCH] added tests --- firebase-query.html | 1 + test/firebase-document.html | 53 +++++++++++++++++++++++++++++++++++++ test/firebase-query.html | 17 ++++++++++++ 3 files changed, 71 insertions(+) diff --git a/firebase-query.html b/firebase-query.html index 117cf4a..466d0d3 100644 --- a/firebase-query.html +++ b/firebase-query.html @@ -340,6 +340,7 @@ }.bind(this)) this.set('data', data); + this._setExists(true); } const query = this.query diff --git a/test/firebase-document.html b/test/firebase-document.html index b97adcf..3fb00e8 100644 --- a/test/firebase-document.html +++ b/test/firebase-document.html @@ -65,6 +65,59 @@ }); } }); + + 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); + }); + }); + + }); + }); diff --git a/test/firebase-query.html b/test/firebase-query.html index 777e7b5..fb9e059 100644 --- a/test/firebase-query.html +++ b/test/firebase-query.html @@ -176,6 +176,7 @@ var object = makeObject(); return pushFirebaseValue(query.path, object).then(function() { + expect(query.exists).to.be.equal(true); expect(query.data.length).to.be.equal(1); expect(query.data[0]).to.be.ok; expect(query.data[0].val).to.be.equal(object.val); @@ -241,6 +242,22 @@ expect(query.data[0].foo).to.be.eql(undefined); }); }); + + test('exists is null when template is stamped', function() { + 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); + }); + }); }); suite('querying against leaf node collections', function() {