Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 18, 2018
1 parent d8d2710 commit 481f7ab
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 119 deletions.
161 changes: 50 additions & 111 deletions test/unit/state/auto-scroll/fluid-scroller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('fluid auto scrolling', () => {
requestAnimationFrame.reset();
});

[vertical /*, horizontal*/].forEach((axis: Axis) => {
[vertical, horizontal].forEach((axis: Axis) => {
describe(`on the ${axis.direction} axis`, () => {
const preset = getPreset(axis);
const state = getStatePreset(axis);
Expand Down Expand Up @@ -283,19 +283,10 @@ describe('fluid auto scrolling', () => {
borderBox: expanded,
});
const selection: Position = onMaxBoundary;
const custom: DraggingState = (() => {
const base: DraggingState = state.dragging(
preset.inHome1.descriptor.id,
selection,
);

const updated: DraggingState = {
...base,
dimensions: addDraggable(base.dimensions, tooBig),
};

return updated;
})();
const custom: DraggingState = addDraggable(state.dragging(
preset.inHome1.descriptor.id,
selection,
), tooBig);

fluidScroll(custom);

Expand Down Expand Up @@ -371,7 +362,7 @@ describe('fluid auto scrolling', () => {
fluidScroll(dragTo({
selection: target2,
viewport: scrolledViewport,
}) );
}));

expect(mocks.scrollWindow).not.toHaveBeenCalled();

Expand Down Expand Up @@ -449,17 +440,10 @@ describe('fluid auto scrolling', () => {
borderBox: expanded,
});
const selection: Position = onMaxBoundary;
const custom: DraggingState = (() => {
const base: DraggingState = state.dragging(
preset.inHome1.descriptor.id,
selection,
);

return {
...base,
dimensions: addDraggable(base.dimensions, tooBig),
};
})();
const custom: DraggingState = addDraggable(state.dragging(
preset.inHome1.descriptor.id,
selection,
), tooBig);

fluidScroll(custom);

Expand Down Expand Up @@ -577,18 +561,11 @@ describe('fluid auto scrolling', () => {
});

const selection: Position = onMaxBoundaryOfBoth;
const custom: DraggingState = (() => {
const base: DraggingState = state.dragging(
preset.inHome1.descriptor.id,
selection,
scrollableViewport,
);

return {
...base,
dimensions: addDraggable(base.dimensions, tooBigOnMainAxis),
};
})();
const custom: DraggingState = addDraggable(state.dragging(
preset.inHome1.descriptor.id,
selection,
scrollableViewport,
), tooBigOnMainAxis);

fluidScroll(custom);

Expand All @@ -612,18 +589,11 @@ describe('fluid auto scrolling', () => {
});

const selection: Position = onMaxBoundaryOfBoth;
const custom: DraggingState = (() => {
const base: DraggingState = state.dragging(
preset.inHome1.descriptor.id,
selection,
scrollableViewport,
);

return {
...base,
dimensions: addDraggable(base.dimensions, tooBigOnCrossAxis),
};
})();
const custom: DraggingState = addDraggable(state.dragging(
preset.inHome1.descriptor.id,
selection,
scrollableViewport,
), tooBigOnCrossAxis);

fluidScroll(custom);

Expand All @@ -646,18 +616,11 @@ describe('fluid auto scrolling', () => {
});

const selection: Position = onMaxBoundaryOfBoth;
const custom: DraggingState = (() => {
const base: DraggingState = state.dragging(
preset.inHome1.descriptor.id,
selection,
scrollableViewport,
);

return {
...base,
dimensions: addDraggable(base.dimensions, tooBig),
};
})();
const custom: DraggingState = addDraggable(state.dragging(
preset.inHome1.descriptor.id,
selection,
scrollableViewport,
), tooBig);

fluidScroll(custom);

Expand Down Expand Up @@ -695,13 +658,10 @@ describe('fluid auto scrolling', () => {
);

it('should not scroll if not past the start threshold', () => {
autoScroller.onStateChange(
state.idle,
addDroppable(dragTo({
selection: onStartBoundary,
viewport: unscrollableViewport,
}), scrollable)
);
fluidScroll(addDroppable(dragTo({
selection: onStartBoundary,
viewport: unscrollableViewport,
}), scrollable));

requestAnimationFrame.flush();
expect(mocks.scrollDroppable).not.toHaveBeenCalled();
Expand All @@ -710,21 +670,18 @@ describe('fluid auto scrolling', () => {
it('should scroll if moving beyond the start threshold', () => {
const target: Position = add(onStartBoundary, patch(axis.line, 1));

autoScroller.onStateChange(
state.idle,
addDroppable(dragTo({
selection: target,
viewport: unscrollableViewport,
}), scrollable),
);
fluidScroll(addDroppable(dragTo({
selection: target,
viewport: unscrollableViewport,
}), scrollable));

expect(mocks.scrollDroppable).not.toHaveBeenCalled();

// only called after a frame
requestAnimationFrame.step();
expect(mocks.scrollDroppable).toHaveBeenCalled();
// moving forwards
const [id, scroll] = mocks.scrollDroppable.mock.calls[0];
const { id, scroll } = mocks.scrollDroppable.mock.calls[0];

expect(id).toBe(scrollable.descriptor.id);
expect(scroll[axis.line]).toBeGreaterThan(0);
Expand All @@ -735,23 +692,14 @@ describe('fluid auto scrolling', () => {
const target1: Position = add(onStartBoundary, patch(axis.line, 1));
const target2: Position = add(onStartBoundary, patch(axis.line, 2));

autoScroller.onStateChange(
state.idle,
addDroppable(dragTo({
selection: target1,
viewport: unscrollableViewport,
}), scrollable),
);
autoScroller.onStateChange(
addDroppable(dragTo({
selection: target1,
viewport: unscrollableViewport,
}), scrollable),
addDroppable(dragTo({
selection: target2,
viewport: unscrollableViewport,
}), scrollable),
);
fluidScroll(addDroppable(dragTo({
selection: target1,
viewport: unscrollableViewport,
}), scrollable));
fluidScroll(addDroppable(dragTo({
selection: target2,
viewport: unscrollableViewport,
}), scrollable));

expect(mocks.scrollDroppable).not.toHaveBeenCalled();

Expand All @@ -770,27 +718,18 @@ describe('fluid auto scrolling', () => {
const target1: Position = add(onStartBoundary, patch(axis.line, 1));
const target2: Position = add(onStartBoundary, patch(axis.line, 2));

autoScroller.onStateChange(
state.idle,
addDroppable(dragTo({
selection: target1,
viewport: unscrollableViewport,
}), scrollable),
);
fluidScroll(addDroppable(dragTo({
selection: target1,
viewport: unscrollableViewport,
}), scrollable));
requestAnimationFrame.step();
expect(mocks.scrollDroppable).toHaveBeenCalledTimes(1);
const scroll1: Position = (mocks.scrollDroppable.mock.calls[0][1] : any);

autoScroller.onStateChange(
addDroppable(dragTo({
selection: target1,
viewport: unscrollableViewport,
}), scrollable),
addDroppable(dragTo({
selection: target2,
viewport: unscrollableViewport,
}), scrollable),
);
fluidScroll(addDroppable(dragTo({
selection: target2,
viewport: unscrollableViewport,
}), scrollable));
requestAnimationFrame.step();
expect(mocks.scrollDroppable).toHaveBeenCalledTimes(2);
const scroll2: Position = (mocks.scrollDroppable.mock.calls[1][1] : any);
Expand Down
22 changes: 14 additions & 8 deletions test/utils/dimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,31 @@ export const getInitialImpact = (draggable: DraggableDimension, axis?: Axis = ve
return impact;
};

export const addDroppable = (base: State, droppable: DroppableDimension): State => ({
export const addDroppable = (
base: DraggingState,
droppable: DroppableDimension
): DraggingState => ({
...base,
dimensions: {
...base.dimensions,
droppables: {
...base.dimension.droppables,
...base.dimensions.droppables,
[droppable.descriptor.id]: droppable,
},
},
});

export const addDraggable = (
dimensions: DimensionMap,
state: DraggingState,
draggable: DraggableDimension
): DimensionMap => ({
...dimensions,
draggables: {
...dimensions.draggables,
[draggable.descriptor.id]: draggable,
): DraggingState => ({
...state,
dimensions: {
...state.dimensions,
draggables: {
...state.dimensions.draggables,
[draggable.descriptor.id]: draggable,
},
},
});

Expand Down

0 comments on commit 481f7ab

Please sign in to comment.