Skip to content

Commit

Permalink
test: update
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Jan 19, 2024
1 parent 59bd765 commit 3127a47
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/dom/test/functional/top-layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,16 @@ test('top-layer, dialog, no transform, stack on dialog', async ({page}) => {

test('flip collision', async ({page}) => {
await page.goto('http://localhost:1234/top-layer');
await click(page, '[data-testid="collision-true"]');
await click(page, '#reference');

await page.evaluate(() => window.scrollTo(0, 130));
await page.evaluate(() => window.scrollTo(0, 86));

expect(await page.locator('.host').screenshot()).toMatchSnapshot(
`top-layer.no-flip.png`,
);

await page.evaluate(() => window.scrollTo(0, 140));
await page.evaluate(() => window.scrollTo(0, 96));

expect(await page.locator('.host').screenshot()).toMatchSnapshot(
`top-layer.flip.png`,
Expand Down
1 change: 1 addition & 0 deletions packages/dom/test/visual/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ main {
background: turquoise;
width: 80px;
height: 80px;
outline: none;
}

.arrow {
Expand Down
28 changes: 26 additions & 2 deletions packages/dom/test/visual/spec/TopLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ export function TopLayer() {
const [withTransform, setWithTransform] = useState(true);
const [withPopover, setPopover] = useState(true);
const [stackedOn, setStackedOn] = useState<STACKED_TYPES>('none');
const [collision, setCollision] = useState(false);

const {x, y, strategy, refs} = useFloating({
whileElementsMounted: autoUpdate,
placement: 'top',
strategy: 'fixed',
middleware: [withMiddleware && topLayer(), flip(), shift()],
middleware: [withMiddleware && topLayer(), collision && flip()],
});

const tooltipStyles = {
Expand Down Expand Up @@ -192,7 +193,11 @@ export function TopLayer() {
return (
<>
<style>{styles}</style>
<h1>Top Layer</h1>
<h1
style={{display: 'flex', alignItems: 'center', height: 100, margin: 0}}
>
Top Layer
</h1>
<Stack {...stackProps}>
<div
className={classes}
Expand Down Expand Up @@ -235,13 +240,32 @@ export function TopLayer() {
position: strategy,
top: y,
left: x,
...(collision && {
height: 100,
}),
}}
>
Floating
</dialog>
</div>
</Stack>

<h2>Collision</h2>
<Controls>
{BOOLS.map((bool) => (
<button
key={String(bool)}
data-testid={`collision-${bool}`}
onClick={() => setCollision(bool)}
style={{
backgroundColor: bool === collision ? 'black' : '',
}}
>
{String(bool)}
</button>
))}
</Controls>

<h2>withMiddleware</h2>
<Controls>
{BOOLS.map((bool) => (
Expand Down

0 comments on commit 3127a47

Please sign in to comment.