Skip to content

Commit

Permalink
getting into it
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 14, 2018
1 parent d936e96 commit 7f77585
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
12 changes: 12 additions & 0 deletions test/unit/state/middleware/create-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @flow
import { createStore, composeEnhances, applyMiddleware } from 'redux';
import reducer from '../../../../src/state/reducer';
import type { Store } from '../../../../src/types';

export default (...middleware: mixed[]): Store => createStore(
reducer,
composeEnhances(
applyMiddleware(...middleware)
)
);

44 changes: 43 additions & 1 deletion test/unit/state/middleware/hooks/hooks.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
// @flow
import middleware from '../../../../../src/state/middleware/hooks';
import { prepare, initialPublish } from '../../../../../src/state/action-creators';
import createStore from '../create-store';
import type { Store, Hooks, Announce } from '../../../../../src/types';

const createHooks = (): Hooks => ({
onDragStart: jest.fn(),
onDragUpdate: jest.fn(),
onDragEnd: jest.fn(),
});

const getAnnounce = (): Announce => jest.fn();

describe('start', () => {
it('should call the onDragStart hook when a initial publish occurs', () => {
const hooks: Hooks = createHooks();
const store: Store = createStore(
middleware(() => hooks, getAnnounce())
);

// prepare step should not trigger hook
store.dispatch(prepare());
expect(hooks.onDragStart).not.toHaveBeenCalled();

// first initial publish
store.dispatch(initialPublish({

}));
expect(hooks.onDragStart).toHaveBeenCalledWith({

});
});

it('should throw an exception if an initial publish is called before a drag ends', () => {

const hooks: Hooks = createHooks();
const store: Store = createStore(
middleware(() => hooks, getAnnounce())
);

const execute = () => {
store.dispatch(initialPublish({

}));
};
// first execution is all good
execute();
expect(hooks.onDragStart).toHaveBeenCalled();

// should not happen
expect(execute).toThrow();
});
});

Expand Down

0 comments on commit 7f77585

Please sign in to comment.