You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.3 KiB
36 lines
1.3 KiB
4 years ago
|
import assert from 'assert';
|
||
|
import { ObservableStore } from '@metamask/obs-store';
|
||
4 years ago
|
import ComposableObservableStore from './ComposableObservableStore';
|
||
7 years ago
|
|
||
5 years ago
|
describe('ComposableObservableStore', function () {
|
||
|
it('should register initial state', function () {
|
||
4 years ago
|
const store = new ComposableObservableStore('state');
|
||
|
assert.strictEqual(store.getState(), 'state');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should register initial structure', function () {
|
||
4 years ago
|
const testStore = new ObservableStore();
|
||
|
const store = new ComposableObservableStore(null, { TestStore: testStore });
|
||
|
testStore.putState('state');
|
||
|
assert.deepEqual(store.getState(), { TestStore: 'state' });
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should update structure', function () {
|
||
4 years ago
|
const testStore = new ObservableStore();
|
||
|
const store = new ComposableObservableStore();
|
||
|
store.updateStructure({ TestStore: testStore });
|
||
|
testStore.putState('state');
|
||
|
assert.deepEqual(store.getState(), { TestStore: 'state' });
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should return flattened state', function () {
|
||
4 years ago
|
const fooStore = new ObservableStore({ foo: 'foo' });
|
||
|
const barStore = new ObservableStore({ bar: 'bar' });
|
||
7 years ago
|
const store = new ComposableObservableStore(null, {
|
||
|
FooStore: fooStore,
|
||
|
BarStore: barStore,
|
||
4 years ago
|
});
|
||
|
assert.deepEqual(store.getFlatState(), { foo: 'foo', bar: 'bar' });
|
||
|
});
|
||
|
});
|