Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tihuan committed Sep 10, 2024
1 parent a727924 commit dde34a7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions client/__tests__/e2e/cellxgeneActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export async function goToPage(page: Page, url = ""): Promise<void> {
await resizeWindow(page);
}

/**
* @param snapshotName - The name of the snapshot. This is optional for cases
* you don't need a snapshot after the action.
*/
export async function drag({
testId,
testInfo,
Expand Down Expand Up @@ -868,6 +872,9 @@ const WAIT_FOR_GRAPH_AS_IMAGE_TIMEOUT_MS = 10_000;
* (thuang): Captures a snapshot of the graph on the canvas element as an image
* for Chromatic snapshot testing.
*
* @param name - The name of the snapshot. The name MUST be unique across the test
* suite to avoid overwriting snapshots.
*
* NOTE: Use this function only for tests that absolutely require graph
* snapshots, as the image layer and graph can sometimes be out of sync,
* potentially leading to false positives in Chromatic if excessive screenshots are taken.
Expand Down Expand Up @@ -926,6 +933,10 @@ export async function selectLayout(
await page.waitForTimeout(WAIT_FOR_SWITCH_LAYOUT_MS);
}

const RESIZE_DIFF_PX = 100;
const RESIZE_STEPS = 10;
const RESIZE_PAUSE_MS = 200;

async function resizeWindow(page: Page) {
await tryUntil(
async () => {
Expand All @@ -934,18 +945,19 @@ async function resizeWindow(page: Page) {
* is fully aligned
*/
await page.setViewportSize({
width: VIEWPORT_SIZE.width - 100,
width: VIEWPORT_SIZE.width - RESIZE_DIFF_PX,
height: VIEWPORT_SIZE.height,
});

// gradually increase the viewport size over 2s with 200ms pauses
for (const [index] of Array.from({ length: 10 }).entries()) {
for (const [index] of Array.from({ length: RESIZE_STEPS }).entries()) {
await page.setViewportSize({
width: VIEWPORT_SIZE.width - 100 + (index + 1) * 10,
width:
VIEWPORT_SIZE.width - RESIZE_DIFF_PX + (index + 1) * RESIZE_STEPS,
height: VIEWPORT_SIZE.height,
});

await page.waitForTimeout(200);
await page.waitForTimeout(RESIZE_PAUSE_MS);
}

await page.setViewportSize({
Expand Down

0 comments on commit dde34a7

Please sign in to comment.