Skip to content

Commit

Permalink
Internal: add Masonry parent-sizing integration test (#2678)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangerismycat authored Mar 2, 2023
1 parent f366943 commit abfc2b9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/pages/integration-test/masonry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ function booleanize(value: string): boolean {

export default function TestPage(): Node {
const router = useRouter();
const { flexible, offsetTop, scrollContainer, virtualize } = router.query;
const { constrained, finiteLength, flexible, offsetTop, scrollContainer, virtualize } =
router.query;

return (
<ColorSchemeProvider colorScheme="light">
<MasonryContainer
constrained={booleanize(constrained)}
finiteLength={booleanize(finiteLength)}
flexible={booleanize(flexible)}
initialItems={generateExampleItems({ name: 'InitialPin' })}
MasonryComponent={Masonry}
Expand Down
25 changes: 25 additions & 0 deletions playwright/masonry/parent-sizing.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// @flow strict
import { expect, test } from '@playwright/test';
import getGridItems from './utils/getGridItems.mjs';
import getServerURL from './utils/getServerURL.mjs';

// Hard-coded in docs/integration-test-helpers/masonry/MasonryContainer.js
const EXPECTED_LEFT_MARGIN = 200;

test.describe('Masonry: Parent Sizing', () => {
test('starts the grid from the left bounding box of the parent', async ({
page,
}) => {
await page.goto(
getServerURL({ virtualize: true, finiteLength: true, constrained: true })
);

// Assert that all items follow the indentation of the grid.
const gridItems = await getGridItems(page);

for (let i = 0; i < gridItems.length; i += 1) {
const itemRect = await gridItems[i].boundingBox();
expect(itemRect.x).toBeGreaterThanOrEqual(EXPECTED_LEFT_MARGIN);
}
});
});
2 changes: 2 additions & 0 deletions playwright/masonry/utils/getServerURL.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const normalizeValue = (val) => {

/*::
type Options = ?{|
constrained?: boolean,
finiteLength?: boolean,
flexible?: boolean,
offsetTop?: number,
scrollContainer?: boolean,
Expand Down

0 comments on commit abfc2b9

Please sign in to comment.