This commit is contained in:
Norbert de Langen 2020-03-10 12:38:00 +01:00
parent f2243c7d87
commit 7a40c5982b
No known key found for this signature in database
GPG Key ID: 976651DA156C2825

View File

@ -516,11 +516,12 @@ describe('stories API', () => {
it('changes args properly, per story when receiving STORY_ARGS_UPDATED', () => { it('changes args properly, per story when receiving STORY_ARGS_UPDATED', () => {
const navigate = jest.fn(); const navigate = jest.fn();
const store = createMockStore(); const store = createMockStore();
const api = new EventEmitter();
const { const {
api: { setStories }, api: { setStories },
init, init,
} = initStories({ store, navigate, provider }); } = initStories({ store, navigate, provider, fullAPI: api });
setStories({ setStories({
'a--1': { kind: 'a', name: '1', parameters, path: 'a--1', id: 'a--1', args: { a: 'b' } }, 'a--1': { kind: 'a', name: '1', parameters, path: 'a--1', id: 'a--1', args: { a: 'b' } },
@ -531,49 +532,31 @@ describe('stories API', () => {
expect(initialStoriesHash['a--1'].args).toEqual({ a: 'b' }); expect(initialStoriesHash['a--1'].args).toEqual({ a: 'b' });
expect(initialStoriesHash['b--1'].args).toEqual({ x: 'y' }); expect(initialStoriesHash['b--1'].args).toEqual({ x: 'y' });
const api = new EventEmitter(); init();
init({ api });
api.emit(STORY_ARGS_UPDATED, 'a--1', { foo: 'bar' }); api.emit(STORY_ARGS_UPDATED, 'a--1', { foo: 'bar' });
const { storiesHash: changedStoriesHash } = store.getState(); const { storiesHash: changedStoriesHash } = store.getState();
expect(changedStoriesHash['a--1']).toEqual({ expect(changedStoriesHash['a--1'].args).toEqual({ foo: 'bar' });
isLeaf: true, expect(changedStoriesHash['b--1'].args).toEqual({ x: 'y' });
parent: 'a',
kind: 'a',
name: '1',
parameters: {},
path: 'a--1',
id: 'a--1',
args: { foo: 'bar' },
});
expect(changedStoriesHash['b--1']).toEqual({
isLeaf: true,
parent: 'b',
kind: 'b',
name: '1',
parameters: {},
path: 'b--1',
id: 'b--1',
args: { x: 'y' },
});
}); });
it('updateStoryArgs emits UPDATE_STORY_ARGS and does not change anything', () => { it('updateStoryArgs emits UPDATE_STORY_ARGS and does not change anything', () => {
const navigate = jest.fn(); const navigate = jest.fn();
const emit = jest.fn();
const on = jest.fn();
const store = createMockStore(); const store = createMockStore();
const { const {
api: { setStories, updateStoryArgs }, api: { setStories, updateStoryArgs },
init, init,
} = initStories({ store, navigate, provider }); } = initStories({ store, navigate, provider, fullAPI: { emit, on } });
setStories({ setStories({
'a--1': { kind: 'a', name: '1', parameters, path: 'a--1', id: 'a--1', args: { a: 'b' } }, 'a--1': { kind: 'a', name: '1', parameters, path: 'a--1', id: 'a--1', args: { a: 'b' } },
'b--1': { kind: 'b', name: '1', parameters, path: 'b--1', id: 'b--1', args: { x: 'y' } }, 'b--1': { kind: 'b', name: '1', parameters, path: 'b--1', id: 'b--1', args: { x: 'y' } },
}); });
const emit = jest.fn(); init();
init({ api: { emit, on: jest.fn() } });
updateStoryArgs('a--1', { foo: 'bar' }); updateStoryArgs('a--1', { foo: 'bar' });
expect(emit).toHaveBeenCalledWith(UPDATE_STORY_ARGS, 'a--1', { foo: 'bar' }); expect(emit).toHaveBeenCalledWith(UPDATE_STORY_ARGS, 'a--1', { foo: 'bar' });