Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcramer committed Jan 22, 2025
1 parent e2063cd commit 03f42a1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/internal/primitives/DismissableLayer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,19 @@ describe('DismissableLayer', () => {
fireEvent.keyDown(document, { key: 'Escape' });
fireEvent.pointerDown(document.body);
});

it('does not call onDismiss when clicking the trigger button', () => {
render(
<>
<button aria-label="Toggle swap settings">Trigger</button>
<DismissableLayer onDismiss={onDismiss}>
<div>Test Content</div>
</DismissableLayer>
</>,
);

const triggerButton = screen.getByLabelText('Toggle swap settings');
fireEvent.pointerDown(triggerButton);
expect(onDismiss).not.toHaveBeenCalled();
});
});
45 changes: 45 additions & 0 deletions src/internal/primitives/Popover.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,49 @@ describe('Popover', () => {
expect(baseElement.contains(screen.getByTestId('ockPopover'))).toBe(true);
});
});

describe('edge cases', () => {
it('handles null anchorEl gracefully', () => {
render(
<Popover isOpen={true} anchorEl={null} onClose={onClose}>
<div>Content</div>
</Popover>,
);
expect(screen.getByTestId('ockPopover')).toBeInTheDocument();
});

it('handles missing getBoundingClientRect gracefully', () => {
const brokenAnchorEl = document.createElement('button');
vi.spyOn(brokenAnchorEl, 'getBoundingClientRect').mockReturnValue(
null as any,
);

render(
<Popover isOpen={true} anchorEl={brokenAnchorEl} onClose={onClose}>
<div>Content</div>
</Popover>,
);
expect(screen.getByTestId('ockPopover')).toBeInTheDocument();
});
});

describe('focus management', () => {
it('traps focus when open', () => {
render(
<Popover isOpen={true} anchorEl={anchorEl} onClose={onClose}>
<button>First</button>
<button>Second</button>
</Popover>,
);

const firstButton = screen.getByText('First');
const secondButton = screen.getByText('Second');

firstButton.focus();
expect(document.activeElement).toBe(firstButton);

fireEvent.keyDown(firstButton, { key: 'Tab' });
expect(document.activeElement).toBe(secondButton);
});
});
});

0 comments on commit 03f42a1

Please sign in to comment.