Skip to content

Commit

Permalink
fixing middleware tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 24, 2018
1 parent 7576193 commit 947748e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/state/create-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default ({
// debugging timer
// require('./debug-middleware/timing-middleware').default,
// average action timer
require('./debug-middleware/timing-average-middleware').default(50),
require('./debug-middleware/timing-average-middleware').default(500),

// ## Application middleware

Expand Down
2 changes: 0 additions & 2 deletions src/state/get-drag-impact/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export default ({
previousDroppableOverId,
});

console.log('destinationId', destinationId);

// not dragging over anything
if (!destinationId) {
return noImpact;
Expand Down
8 changes: 3 additions & 5 deletions src/state/middleware/drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { Position } from 'css-box-model';
import {
dropPending,
completeDrop,
clean,
animateDrop,
} from '../action-creators';
import noImpact from '../no-impact';
Expand Down Expand Up @@ -55,10 +54,9 @@ export default ({ getState, dispatch }: Store) =>
}

// Still waiting for our drop pending to end
if (state.phase === 'DROP_PENDING' && state.isWaiting) {
console.error('A drop action occurred while DROP_PENDING and still waiting');
return;
}
// TODO: should this throw?
const isWaitingForDrop: boolean = state.phase === 'DROP_PENDING' && state.isWaiting;
invariant(!isWaitingForDrop, 'A DROP action occurred while DROP_PENDING and still waiting');

invariant(
state.phase === 'DRAGGING' || state.phase === 'DROP_PENDING',
Expand Down
6 changes: 0 additions & 6 deletions src/state/middleware/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ export default (getHooks: () => Hooks, announce: Announce) => {
const move = (critical: Critical, location: ?DraggableLocation) => {
invariant(isDragStartPublished && lastCritical, 'Cannot fire onDragMove when onDragStart has not been called');

console.log('potential move fired');
console.log('location: ', location);
console.log('lastLocation', lastLocation);
console.log('is critical equal', isCriticalEqual(critical, lastCritical));
console.log('areLocationsEqual', areLocationsEqual(lastLocation, location));

// No change to publish
if (isCriticalEqual(critical, lastCritical) &&
areLocationsEqual(lastLocation, location)) {
Expand Down
3 changes: 2 additions & 1 deletion src/state/middleware/lift.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export default (getMarshal: () => DimensionMarshal) => {
dispatch(prepare());

timeoutId = setTimeout(() => {
// Phase 2: collect initial dimensions
timeoutId = null;
// Phase 2: collect initial dimensions
const state: State = getState();
invariant(state.phase === 'PREPARING', 'Invalid phase for completing lift');

Expand Down
17 changes: 7 additions & 10 deletions test/unit/state/middleware/drop.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ it('should dispatch a DROP_PENDING action if BULK_COLLECTING', () => {
expect(store.getState().phase).toBe('DROP_PENDING');
});

it('should not do anything if a drop action is fired and there is DROP_PENDING and it is waiting for a publish', () => {
it.only('should throw if a drop action is fired and there is DROP_PENDING and it is waiting for a publish', () => {
const mock = jest.fn();
const passThrough = () => next => (action) => {
mock(action);
Expand Down Expand Up @@ -131,10 +131,8 @@ it('should not do anything if a drop action is fired and there is DROP_PENDING a

// Drop action being fired (should not happen?)

mock.mockReset();
store.dispatch(drop({ reason: 'DROP' }));
expect(mock).toHaveBeenCalledTimes(1);
expect(mock).toHaveBeenCalledWith(drop({ reason: 'DROP' }));
expect(() => store.dispatch(drop({ reason: 'DROP' })))
.toThrow('A DROP action occurred while DROP_PENDING and still waiting');
});

describe('no drop animation required', () => {
Expand Down Expand Up @@ -179,8 +177,7 @@ describe('no drop animation required', () => {
};
expect(mock).toHaveBeenCalledWith(drop({ reason }));
expect(mock).toHaveBeenCalledWith(completeDrop(result));
expect(mock).toHaveBeenCalledWith(clean());
expect(mock).toHaveBeenCalledTimes(3);
expect(mock).toHaveBeenCalledTimes(2);

// reset to initial phase
expect(store.getState().phase).toBe('IDLE');
Expand Down Expand Up @@ -496,14 +493,14 @@ describe('drop animation required', () => {
movement: {
displaced: [],
amount: patch(axis.line, preset.inHome1.client.marginBox[axis.size]),
isBeyondStartPosition: false,
isBeyondStartPosition: true,
},
direction: preset.home.axis.direction,
destination: getHomeLocation(initialPublishArgs.critical),
destination: getHomeLocation(),
},
result: {
...getDragStart(),
destination: getHomeLocation(initialPublishArgs.critical),
destination: getHomeLocation(),
reason: 'DROP',
},
};
Expand Down
6 changes: 1 addition & 5 deletions test/unit/state/middleware/hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
moveDown,
move,
bulkCollectionStarting,
type MoveArgs,
type MoveArgs, animateDrop,
} from '../../../../src/state/action-creators';
import createStore from './util/create-store';
import { viewport, initialPublishArgs, initialBulkReplaceArgs, getDragStart } from '../../../utils/preset-action-args';
Expand Down Expand Up @@ -381,10 +381,6 @@ describe('abort', () => {
});
});

describe('drop flushing', () => {
throw new Error('TODO');
});

describe('subsequent drags', () => {
it('should behave correctly across multiple drags', () => {
const hooks: Hooks = createHooks();
Expand Down
4 changes: 4 additions & 0 deletions test/unit/state/middleware/lift.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { DimensionMarshal, Callbacks } from '../../../../src/state/dimensio
import middleware from '../../../../src/state/middleware/lift';
import createStore from './util/create-store';
import passThrough from './util/pass-through-middleware';
import { setViewport, resetViewport } from '../../../utils/viewport';
import {
prepare,
lift,
Expand All @@ -18,6 +19,7 @@ import {
updateDroppableIsEnabled,
} from '../../../../src/state/action-creators';
import {
viewport,
liftArgs,
initialPublishArgs,
initialBulkReplaceArgs,
Expand All @@ -41,10 +43,12 @@ const getMarshal = (store: Store): DimensionMarshal => {
};

beforeEach(() => {
setViewport(viewport);
jest.useFakeTimers();
});

afterEach(() => {
resetViewport();
jest.clearAllTimers();
jest.useRealTimers();
});
Expand Down
3 changes: 1 addition & 2 deletions test/unit/state/middleware/pending-drop.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ it('should trigger a drop on a bulk replace if a drop pending is waiting', () =>
reason: 'DROP',
};
expect(mock).toHaveBeenCalledWith(completeDrop(result));
expect(mock).toHaveBeenCalledWith(clean());
expect(mock).toHaveBeenCalledTimes(4);
expect(mock).toHaveBeenCalledTimes(3);
expect(store.getState().phase).toBe('IDLE');
});

Expand Down

0 comments on commit 947748e

Please sign in to comment.