Skip to content

Commit

Permalink
[test] Fix flaky screenshots (#11388)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii authored Dec 12, 2023
1 parent 2d82a6f commit 11c10bb
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react';
import { DataGrid } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';
import { useDemoData, randomInt } from '@mui/x-data-grid-generator';

function loadServerRows(page, data) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(data.rows.slice(page * 5, (page + 1) * 5));
}, Math.random() * 500 + 100); // simulate network latency
}, randomInt(100, 600)); // simulate network latency
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react';
import { DataGrid, GridRowsProp, GridRowSelectionModel } from '@mui/x-data-grid';
import { GridDemoData, useDemoData } from '@mui/x-data-grid-generator';
import { GridDemoData, useDemoData, randomInt } from '@mui/x-data-grid-generator';

function loadServerRows(page: number, data: GridDemoData): Promise<any> {
return new Promise((resolve) => {
setTimeout(() => {
resolve(data.rows.slice(page * 5, (page + 1) * 5));
}, Math.random() * 500 + 100); // simulate network latency
}, randomInt(100, 600)); // simulate network latency
});
}

Expand Down
3 changes: 2 additions & 1 deletion docs/data/data-grid/row-updates/InfiniteLoadingGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useDemoData,
getRealGridData,
getCommodityColumns,
randomInt,
} from '@mui/x-data-grid-generator';
import LinearProgress from '@mui/material/LinearProgress';

Expand Down Expand Up @@ -31,7 +32,7 @@ export default function InfiniteLoadingGrid() {
setLoading(true);
const newData = await getRealGridData(newRowLength, getCommodityColumns());
// Simulate network throttle
await sleep(Math.random() * 500 + 100);
await sleep(randomInt(100, 600));

if (mounted.current) {
setLoading(false);
Expand Down
3 changes: 2 additions & 1 deletion docs/data/data-grid/row-updates/InfiniteLoadingGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useDemoData,
getRealGridData,
getCommodityColumns,
randomInt,
} from '@mui/x-data-grid-generator';
import LinearProgress from '@mui/material/LinearProgress';

Expand Down Expand Up @@ -31,7 +32,7 @@ export default function InfiniteLoadingGrid() {
setLoading(true);
const newData = await getRealGridData(newRowLength, getCommodityColumns());
// Simulate network throttle
await sleep(Math.random() * 500 + 100);
await sleep(randomInt(100, 600));

if (mounted.current) {
setLoading(false);
Expand Down
3 changes: 2 additions & 1 deletion packages/grid/x-data-grid-generator/src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getColumnsFromOptions,
getInitialState,
} from './useDemoData';
import { randomInt } from '../services/random-generator';

const simplifiedValueGetter = (field: string, colDef: GridColDef) => (row: GridRowModel) => {
const params = { id: row.id, row, field, rowNode: {} };
Expand Down Expand Up @@ -118,7 +119,7 @@ export const loadServerRows = (
if (maxDelay < minDelay) {
throw new Error('serverOptions.minDelay is larger than serverOptions.maxDelay ');
}
const delay = Math.random() * (maxDelay - minDelay) + minDelay;
const delay = randomInt(minDelay, maxDelay);

const { cursor, page = 0, pageSize } = queryOptions;

Expand Down

0 comments on commit 11c10bb

Please sign in to comment.