Skip to content

Commit 05ec5c7

Browse files
committed
Experimental component tests for playwright
Signed-off-by: Andrew Stein <[email protected]>
1 parent e8b6107 commit 05ec5c7

File tree

13 files changed

+1103
-98
lines changed

13 files changed

+1103
-98
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"@finos/perspective-viewer-openlayers": "workspace:^",
4949
"@finos/perspective-workspace": "workspace:^",
5050
"@fontsource/roboto-mono": "4.5.10",
51-
"@playwright/test": "^1.49.1",
51+
"@playwright/test": "^1.52.0",
52+
"@playwright/experimental-ct-react": "1.52.0",
5253
"@types/ws": "^8.18.1",
5354
"@zip.js/zip.js": "^2.7.54",
5455
"auto-changelog": "^2.5.0",
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2+
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3+
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4+
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5+
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6+
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7+
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8+
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9+
// ┃ This file is part of the Perspective library, distributed under the terms ┃
10+
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11+
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12+
13+
import perspective from "@finos/perspective";
14+
import perspective_viewer from "@finos/perspective-viewer";
15+
import "@finos/perspective-viewer-datagrid";
16+
import "@finos/perspective-viewer-d3fc";
17+
18+
// @ts-ignore
19+
import SERVER_WASM from "@finos/perspective/dist/wasm/perspective-server.wasm?url";
20+
21+
// @ts-ignore
22+
import CLIENT_WASM from "@finos/perspective-viewer/dist/wasm/perspective-viewer.wasm?url";
23+
24+
await Promise.all([
25+
perspective.init_server(fetch(SERVER_WASM)),
26+
perspective_viewer.init_client(fetch(CLIENT_WASM)),
27+
]);
28+
29+
import type * as psp from "@finos/perspective";
30+
import type * as pspViewer from "@finos/perspective-viewer";
31+
32+
// @ts-ignore
33+
import SUPERSTORE_ARROW from "superstore-arrow/superstore.lz4.arrow?url";
34+
35+
const WORKER = await perspective.worker();
36+
37+
async function createNewSuperstoreTable(): Promise<psp.Table> {
38+
const req = fetch(SUPERSTORE_ARROW);
39+
const resp = await req;
40+
const buffer = await resp.arrayBuffer();
41+
return await WORKER.table(buffer);
42+
}
43+
44+
const CONFIG: pspViewer.ViewerConfigUpdate = {
45+
group_by: ["State"],
46+
};
47+
48+
import * as React from "react";
49+
import { PerspectiveViewer } from "@finos/perspective-react";
50+
51+
import "@finos/perspective-viewer/dist/css/themes.css";
52+
import "./index.css";
53+
54+
interface ToolbarState {
55+
mounted: boolean;
56+
table?: Promise<psp.Table>;
57+
config: pspViewer.ViewerConfigUpdate;
58+
}
59+
60+
export const App: React.FC = () => {
61+
const [state, setState] = React.useState<ToolbarState>(() => ({
62+
mounted: true,
63+
table: createNewSuperstoreTable(),
64+
config: { ...CONFIG },
65+
}));
66+
67+
React.useEffect(() => {
68+
return () => {
69+
state.table?.then((table) => table?.delete({ lazy: true }));
70+
};
71+
}, []);
72+
73+
const onConfigUpdate = (config: pspViewer.ViewerConfigUpdate) => {
74+
console.log("Config Update Event", config);
75+
setState({ ...state, config });
76+
};
77+
78+
const onClick = (detail: pspViewer.PerspectiveClickEventDetail) => {
79+
console.log("Click Event,", detail);
80+
};
81+
82+
const onSelect = (detail: pspViewer.PerspectiveSelectEventDetail) => {
83+
console.log("Select Event", detail);
84+
};
85+
86+
return (
87+
<div className="container">
88+
{state.mounted && (
89+
<>
90+
<PerspectiveViewer table={state.table} />
91+
<PerspectiveViewer
92+
table={state.table}
93+
config={state.config}
94+
onClick={onClick}
95+
onSelect={onSelect}
96+
onConfigUpdate={onConfigUpdate}
97+
/>
98+
</>
99+
)}
100+
</div>
101+
);
102+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2+
* ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3+
* ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4+
* ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5+
* ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6+
* ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7+
* ┃ Copyright (c) 2017, the Perspective Authors. ┃
8+
* ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9+
* ┃ This file is part of the Perspective library, distributed under the terms ┃
10+
* ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11+
* ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12+
*/
13+
14+
body {
15+
margin: 0;
16+
background-color: #f0f0f0;
17+
font-family: "ui-monospace", "SFMono-Regular", "SF Mono", "Menlo",
18+
"Consolas", "Liberation Mono", monospace;
19+
}
20+
21+
.container {
22+
position: absolute;
23+
top: 0;
24+
left: 0;
25+
right: 0;
26+
bottom: 0;
27+
28+
display: grid;
29+
gap: 8px;
30+
grid-template-columns: 1fr 1fr;
31+
grid-template-rows: 45px 1fr;
32+
}
33+
34+
perspective-viewer {
35+
grid-row: 2;
36+
}
37+
38+
.toolbar {
39+
grid-row: 1;
40+
grid-column-start: 1;
41+
grid-column-end: 3;
42+
43+
display: flex;
44+
flex-direction: row;
45+
gap: 10px;
46+
padding: 10px;
47+
justify-content: stretch;
48+
border-bottom: 1px solid #666;
49+
}
50+
51+
button {
52+
font-family: "ui-monospace", "SFMono-Regular", "SF Mono", "Menlo",
53+
"Consolas", "Liberation Mono", monospace;
54+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2+
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
3+
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
4+
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
5+
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
6+
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7+
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
8+
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9+
// ┃ This file is part of the Perspective library, distributed under the terms ┃
10+
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11+
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12+
13+
import { test, expect } from "@playwright/experimental-ct-react";
14+
import { PerspectiveViewer } from "@finos/perspective-react";
15+
import React from "react";
16+
17+
import { App } from "./basic.story";
18+
19+
test.describe("Perspective React", () => {
20+
test("The viewer loads with data in it", async ({ page, mount }) => {
21+
const comp = await mount(<App></App>);
22+
const count = await page.evaluate(async () => {
23+
await new Promise((x) => setTimeout(x, 1000));
24+
return document.querySelectorAll("perspective-viewer").length;
25+
});
26+
27+
expect(count).toBe(2);
28+
});
29+
});

0 commit comments

Comments
 (0)