From 8b683f643bed9628cf55b77eeb89bfd2df6c169d Mon Sep 17 00:00:00 2001 From: Salakar Date: Mon, 16 Apr 2018 17:45:45 +0100 Subject: [PATCH] [tests][firestore] path tests --- bridge/e2e/firestore/path.e2e.js | 145 +++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 bridge/e2e/firestore/path.e2e.js diff --git a/bridge/e2e/firestore/path.e2e.js b/bridge/e2e/firestore/path.e2e.js new file mode 100644 index 00000000..a17c4121 --- /dev/null +++ b/bridge/e2e/firestore/path.e2e.js @@ -0,0 +1,145 @@ +describe('firestore()', () => { + describe('Path', () => { + describe('id', () => { + it('returns the document id', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName('collection/documentId'); + path.id.should.be.equal('documentId'); + }); + + it('returns null if no path', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName(''); + should.equal(path.id, null); + }); + }); + + describe('isDocument', () => { + it('returns true if path is a document', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName('collection/documentId'); + path.isDocument.should.be.equal(true); + }); + + it('returns false if path is a collection', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName('collection'); + path.isDocument.should.be.equal(false); + }); + }); + + describe('isCollection', () => { + it('returns true if path is a collection', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName('collection'); + path.isCollection.should.be.equal(true); + }); + + it('returns false if path is a document', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName('collection/documentId'); + path.isCollection.should.be.equal(false); + }); + }); + + describe('relativeName', () => { + it('returns original full path', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName('collection'); + const path2 = Path.fromName('collection/documentId'); + path.relativeName.should.be.equal('collection'); + path2.relativeName.should.be.equal('collection/documentId'); + }); + }); + + describe('child()', () => { + it('returns original path joined with the provided child path', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName('collection'); + const path2 = path.child('documentId'); + path.relativeName.should.be.equal('collection'); + path2.relativeName.should.be.equal('collection/documentId'); + }); + }); + + describe('parent()', () => { + it('returns the parent of the current child path', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName('collection/documentId'); + const path2 = path.parent(); + path.relativeName.should.be.equal('collection/documentId'); + path2.relativeName.should.be.equal('collection'); + }); + + it('returns null if no path', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName(''); + const path2 = path.parent(); + path._parts.length.should.be.equal(0); + should.equal(path2, null); + }); + }); + + describe('static fromName()', () => { + it('returns a new instance from a / delimited path string', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName('collection/document'); + path.should.be.instanceOf(Path); + path._parts.length.should.be.equal(2); + }); + + it('returns a new instance from an empty string', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName(''); + path.should.be.instanceOf(Path); + path._parts.length.should.be.equal(0); + }); + }); + + it('returns a new instance with no args provided', async () => { + const Path = bridge.require( + 'react-native-firebase/dist/modules/firestore/Path' + ); + + const path = Path.fromName(); + path.should.be.instanceOf(Path); + path._parts.length.should.be.equal(0); + }); + }); +});