diff --git a/src/state/middleware/dimension-marshal-stopper.js b/src/state/middleware/dimension-marshal-stopper.js index 9ef54a27e6..6f63346946 100644 --- a/src/state/middleware/dimension-marshal-stopper.js +++ b/src/state/middleware/dimension-marshal-stopper.js @@ -4,7 +4,7 @@ import type { DimensionMarshal } from '../dimension-marshal/dimension-marshal-ty export default (getMarshal: () => DimensionMarshal) => () => (next: (Action) => mixed) => (action: Action): mixed => { - // Not stopping a bulk collection on a 'DROP' as we want that collection to continue + // Not stopping a collection on a 'DROP' as we want that collection to continue if (action.type === 'DROP_COMPLETE' || action.type === 'CLEAN' || action.type === 'DROP_ANIMATE') { const marshal: DimensionMarshal = getMarshal(); marshal.stopPublishing(); diff --git a/src/view/draggable/draggable.jsx b/src/view/draggable/draggable.jsx index f28d61ed28..e61f07de32 100644 --- a/src/view/draggable/draggable.jsx +++ b/src/view/draggable/draggable.jsx @@ -102,11 +102,11 @@ export default class Draggable extends Component { ); } - onMoveEnd = () => { - if (this.props.isDropAnimating) { - this.props.dropAnimationFinished(); + onMoveEnd = () => { + if (this.props.isDropAnimating) { + this.props.dropAnimationFinished(); + } } - } onLift = (options: {clientSelection: Position, autoScrollMode: AutoScrollMode}) => { timings.start('LIFT'); diff --git a/test/unit/state/middleware/dimension-marshal-stopper.spec.js b/test/unit/state/middleware/dimension-marshal-stopper.spec.js index 1db97bfe05..d644517a1b 100644 --- a/test/unit/state/middleware/dimension-marshal-stopper.spec.js +++ b/test/unit/state/middleware/dimension-marshal-stopper.spec.js @@ -4,8 +4,8 @@ import type { DimensionMarshal } from '../../../../src/state/dimension-marshal/d import middleware from '../../../../src/state/middleware/dimension-marshal-stopper'; import dropMiddleware from '../../../../src/state/middleware/drop'; import createStore from './util/create-store'; -import { clean, prepare, initialPublish, drop, bulkReplace, completeDrop, animateDrop } from '../../../../src/state/action-creators'; -import { initialPublishArgs, initialBulkReplaceArgs, getDragStart } from '../../../utils/preset-action-args'; +import { clean, prepare, initialPublish, drop, completeDrop, animateDrop, collectionStarting } from '../../../../src/state/action-creators'; +import { initialPublishArgs, getDragStart } from '../../../utils/preset-action-args'; import noImpact from '../../../../src/state/no-impact'; const getMarshal = (stopPublishing: Function): DimensionMarshal => { @@ -40,7 +40,9 @@ it('should not stop a collection if a drop is pending', () => { store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); - expect(store.getState().phase).toBe('BULK_COLLECTING'); + expect(store.getState().phase).toBe('DRAGGING'); + store.dispatch(collectionStarting()); + expect(store.getState().phase).toBe('COLLECTING'); expect(stopPublishing).not.toHaveBeenCalled(); // dropping @@ -59,7 +61,6 @@ it('should stop a collection if a drag is complete', () => { store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); expect(stopPublishing).not.toHaveBeenCalled(); @@ -84,7 +85,6 @@ it('should stop a collection if a drop animation starts', () => { store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); expect(stopPublishing).not.toHaveBeenCalled(); diff --git a/test/unit/state/middleware/drop.spec.js b/test/unit/state/middleware/drop.spec.js index 751abef2fc..83d5ffb50d 100644 --- a/test/unit/state/middleware/drop.spec.js +++ b/test/unit/state/middleware/drop.spec.js @@ -1,25 +1,24 @@ // @flow -import type { Position } from 'css-box-model'; import invariant from 'tiny-invariant'; import middleware from '../../../../src/state/middleware/drop'; import createStore from './util/create-store'; import getHomeLocation from '../../../../src/state/get-home-location'; import { add, patch } from '../../../../src/state/position'; import { getPreset, makeScrollable } from '../../../utils/dimension'; +import passThrough from './util/pass-through-middleware'; import { clean, drop, prepare, initialPublish, - bulkReplace, animateDrop, dropPending, move, completeDrop, updateDroppableScroll, + moveByWindowScroll, type InitialPublishArgs, - type BulkReplaceArgs, - type DropAnimateAction, moveByWindowScroll, + type DropAnimateAction, collectionStarting, } from '../../../../src/state/action-creators'; import { initialPublishArgs, @@ -60,7 +59,6 @@ it('should throw an error if a drop action occurs while not in a phase where you store.dispatch(clean()); store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); // moving a little bit so that a drop animation will be needed @@ -75,22 +73,20 @@ it('should throw an error if a drop action occurs while not in a phase where you expect(() => store.dispatch(drop({ reason: 'DROP' }))).toThrow(); }); -it('should dispatch a DROP_PENDING action if BULK_COLLECTING', () => { +it('should dispatch a DROP_PENDING action if COLLECTING', () => { const mock = jest.fn(); - const passThrough = () => next => (action) => { - mock(action); - next(action); - }; const store: Store = createStore( - passThrough, + passThrough(mock), middleware, ); store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); + expect(store.getState().phase).toBe('DRAGGING'); + store.dispatch(collectionStarting()); // now in the bulk collecting phase - expect(store.getState().phase).toBe('BULK_COLLECTING'); + expect(store.getState().phase).toBe('COLLECTING'); mock.mockReset(); // drop @@ -102,22 +98,19 @@ it('should dispatch a DROP_PENDING action if BULK_COLLECTING', () => { expect(store.getState().phase).toBe('DROP_PENDING'); }); -it.only('should throw if a drop action is fired and there is DROP_PENDING and it is waiting for a publish', () => { +it('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); - next(action); - }; const store: Store = createStore( - passThrough, + passThrough(mock), middleware, ); store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); + store.dispatch(collectionStarting()); // now in the bulk collecting phase - expect(store.getState().phase).toBe('BULK_COLLECTING'); + expect(store.getState().phase).toBe('COLLECTING'); mock.mockReset(); // drop moving to drop pending @@ -142,19 +135,14 @@ describe('no drop animation required', () => { describe(`with drop reason: ${reason}`, () => { it('should fire a complete drop action is no drop animation is required', () => { const mock = jest.fn(); - const passThrough = () => next => (action) => { - mock(action); - next(action); - }; const store: Store = createStore( - passThrough, + passThrough(mock), middleware, ); store.dispatch(clean()); store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); // no movement yet @@ -188,12 +176,8 @@ describe('no drop animation required', () => { describe('drop animation required', () => { const withPassThrough = (myMiddleware: mixed, mock: Function): Store => { - const passThrough = () => next => (action) => { - mock(action); - next(action); - }; const store: Store = createStore( - passThrough, + passThrough(mock), myMiddleware, ); return store; @@ -206,7 +190,6 @@ describe('drop animation required', () => { store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); // moving a little bit so that a drop animation will be needed @@ -254,7 +237,6 @@ describe('drop animation required', () => { store.dispatch(clean()); store.dispatch(prepare()); store.dispatch(initialPublish(customArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); // doing a small scroll @@ -290,12 +272,12 @@ describe('drop animation required', () => { const store: Store = withPassThrough(middleware, mock); const scrollableForeign: DroppableDimension = makeScrollable(preset.foreign); - const customReplace: BulkReplaceArgs = { - ...initialBulkReplaceArgs, + const customInitial: InitialPublishArgs = { + ...initialPublishArgs, dimensions: { - ...initialBulkReplaceArgs.dimensions, + ...initialPublishArgs.dimensions, droppables: { - ...initialBulkReplaceArgs.dimensions.droppables, + ...initialPublishArgs.dimensions.droppables, [scrollableForeign.descriptor.id]: scrollableForeign, }, }, @@ -304,8 +286,7 @@ describe('drop animation required', () => { // getting into a drag store.dispatch(clean()); store.dispatch(prepare()); - store.dispatch(initialPublish(initialPublishArgs)); - store.dispatch(bulkReplace(customReplace)); + store.dispatch(initialPublish(customInitial)); expect(store.getState().phase).toBe('DRAGGING'); // moving over the foreign droppable @@ -356,7 +337,6 @@ describe('drop animation required', () => { // getting into a drag store.dispatch(prepare()); store.dispatch(initialPublish(customArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); // move after the end of the home droppable @@ -421,7 +401,6 @@ describe('drop animation required', () => { // getting into a drag store.dispatch(prepare()); store.dispatch(initialPublish(customArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); // moving to the top of the foreign droppable @@ -474,7 +453,6 @@ describe('drop animation required', () => { store.dispatch(clean()); store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); // scroll the window diff --git a/test/unit/state/middleware/lift.spec.js b/test/unit/state/middleware/lift.spec.js index c06435b684..9d0cbb9a11 100644 --- a/test/unit/state/middleware/lift.spec.js +++ b/test/unit/state/middleware/lift.spec.js @@ -1,5 +1,4 @@ // @flow -import { bindActionCreators } from 'redux'; import type { Store, PendingDrop } from '../../../../src/types'; import type { DimensionMarshal, Callbacks } from '../../../../src/state/dimension-marshal/dimension-marshal-types'; import middleware from '../../../../src/state/middleware/lift'; @@ -10,34 +9,26 @@ import { prepare, lift, initialPublish, - bulkReplace, clean, + publish, animateDrop, completeDrop, - bulkCollectionStarting, + collectionStarting, updateDroppableScroll, updateDroppableIsEnabled, } from '../../../../src/state/action-creators'; +import getDimensionMarshal, { populateMarshal } from '../../../utils/dimension-marshal'; import getHomeLocation from '../../../../src/state/get-home-location'; import { viewport, liftArgs, initialPublishArgs, - initialBulkReplaceArgs, getDragStart, critical, } from '../../../utils/preset-action-args'; -import createDimensionMarshal from '../../../../src/state/dimension-marshal/dimension-marshal'; -import { populateMarshal } from '../../../utils/dimension-marshal'; const getMarshal = (store: Store): DimensionMarshal => { - const callbacks: Callbacks = bindActionCreators({ - bulkCollectionStarting, - bulkReplace, - updateDroppableScroll, - updateDroppableIsEnabled, - }, store.dispatch); - const marshal: DimensionMarshal = createDimensionMarshal(callbacks); + const marshal: DimensionMarshal = getDimensionMarshal(store.dispatch); populateMarshal(marshal); return marshal; @@ -95,7 +86,6 @@ it('should flush any animating drops', () => { // start a drag store.dispatch(prepare()); store.dispatch(initialPublish(initialPublishArgs)); - store.dispatch(bulkReplace(initialBulkReplaceArgs)); expect(store.getState().phase).toBe('DRAGGING'); // start a drop @@ -104,7 +94,9 @@ it('should flush any animating drops', () => { impact: { movement: { displaced: [], - amount: 0, + amount: { + x: 0, y: 0, + }, isBeyondStartPosition: false, }, direction: 'vertical', @@ -153,7 +145,7 @@ describe('collection phase', () => { expect(mock).not.toHaveBeenCalled(); }); - it('should publish the critical dimensions and then trigger a non-critical dimension collection', () => { + it('should publish the initial dimensions', () => { const mock = jest.fn(); const store: Store = createStore( passThrough(mock), @@ -170,14 +162,6 @@ describe('collection phase', () => { mock.mockReset(); jest.runOnlyPendingTimers(); expect(mock).toHaveBeenCalledWith(initialPublish(initialPublishArgs)); - expect(mock).toHaveBeenCalledWith(bulkCollectionStarting()); - expect(mock).toHaveBeenCalledTimes(2); - expect(store.getState().phase).toBe('BULK_COLLECTING'); - - // then there is a dimension marshal collection - mock.mockReset(); - requestAnimationFrame.flush(); - expect(mock).toHaveBeenCalledWith(bulkReplace(initialBulkReplaceArgs)); expect(mock).toHaveBeenCalledTimes(1); expect(store.getState().phase).toBe('DRAGGING'); }); diff --git a/test/unit/state/middleware/style.spec.js b/test/unit/state/middleware/style.spec.js new file mode 100644 index 0000000000..658f3f6835 --- /dev/null +++ b/test/unit/state/middleware/style.spec.js @@ -0,0 +1,3 @@ +// @flow + +throw new Error('TODO'); diff --git a/test/utils/dimension-marshal.js b/test/utils/dimension-marshal.js index d02cd25a1d..6ff4ee051b 100644 --- a/test/utils/dimension-marshal.js +++ b/test/utils/dimension-marshal.js @@ -1,11 +1,12 @@ // @flow import { type Position } from 'css-box-model'; -import bindActionCreators from 'redux'; +import { bindActionCreators } from 'redux'; import createDimensionMarshal from '../../src/state/dimension-marshal/dimension-marshal'; import { publish, updateDroppableScroll, updateDroppableIsEnabled, + collectionStarting, } from '../../src/state/action-creators'; import { getPreset } from './dimension'; import type { DimensionMarshal, Callbacks, DroppableCallbacks } from '../../src/state/dimension-marshal/dimension-marshal-types'; @@ -20,6 +21,7 @@ import type { export default (dispatch: Function): DimensionMarshal => { const callbacks: Callbacks = bindActionCreators({ publish, + collectionStarting, updateDroppableScroll, updateDroppableIsEnabled, }, dispatch);