Skip to content

Commit

Permalink
test test tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 21, 2018
1 parent edc21bb commit 23f50d5
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/state/create-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default ({

// > uncomment to use
// debugging logger
// require('./debug-middleware/log-middleware').default,
require('./debug-middleware/log-middleware').default,
// debugging timer
// require('./debug-middleware/timing-middleware').default,
// average action timer
Expand Down
2 changes: 1 addition & 1 deletion src/state/dimension-marshal/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default ({
critical: includeCritical ? critical : null,
});
timings.finish('Bulk dimension publish');
}, 0);
}, 200);
frameId = null;
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/state/middleware/auto-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { AutoScroller } from '../auto-scroller/auto-scroller-types';
import type { DimensionMarshal } from '../../state/dimension-marshal/dimension-marshal-types';
import { move } from '../action-creators';
import scrollWindow from '../../view/window/scroll-window';
import isDragEnding from './util/is-drag-ending';
import type {
DraggableId,

Expand All @@ -32,7 +31,8 @@ export default (getMarshal: () => DimensionMarshal) =>

const shouldCancel = (action: Action) =>
// Need to cancel any pending auto scrolling when drag is ending
isDragEnding(action) ||
action.type === 'CANCEL' ||
action.type === 'DROP' ||
// A new bulk collection is starting - cancel any pending auto scrolls
action.type === 'BULK_COLLECTION_STARTING';

Expand Down
4 changes: 2 additions & 2 deletions src/state/middleware/dimension-marshal-stopper.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @flow
import isDragEnding from './util/is-drag-ending';
import type { Action } from '../../types';
import type { DimensionMarshal } from '../dimension-marshal/dimension-marshal-types';

export default (getMarshal: () => DimensionMarshal) =>
() => (next: (Action) => mixed) => (action: Action): mixed => {
if (isDragEnding(action)) {
// Not stopping a bulk 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();
}
Expand Down
5 changes: 0 additions & 5 deletions src/state/middleware/util/is-drag-ending.js

This file was deleted.

73 changes: 68 additions & 5 deletions test/unit/state/scroll-viewport.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import { getRect, type Position, type Rect } from 'css-box-model';
import type { Viewport } from '../../../src/types';
import { add, negate } from '../../../src/state/position';
import { add, negate, subtract } from '../../../src/state/position';
import scrollViewport from '../../../src/state/scroll-viewport';
import { offsetByPosition } from '../../../src/state/spacing';

Expand Down Expand Up @@ -51,20 +51,22 @@ it('should update the window details scroll', () => {
expect(updated).toEqual(expected);
});

it('should correctly update scroll across multiple movements', () => {
it('should correctly update scroll across multiple movements (forwards)', () => {
const original: Rect = getRect({
top: 0,
left: 0,
right: 100,
bottom: 100,
});

const max: Position = { x: 200, y: 200 };

let lastViewport: Viewport = {
frame: original,
scroll: {
initial: origin,
current: origin,
max: { x: 1000, y: 1000 },
max,
diff: {
value: origin,
displacement: origin,
Expand All @@ -73,8 +75,9 @@ it('should correctly update scroll across multiple movements', () => {
};

let lastScroll: Position = origin;
let runCount: number = 0;

Array.from({ length: 5 }).forEach(() => {
while (lastScroll.y < max.y && lastScroll.x < max.x) {
const newScroll: Position = add(lastScroll, { x: 10, y: 20 });
const updated: Viewport = scrollViewport(lastViewport, newScroll);

Expand All @@ -83,7 +86,7 @@ it('should correctly update scroll across multiple movements', () => {
scroll: {
initial: origin,
current: newScroll,
max: { x: 1000, y: 1000 },
max,
diff: {
value: newScroll,
displacement: negate(newScroll),
Expand All @@ -96,5 +99,65 @@ it('should correctly update scroll across multiple movements', () => {

lastScroll = newScroll;
lastViewport = updated;
runCount++;
};

// Simply asserting our loop ran a few times
expect(runCount).toBeGreaterThan(2);
});

it('should correctly update scroll across multiple movements (backwards)', () => {
const original: Rect = getRect({
top: 0,
left: 0,
right: 100,
bottom: 100,
});

const max: Position = { x: 200, y: 200 };

let lastViewport: Viewport = {
frame: original,
scroll: {
initial: max,
current: max,
max,
diff: {
value: origin,
displacement: origin,
},
},
};

let lastScroll: Position = max;
let runCount: number = 0;
while (lastScroll.y > 0 && lastScroll.x > 0) {
const newScroll: Position = subtract(lastScroll, { x: 10, y: 20 });
const updated: Viewport = scrollViewport(lastViewport, newScroll);

const diff: Position = subtract(newScroll, lastViewport.scroll.initial);

const expected: Viewport = {
frame: getRect(offsetByPosition(original, newScroll)),
scroll: {
initial: max,
current: newScroll,
max,
diff: {
value: diff,
displacement: negate(diff),
},
},
};
expect(updated).toEqual(expected);
expect(updated.frame.top).toEqual(newScroll.y);
expect(updated.frame.left).toEqual(newScroll.x);

lastScroll = newScroll;
lastViewport = updated;
runCount++;
}

// Simply asserting our loop ran a few times
expect(runCount).toBeGreaterThan(2);
});

0 comments on commit 23f50d5

Please sign in to comment.