Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KingSora committed May 9, 2024
1 parent 2acbfbb commit 8915adb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ const updateInstances = (force?: boolean) => {
const checkInstanceState = (osInstance: OverlayScrollbars, before?: boolean) => {
const { host } = osInstance.elements();
const { scrollCoordinates, overflowAmount, hasOverflow } = osInstance.state();
const { start, end } = scrollCoordinates;
const beforeAfter = before ? 'before' : 'after';
const hostId = host.id;

Expand All @@ -233,13 +234,13 @@ const checkInstanceState = (osInstance: OverlayScrollbars, before?: boolean) =>
);
}

should(scrollCoordinates.end.x).equal(
should(Math.abs(start.x + end.x)).equal(
overflowAmount.x,
`Scroll Coordinates for EndX must equal overflow amount ${beforeAfter} appear. (${hostId})`
`ScrollCoordinatesX must equal overflowAmountX ${beforeAfter} appear. (${hostId})`
);
should(scrollCoordinates.end.y).equal(
should(Math.abs(start.y + end.y)).equal(
overflowAmount.y,
`Scroll Coordinates for EndY must equal overflow amount ${beforeAfter} appear. (${hostId})`
`ScrollCoordinatesY must equal overflowAmountY ${beforeAfter} appear. (${hostId})`
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,21 @@ const assetScrollbarClickStopsPropagation = (osInstance: OverlayScrollbars) => {

const assertScrollCoordinates = (osInstance: OverlayScrollbars) => {
const { target } = osInstance.elements();
const { end } = osInstance.state().scrollCoordinates;
const hostId = target === document.body ? 'body' : target.getAttribute('id');

should(end.x).not.equal(0, `Scroll Coordinate EndX is incorrect for "${hostId}".`);
should(end.y).not.equal(0, `Scroll Coordinate EndY is incorrect for "${hostId}".`);
const { scrollCoordinates, overflowAmount } = osInstance.state();
const { start, end } = scrollCoordinates;

should.equal(
Math.abs(start.x + end.x),
overflowAmount.x,
`OverflowAmountX and ScrollCoordinatesX matches for "${hostId}".`
);
should.equal(
Math.abs(start.y + end.y),
overflowAmount.y,
`OverflowAmountY and ScrollCoordinatesY matches for "${hostId}".`
);
};

const runBlock = async () => {
Expand Down

0 comments on commit 8915adb

Please sign in to comment.