Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMike Gerwitz <gerwitzm@lovullo.com>2016-12-21 11:21:09 -0500
committerMike Gerwitz <gerwitzm@lovullo.com>2017-01-03 09:11:18 -0500
commit29f67bd157c6ab1b617fa680eb647fd8227910f3 (patch)
tree4a7bf4941d0e9cba0e3f38aa8959048a3daafa2c /test
parentd8d44130e888d43b2b8c47a526f9dc074726d024 (diff)
downloadliza-29f67bd157c6ab1b617fa680eb647fd8227910f3.tar.gz
liza-29f67bd157c6ab1b617fa680eb647fd8227910f3.tar.bz2
liza-29f67bd157c6ab1b617fa680eb647fd8227910f3.zip
Add store.Cascading
* src/store/Cascading.js: Add trait. * test/store/CascadingTest.js: Add test case.
Diffstat (limited to 'test')
-rw-r--r--test/store/CascadingTest.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/store/CascadingTest.js b/test/store/CascadingTest.js
new file mode 100644
index 0000000..51aaca0
--- /dev/null
+++ b/test/store/CascadingTest.js
@@ -0,0 +1,77 @@
+/**
+ * Test case for Cascading store
+ *
+ * Copyright (C) 2016 LoVullo Associates, Inc.
+ *
+ * This file is part of the Liza Data Collection Framework
+ *
+ * Liza is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+var store = require( '../../' ).store,
+ expect = require( 'chai' ).expect,
+ Store = store.MemoryStore,
+ Sut = store.Cascading;
+
+describe( 'store.Cascading', () =>
+{
+ describe( '#add', () =>
+ {
+ it( 'does not allow attaching non-store objects', () =>
+ {
+ expect( () => Store.use( Sut )().add( 'invalid', {} ) )
+ .to.throw( TypeError );
+ } );
+
+
+ it( 'allows attaching Store objects', () =>
+ {
+ expect( () => Store.use( Sut )().add( 'valid', Store() ) )
+ .to.not.throw( TypeError );
+ } );
+ } );
+
+
+ describe( '#clear', () =>
+ {
+ it( 'invokes #clear on all contained stores', () =>
+ {
+ const cleared = [];
+
+ const MockStore = Store.extend(
+ {
+ 'override clear'()
+ {
+ cleared.push( this.__inst );
+ }
+ } );
+
+ const stores = [ 1, 2, 3 ].map( () => MockStore() );
+ const sut = Store.use( Sut )();
+
+ stores.forEach( ( store, i ) => sut.add( i, store ) );
+
+ // should trigger clear on all stores
+ sut.clear();
+
+ expect(
+ stores.every( store =>
+ cleared.some( item => item === store )
+ )
+ ).to.be.true;
+ } );
+ } );
+} ); \ No newline at end of file