2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import { ObservableStore } from '@metamask/obs-store';
|
|
|
|
import ComposableObservableStore from '../../../app/scripts/lib/ComposableObservableStore';
|
2018-04-13 19:13:36 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('ComposableObservableStore', function () {
|
|
|
|
it('should register initial state', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const store = new ComposableObservableStore('state');
|
|
|
|
assert.strictEqual(store.getState(), 'state');
|
|
|
|
});
|
2018-04-13 19:13:36 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should register initial structure', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const testStore = new ObservableStore();
|
|
|
|
const store = new ComposableObservableStore(null, { TestStore: testStore });
|
|
|
|
testStore.putState('state');
|
|
|
|
assert.deepEqual(store.getState(), { TestStore: 'state' });
|
|
|
|
});
|
2018-04-13 19:13:36 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should update structure', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const testStore = new ObservableStore();
|
|
|
|
const store = new ComposableObservableStore();
|
|
|
|
store.updateStructure({ TestStore: testStore });
|
|
|
|
testStore.putState('state');
|
|
|
|
assert.deepEqual(store.getState(), { TestStore: 'state' });
|
|
|
|
});
|
2018-04-13 19:13:36 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should return flattened state', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const fooStore = new ObservableStore({ foo: 'foo' });
|
|
|
|
const barStore = new ObservableStore({ bar: 'bar' });
|
2018-04-13 19:13:36 +02:00
|
|
|
const store = new ComposableObservableStore(null, {
|
|
|
|
FooStore: fooStore,
|
|
|
|
BarStore: barStore,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert.deepEqual(store.getFlatState(), { foo: 'foo', bar: 'bar' });
|
|
|
|
});
|
|
|
|
});
|