2021-05-07 21:38:24 +02:00
|
|
|
import { strict as assert } from 'assert';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { ObservableStore } from '@metamask/obs-store';
|
2021-03-16 22:00:08 +01:00
|
|
|
import ComposableObservableStore from './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' });
|
|
|
|
});
|
2021-05-11 18:39:17 +02:00
|
|
|
|
|
|
|
it('should return empty flattened state when not configured', function () {
|
|
|
|
const store = new ComposableObservableStore();
|
|
|
|
assert.deepEqual(store.getFlatState(), {});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|