Skip to content

Commit

Permalink
Add a test case for this bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pksjce committed Nov 13, 2023
1 parent f8d1a8e commit ec0d263
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/__tests__/anchored-position.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,19 @@ describe('getAnchoredPosition', () => {
expect(top).toEqual(54) // anchorRect.top + anchorRect.height + (settings.anchorOffset ?? 4) - parentRect.top
expect(left).toEqual(380) // anchorRect.left + anchorRect.width - parentRect.left - floatingRect.width
})

// This test runs for values derived from a real use case https://github.com/github/accessibility-audits/issues/4515 as run on a local storybook.
it('should overflow to bottom if the element is too tall to fit on the screen when zoomed', () => {
const parentRect = makeDOMRect(0, 0, 0, 0)
const anchorRect = makeDOMRect(16, 16, 32, 32) // left aligned button
const floatingRect = makeDOMRect(0, 0, 256, 428) // 428 is the max height of the screen
const {float, anchor} = createVirtualDOM(parentRect, anchorRect, floatingRect)
const settings: Partial<PositionSettings> = {side: 'outside-bottom', align: 'start'}
const {top, left, anchorSide, anchorAlign} = getAnchoredPosition(float, anchor, settings)
// Not really sure what to expect here.
expect(anchorSide).toEqual('outside-bottom')
expect(anchorAlign).toEqual('center')
expect(top).toEqual(52)
expect(left).toEqual(-256) // Expecting 32, Receiving -256
})
})

0 comments on commit ec0d263

Please sign in to comment.