Skip to content

Commit c944cbe

Browse files
committed
add test case
1 parent 48d9645 commit c944cbe

File tree

6 files changed

+130
-4
lines changed

6 files changed

+130
-4
lines changed

Diff for: packages/core/src/internal/data-grid-overlay-editor/data-grid-overlay-editor-style.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export const DataGridOverlayEditorStyle = styled.div<Props>`
4747
0px 6px 12px rgba(62, 65, 86, 0.15);
4848
4949
animation: glide_fade_in 60ms 1;
50+
51+
&:focus {
52+
outline: none;
53+
}
5054
}
5155
5256
&.gdg-pad {

Diff for: packages/core/src/internal/data-grid-overlay-editor/data-grid-overlay-editor.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ const DataGridOverlayEditor: React.FunctionComponent<DataGridOverlayEditorProps>
225225
if (elem) elem.focus();
226226
}}
227227
id={id}
228+
data-testid="data-grid-overlay-editor"
228229
className={classWrap}
229230
style={styleOverride}
230231
as={useLabel === true ? "label" : undefined}

Diff for: packages/core/src/internal/data-grid-overlay-editor/private/markdown-overlay-editor.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ export const MarkdownOverlayEditor: React.FunctionComponent<Props> = p => {
6262
</MarkdownOverlayEditorStyle>
6363
);
6464
};
65+
66+
export default MarkdownOverlayEditor;

Diff for: packages/core/test/data-editor.test.tsx

+121-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
isSizedGridColumn,
1010
type Item,
1111
} from "../src/index.js";
12-
import type { CustomCell } from "../src/internal/data-grid/data-grid-types.js";
12+
import type { CustomCell, SizedGridColumn } from "../src/internal/data-grid/data-grid-types.js";
1313
import type { DataEditorRef } from "../src/data-editor/data-editor.js";
1414
import { assert } from "../src/common/support.js";
1515
import { vi, type Mock, expect, describe, test, beforeEach, afterEach } from "vitest";
@@ -1352,7 +1352,7 @@ describe("data-editor", () => {
13521352
expect(document.body.contains(overlay)).toBe(false);
13531353
});
13541354

1355-
test("Open markdown overlay", async () => {
1355+
test("Open and close markdown overlay", async () => {
13561356
vi.useFakeTimers();
13571357
render(<DataEditor {...basicProps} />, {
13581358
wrapper: Context,
@@ -1384,6 +1384,125 @@ describe("data-editor", () => {
13841384
expect(document.body.contains(overlay)).toBe(false);
13851385
});
13861386

1387+
test("Open and close overlays", async () => {
1388+
vi.useFakeTimers();
1389+
1390+
const columns = basicProps.columns.slice(0, 5);
1391+
const getCellContent: (typeof basicProps)["getCellContent"] = c => {
1392+
const [col, row] = c;
1393+
switch (col) {
1394+
case 0: {
1395+
return {
1396+
kind: GridCellKind.Bubble,
1397+
allowOverlay: true,
1398+
data: ["Foobar"],
1399+
readOnly: true,
1400+
};
1401+
}
1402+
case 1: {
1403+
return {
1404+
kind: GridCellKind.Drilldown,
1405+
allowOverlay: true,
1406+
data: [
1407+
{
1408+
img: "https://cdn.pixabay.com/photo/2017/02/20/18/03/cat-2083492_1280.jpg",
1409+
text: "Foobar",
1410+
},
1411+
],
1412+
readOnly: true,
1413+
};
1414+
}
1415+
case 2: {
1416+
return {
1417+
kind: GridCellKind.Image,
1418+
data: [
1419+
"https://i.imgur.com/5J0BftG.jpg",
1420+
"https://preview.redd.it/7jlqkp2cyap51.jpg?width=575&auto=webp&s=26fa9ed15b16fb450ee08ed1f2f0ccb5e0223581",
1421+
],
1422+
allowOverlay: true,
1423+
readOnly: true,
1424+
};
1425+
}
1426+
case 3: {
1427+
return {
1428+
kind: GridCellKind.Markdown,
1429+
allowOverlay: true,
1430+
data: `# Header: ${col}, ${row}`,
1431+
readOnly: true,
1432+
};
1433+
}
1434+
case 4: {
1435+
return {
1436+
kind: GridCellKind.Number,
1437+
allowOverlay: true,
1438+
data: row,
1439+
displayData: row.toString(),
1440+
readOnly: true,
1441+
};
1442+
}
1443+
case 5: {
1444+
return {
1445+
kind: GridCellKind.Uri,
1446+
allowOverlay: true,
1447+
data: "https://www.google.com",
1448+
readOnly: true,
1449+
};
1450+
}
1451+
}
1452+
1453+
return basicProps.getCellContent(c);
1454+
};
1455+
1456+
render(
1457+
<DataEditor
1458+
{...basicProps}
1459+
columns={columns}
1460+
getCellContent={getCellContent}
1461+
/>,
1462+
{
1463+
wrapper: Context,
1464+
}
1465+
);
1466+
prep();
1467+
1468+
const canvas = screen.getByTestId("data-grid-canvas");
1469+
1470+
let clientX = 10;
1471+
for (const col of columns) {
1472+
// Double click to open overlay
1473+
sendClick(canvas, {
1474+
clientX,
1475+
clientY: 36 + 32 + 16, // Row 1 (0 indexed)
1476+
});
1477+
1478+
sendClick(canvas, {
1479+
clientX,
1480+
clientY: 36 + 32 + 16, // Row 1 (0 indexed)
1481+
});
1482+
1483+
// Single click on overlay editor
1484+
sendClick(canvas, {
1485+
clientX,
1486+
clientY: 36 + 32 + 16, // Row 1 (0 indexed)
1487+
});
1488+
1489+
const overlay = screen.getByTestId("data-grid-overlay-editor")
1490+
expect(document.body.contains(overlay)).toBe(true);
1491+
1492+
vi.useFakeTimers();
1493+
fireEvent.keyDown(canvas, {
1494+
key: "Escape",
1495+
});
1496+
act(() => {
1497+
vi.runAllTimers();
1498+
});
1499+
1500+
expect(document.body.contains(overlay)).toBe(false);
1501+
1502+
clientX += (col as SizedGridColumn).width;
1503+
}
1504+
})
1505+
13871506
test("Open overlay with keypress", async () => {
13881507
vi.useFakeTimers();
13891508
render(<DataEditor {...basicProps} />, {

Diff for: packages/core/test/data-grid-overlay.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render, cleanup } from "@testing-library/react";
33
import BubblesOverlayEditor from "../src/internal/data-grid-overlay-editor/private/bubbles-overlay-editor.js";
44
import DrilldownOverlayEditor from "../src/internal/data-grid-overlay-editor/private/drilldown-overlay-editor.js";
55
import { GridCellKind, ImageOverlayEditor } from "../src/index.js";
6-
import { MarkdownOverlayEditor } from "../src/internal/data-grid-overlay-editor/private/markdown-overlay-editor.js";
6+
import MarkdownOverlayEditor from "../src/internal/data-grid-overlay-editor/private/markdown-overlay-editor.js";
77
import NumberOverlayEditor from "../src/internal/data-grid-overlay-editor/private/number-overlay-editor.js";
88
import UriOverlayEditor from "../src/internal/data-grid-overlay-editor/private/uri-overlay-editor.js";
99
import { vi, describe, test, afterEach } from "vitest";

Diff for: setup-react-18-test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
npm i -D react@latest react-dom@latest @testing-library/react@latest @testing-library/react-hooks@latest @testing-library/[email protected] react-test-renderer@latest
3+
npm i -D react@latest react-dom@latest @testing-library/react@latest @testing-library/react-hooks@latest @testing-library/[email protected] react-test-renderer@latest @testing-library/dom

0 commit comments

Comments
 (0)