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', () => {
const navigate = jest.fn();
const store = createMockStore();
const api = new EventEmitter();
const {
api: { setStories },
init,
} = initStories({ store, navigate, provider });
} = initStories({ store, navigate, provider, fullAPI: api });
setStories({
'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['b--1'].args).toEqual({ x: 'y' });
const api = new EventEmitter();
init({ api });
init();
api.emit(STORY_ARGS_UPDATED, 'a--1', { foo: 'bar' });
const { storiesHash: changedStoriesHash } = store.getState();
expect(changedStoriesHash['a--1']).toEqual({
isLeaf: true,
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' },
});
expect(changedStoriesHash['a--1'].args).toEqual({ foo: 'bar' });
expect(changedStoriesHash['b--1'].args).toEqual({ x: 'y' });
});
it('updateStoryArgs emits UPDATE_STORY_ARGS and does not change anything', () => {
const navigate = jest.fn();
const emit = jest.fn();
const on = jest.fn();
const store = createMockStore();
const {
api: { setStories, updateStoryArgs },
init,
} = initStories({ store, navigate, provider });
} = initStories({ store, navigate, provider, fullAPI: { emit, on } });
setStories({
'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' } },
});
const emit = jest.fn();
init({ api: { emit, on: jest.fn() } });
init();
updateStoryArgs('a--1', { foo: 'bar' });
expect(emit).toHaveBeenCalledWith(UPDATE_STORY_ARGS, 'a--1', { foo: 'bar' });