|
|
|
@ -17,25 +17,25 @@ const mockInitialState = { |
|
|
|
|
|
|
|
type MockState = typeof mockInitialState; |
|
|
|
|
|
|
|
const patch1: DeepPartial<MockState> = { foo: { bar: { baz: [() => {}] } } }; |
|
|
|
const deepPatch1: DeepPartial<MockState> = { foo: { bar: { baz: [() => {}] } } }; |
|
|
|
const expected1: MockState = clone(mockInitialState); |
|
|
|
expected1.foo.bar.baz = patch1.foo.bar.baz; |
|
|
|
expected1.foo.bar.baz = deepPatch1.foo.bar.baz; |
|
|
|
|
|
|
|
const patch2: DeepPartial<MockState> = { foo: { bar: { qux: Promise.resolve() } } }; |
|
|
|
const deepPatch2: DeepPartial<MockState> = { foo: { bar: { qux: Promise.resolve() } } }; |
|
|
|
const expected2: MockState = clone(mockInitialState); |
|
|
|
expected2.foo.bar.qux = patch2.foo.bar.qux; |
|
|
|
expected2.foo.bar.qux = deepPatch2.foo.bar.qux; |
|
|
|
|
|
|
|
const patch3: DeepPartial<MockState> = { foo: { n: 1 } }; |
|
|
|
const deepPatch3: DeepPartial<MockState> = { foo: { n: 1 } }; |
|
|
|
const expected3: MockState = clone(mockInitialState); |
|
|
|
expected3.foo.n = patch3.foo.n; |
|
|
|
expected3.foo.n = deepPatch3.foo.n; |
|
|
|
|
|
|
|
const patch4: DeepPartial<MockState> = { x: 'X' }; |
|
|
|
const deepPatch4: DeepPartial<MockState> = { x: 'X' }; |
|
|
|
const expected4: MockState = clone(mockInitialState); |
|
|
|
expected4.x = patch4.x; |
|
|
|
expected4.x = deepPatch4.x; |
|
|
|
|
|
|
|
const patch5: DeepPartial<MockState> = { a: true }; |
|
|
|
const deepPatch5: DeepPartial<MockState> = { a: true }; |
|
|
|
const expected5: MockState = clone(mockInitialState); |
|
|
|
expected5.a = patch5.a; |
|
|
|
expected5.a = deepPatch5.a; |
|
|
|
|
|
|
|
describe('Internal Store', () => { |
|
|
|
describe('sliceState', () => { |
|
|
|
@ -52,10 +52,7 @@ describe('Internal Store', () => { |
|
|
|
async ({ selector, expected }) => { |
|
|
|
const store = new InternalStore(mockInitialState); |
|
|
|
|
|
|
|
const value = await store |
|
|
|
.sliceState(selector) |
|
|
|
.pipe(take(1)) |
|
|
|
.toPromise(); |
|
|
|
const value = await store.sliceState(selector).pipe(take(1)).toPromise(); |
|
|
|
|
|
|
|
expect(value).toEqual(expected); |
|
|
|
}, |
|
|
|
@ -64,16 +61,16 @@ describe('Internal Store', () => { |
|
|
|
|
|
|
|
describe('patchState', () => { |
|
|
|
test.each` |
|
|
|
patch | expected |
|
|
|
${patch1} | ${expected1} |
|
|
|
${patch2} | ${expected2} |
|
|
|
${patch3} | ${expected3} |
|
|
|
${patch4} | ${expected4} |
|
|
|
${patch5} | ${expected5} |
|
|
|
patch | expected |
|
|
|
${deepPatch1} | ${expected1} |
|
|
|
${deepPatch2} | ${expected2} |
|
|
|
${deepPatch3} | ${expected3} |
|
|
|
${deepPatch4} | ${expected4} |
|
|
|
${deepPatch5} | ${expected5} |
|
|
|
`('should set state as $expected when patch is $patch', ({ patch, expected }) => {
|
|
|
|
const store = new InternalStore(mockInitialState); |
|
|
|
|
|
|
|
store.patch(patch); |
|
|
|
store.deepPatch(patch); |
|
|
|
|
|
|
|
expect(store.state).toEqual(expected); |
|
|
|
}); |
|
|
|
@ -86,12 +83,12 @@ describe('Internal Store', () => { |
|
|
|
const onQux$ = store.sliceUpdate(state => state.foo.bar.qux); |
|
|
|
|
|
|
|
onQux$.pipe(take(1)).subscribe(value => { |
|
|
|
expect(value).toEqual(patch2.foo.bar.qux); |
|
|
|
expect(value).toEqual(deepPatch2.foo.bar.qux); |
|
|
|
done(); |
|
|
|
}); |
|
|
|
|
|
|
|
store.patch(patch1); |
|
|
|
store.patch(patch2); |
|
|
|
store.deepPatch(deepPatch1); |
|
|
|
store.deepPatch(deepPatch2); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
@ -99,7 +96,7 @@ describe('Internal Store', () => { |
|
|
|
it('should reset state to initialState', () => { |
|
|
|
const store = new InternalStore(mockInitialState); |
|
|
|
|
|
|
|
store.patch(patch1); |
|
|
|
store.deepPatch(deepPatch1); |
|
|
|
store.reset(); |
|
|
|
|
|
|
|
expect(store.state).toEqual(mockInitialState); |
|
|
|
|