Skip to content

Fix overflow not adjusting position #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test tweaks
-    Reverted `collisionHandler` for scroll test, as we ignore collisions
-    Added a hidden check that returns 0 for sizes
  • Loading branch information
glenn2223 committed Sep 12, 2024
commit 70c72573aacac09ca37174edbc6f380f4136e7fa
12 changes: 7 additions & 5 deletions tests/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class Helper {
div.style.height = `${this.targetSize.height}px`;
div.style.width = `${this.targetSize.width}px`;
div.style.position = 'absolute';
div.style.display = 'none';
document.body.insertAdjacentElement('beforeend', div);
}

Expand Down Expand Up @@ -212,16 +213,17 @@ export class Helper {

targetEl!.getBoundingClientRect = jest.fn(() => {
const top = 0,
left = 0;
left = 0,
hiddenSize = targetEl?.style.display === 'none' ? 0 : null;

return {
x: left,
y: top,
width: this.targetSize.width,
height: this.targetSize.height,
width: hiddenSize ?? this.targetSize.width,
height: hiddenSize ?? this.targetSize.height,
top: top,
right: left + this.targetSize.width,
bottom: top + this.targetSize.height,
right: left + (hiddenSize ?? this.targetSize.width),
bottom: top + (hiddenSize ?? this.targetSize.height),
left: left,
toJSON: () => '{}',
};
Expand Down
18 changes: 4 additions & 14 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const windowSize: SizeData = {
'bottom center',
'bottom right',
],
helper = new Helper(CollisionHandler.ignore, anchorSize, targetSize),
collisionHandler: (input: number) => number = (input) => input + 50;
helper = new Helper(CollisionHandler.ignore, anchorSize, targetSize);

helper.setupEnvironment(windowSize);

Expand Down Expand Up @@ -86,18 +85,9 @@ test('Window scroll adjusts output', () => {
left: parseInt(pData.left, 10),
top: parseInt(pData.top, 10),
}).toStrictEqual({
left: helper.getLeft(
targetWindowPosition,
myPlacement,
atPlacement,
collisionHandler,
),
top: helper.getTop(
targetWindowPosition,
myPlacement,
atPlacement,
collisionHandler,
),
left:
helper.getLeft(targetWindowPosition, myPlacement, atPlacement) + 50,
top: helper.getTop(targetWindowPosition, myPlacement, atPlacement) + 50,
});

// Reset the window scroll position
Expand Down