Skip to content

Commit

Permalink
Fix flaky tests (#2812)
Browse files Browse the repository at this point in the history
  • Loading branch information
apedroferreira authored Oct 20, 2023
1 parent a9ec6f6 commit 1a3960e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/toolpad-components/src/Chart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { Container, ContainerProps, Skeleton } from '@mui/material';
import { Box, BoxProps, Skeleton } from '@mui/material';

import {
XAxis,
Expand Down Expand Up @@ -37,7 +37,7 @@ function getBarChartDataSeriesNormalizedYKey(dataSeries: ChartDataSeries, index:
return `${dataSeries.label}-${dataSeries.yKey}-${index}`;
}

interface ChartProps extends ContainerProps {
interface ChartProps extends BoxProps {
data?: ChartData;
loading?: boolean;
error?: Error | string;
Expand Down Expand Up @@ -94,7 +94,7 @@ function Chart({ data = [], loading, error, height, sx }: ChartProps) {
const isDataVisible = !loading && !displayError;

return (
<Container disableGutters sx={{ ...sx, position: 'relative' }} aria-busy={loading}>
<Box sx={{ ...sx, position: 'relative', width: '100%' }} aria-busy={loading}>
<ResponsiveContainer width="100%" height={height}>
<ComposedChart data={barChartData} margin={{ top: 20, right: 80 }}>
{isDataVisible ? (
Expand Down Expand Up @@ -196,7 +196,7 @@ function Chart({ data = [], loading, error, height, sx }: ChartProps) {
height={height}
/>
) : null}
</Container>
</Box>
);
}

Expand Down
9 changes: 4 additions & 5 deletions packages/toolpad-components/src/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Container, ContainerProps, Box, Stack, BoxProps } from '@mui/material';
import { Box, BoxProps, Stack } from '@mui/material';
import { LoadingButton } from '@mui/lab';
import { useNode } from '@mui/toolpad-core';
import { equalProperties } from '@mui/toolpad-utils/collections';
Expand All @@ -15,7 +15,7 @@ export const FormContext = React.createContext<{
fieldValues: {},
});

interface FormProps extends ContainerProps {
interface FormProps extends BoxProps {
value: FieldValues;
onChange: (newValue: FieldValues) => void;
onSubmit?: (data?: FieldValues) => unknown | Promise<unknown>;
Expand All @@ -39,7 +39,6 @@ function Form({
mode = 'onSubmit',
hasChrome = true,
sx,
...rest
}: FormProps) {
const form = useForm({ mode });
const { isSubmitSuccessful } = form.formState;
Expand Down Expand Up @@ -79,7 +78,7 @@ function Form({
return (
<FormContext.Provider value={formContextValue}>
{hasChrome ? (
<Container disableGutters sx={sx} {...rest}>
<Box sx={{ ...sx, width: '100%' }}>
<form onSubmit={form.handleSubmit(handleSubmit)} onReset={handleReset}>
{children}

Expand Down Expand Up @@ -118,7 +117,7 @@ function Form({
</Stack>
</Box>
</form>
</Container>
</Box>
) : (
children
)}
Expand Down
3 changes: 3 additions & 0 deletions test/integration/data-grid/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ test('Column prop updates are not lost on drag interactions', async ({ page }) =

const firstGridLocator = canvasGridLocator.first();

// Wait for data to load so that datagrid bounding box is stable
await expect(editorModel.pageRoot.getByText('Todd Breitenberg')).toBeVisible();

await clickCenter(page, firstGridLocator);

await editorModel.componentEditor.locator('button:has-text("columns")').click();
Expand Down
9 changes: 7 additions & 2 deletions test/models/ToolpadEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ export class ToolpadEditor {

await this.componentCatalog.hover();

const pageRootBoundingBox = await this.pageRoot.boundingBox();
let pageRootBoundingBox;
await expect(async () => {
pageRootBoundingBox = await this.pageRoot.boundingBox();
expect(pageRootBoundingBox).toBeTruthy();
}).toPass();

if (!moveTargetX) {
moveTargetX = pageRootBoundingBox!.x + pageRootBoundingBox!.width / 2;
}
Expand All @@ -148,7 +153,7 @@ export class ToolpadEditor {
const sourceLocator = this.getComponentCatalogItem(componentName);
await expect(sourceLocator).toBeVisible();

await this.dragTo(sourceLocator, moveTargetX, moveTargetY, hasDrop);
await this.dragTo(sourceLocator, moveTargetX!, moveTargetY!, hasDrop);

await style.evaluate((elm) => elm.parentNode?.removeChild(elm));
}
Expand Down
11 changes: 7 additions & 4 deletions test/utils/clickCenter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Page, Locator, expect } from '@playwright/test';

export default async function clickCenter(page: Page, targetLocator: Locator) {
await expect(targetLocator).toBeAttached();

const targetBoundingBox = await targetLocator.boundingBox();
expect(targetBoundingBox).toBeTruthy();
let targetBoundingBox;
await expect(async () => {
targetBoundingBox = await targetLocator.boundingBox();
expect(targetBoundingBox).toBeTruthy();
expect(targetBoundingBox!.width).toBeGreaterThan(0);
expect(targetBoundingBox!.height).toBeGreaterThan(0);
}).toPass();

await page.mouse.click(
targetBoundingBox!.x + targetBoundingBox!.width / 2,
Expand Down

0 comments on commit 1a3960e

Please sign in to comment.