Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New plugin @finos/perspective-viewer-datagrid #954

Merged
merged 4 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests to @finos/perspective-viewer-datagrid
  • Loading branch information
texodus committed Feb 28, 2020
commit 609e69696c3a39824e62a5aa42859df559bac8e1
1 change: 1 addition & 0 deletions packages/perspective-test/jest.all.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
"packages/perspective-viewer/test/js",
"packages/perspective-viewer-hypergrid/test/js",
"packages/perspective-viewer-highcharts/test/js",
"packages/perspective-viewer-datagrid/test/js",
"packages/perspective-viewer-d3fc/test/js",
"packages/perspective-workspace/test/js",
"packages/perspective-jupyterlab/test/js"
Expand Down
34 changes: 34 additions & 0 deletions packages/perspective-viewer-datagrid/test/html/empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--

Copyright (c) 2017, the Perspective Authors.

This file is part of the Perspective library, distributed under the terms of
the Apache License 2.0. The full license can be found in the LICENSE file.

-->

<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<script src="perspective-viewer.js"></script>
<script src="perspective-viewer-datagrid.js"></script>

<link rel='stylesheet' href="demo.css">

</head>
<body>

<perspective-viewer>

</perspective-viewer>

<script>

var viewer = document.getElementsByTagName('perspective-viewer')[0];
viewer.load({x: "integer"});

</script>

</body>
</html>
41 changes: 41 additions & 0 deletions packages/perspective-viewer-datagrid/test/html/regressions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--

Copyright (c) 2017, the Perspective Authors.

This file is part of the Perspective library, distributed under the terms of
the Apache License 2.0. The full license can be found in the LICENSE file.

-->

<!DOCTYPE html>
<html>
<head>

<script src="perspective-viewer.js"></script>
<script src="perspective-viewer-datagrid.js"></script>

<link rel='stylesheet' href="demo.css">

</head>
<body>

<perspective-viewer>

</perspective-viewer>

<script>

var viewer = document.getElementsByTagName('perspective-viewer')[0];
viewer.load([
{x: 1, y: "a", z: true},
{x: 2, y: "b", z: false},
{x: 3, y: "c", z: true},
{x: 4, y: "a", z: false},
{x: 5, y: "b", z: true},
{x: 6, y: "c", z: false}
], {index: 'x'});

</script>

</body>
</html>
38 changes: 38 additions & 0 deletions packages/perspective-viewer-datagrid/test/html/superstore.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--

Copyright (c) 2017, the Perspective Authors.

This file is part of the Perspective library, distributed under the terms of
the Apache License 2.0. The full license can be found in the LICENSE file.

-->

<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<script src="perspective-viewer.js"></script>
<script src="perspective-viewer-datagrid.js"></script>

<link rel='stylesheet' href="demo.css">

</head>
<body>

<perspective-viewer>

</perspective-viewer>

<script>

var xhr = new XMLHttpRequest();
xhr.open('GET', 'superstore.csv', true);
xhr.onload = function () {
document.getElementsByTagName('perspective-viewer')[0].load(xhr.response);
}
xhr.send(null);

</script>

</body>
</html>
70 changes: 70 additions & 0 deletions packages/perspective-viewer-datagrid/test/js/regressions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

const utils = require("@finos/perspective-test");
const path = require("path");
const {capture_update} = require("./utils.js");

utils.with_server({}, () => {
describe.page(
"empty.html",
() => {
test.capture("empty grids do not explode", async page => {
const viewer = await page.$("perspective-viewer");
await page.shadow_click("perspective-viewer", "#config_button");
await page.waitFor("perspective-viewer:not([updating])");
await capture_update(page, viewer, () => page.evaluate(element => element.update([{x: 3}]), viewer));
await page.waitFor("perspective-viewer:not([updating])");
});
},
{root: path.join(__dirname, "..", "..")}
);

describe.page(
"regressions.html",
() => {
describe("Updates", () => {
test.capture("should not render an extra row for column_only views", async page => {
const viewer = await page.$("perspective-viewer");
await page.shadow_click("perspective-viewer", "#config_button");
await page.evaluate(element => element.setAttribute("column-pivots", '["y"]'), viewer);
});

test.capture("regular updates", async page => {
const viewer = await page.$("perspective-viewer");
await page.shadow_click("perspective-viewer", "#config_button");
await capture_update(page, viewer, () => page.evaluate(element => element.update([{x: 3, y: "Updated!"}]), viewer));
await page.waitFor("perspective-viewer:not([updating])");
});

test.capture("saving a computed column does not interrupt update rendering", async page => {
const viewer = await page.$("perspective-viewer");
await page.shadow_click("perspective-viewer", "#config_button");
await page.evaluate(element => element.shadowRoot.querySelector("#add-computed-column").click(), viewer);
await page.evaluate(element => {
let com = element.shadowRoot.querySelector("perspective-computed-column");
const columns = [{name: "y", type: "string"}];
com._apply_state(columns, com.computations["length"], "new_cc");
}, viewer);
await page.evaluate(
element =>
element.shadowRoot
.querySelector("perspective-computed-column")
.shadowRoot.querySelector("#psp-cc-button-save")
.click(),
viewer
);
await page.waitForSelector("perspective-viewer:not([updating])");
await capture_update(page, viewer, () => page.evaluate(element => element.update([{x: 3, y: "Updated!"}]), viewer));
});
});
},
{root: path.join(__dirname, "..", "..")}
);
});
23 changes: 23 additions & 0 deletions packages/perspective-viewer-datagrid/test/js/slow.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

const utils = require("@finos/perspective-test");
const path = require("path");

const mutation_tests = require("@finos/perspective-viewer/test/js/mutation_tests.js");

utils.with_server({}, () => {
describe.page(
"superstore.html",
() => {
mutation_tests.default();
},
{root: path.join(__dirname, "..", "..")}
);
});
40 changes: 40 additions & 0 deletions packages/perspective-viewer-datagrid/test/js/superstore.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

const utils = require("@finos/perspective-test");
const path = require("path");

const simple_tests = require("@finos/perspective-viewer/test/js/simple_tests.js");

utils.with_server({}, () => {
describe.page(
"superstore.html",
() => {
simple_tests.default();

test.capture("resets viewable area when the logical size expands.", async page => {
const viewer = await page.$("perspective-viewer");
await page.shadow_click("perspective-viewer", "#config_button");
await page.evaluate(element => element.setAttribute("column-pivots", '["Category"]'), viewer);
await page.waitForSelector("perspective-viewer:not([updating])");
await page.evaluate(element => element.setAttribute("row-pivots", '["City"]'), viewer);
});

test.capture("resets viewable area when the physical size expands.", async page => {
const viewer = await page.$("perspective-viewer");
await page.shadow_click("perspective-viewer", "#config_button");
await page.evaluate(element => element.setAttribute("row-pivots", '["Category"]'), viewer);
await page.waitForSelector("perspective-viewer:not([updating])");
await page.evaluate(element => element.setAttribute("row-pivots", "[]"), viewer);
await page.shadow_click("perspective-viewer", "#config_button");
});
},
{reload_page: false, root: path.join(__dirname, "..", "..")}
);
});
74 changes: 74 additions & 0 deletions packages/perspective-viewer-datagrid/test/js/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/******************************************************************************
*
* Copyright (c) 2019, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/

exports.scroll = async (page, x = 0, y = 100) => {
await page.evaluate(
({x, y}) => {
const grid = document
.querySelector("perspective-viewer")
.shadowRoot.querySelector("perspective-hypergrid")
.shadowRoot.querySelector("canvas");
const wheel_event = new WheelEvent("wheel", {
bubbles: true,
cancelable: true,
deltaX: x,
deltaY: y
});
grid.dispatchEvent(wheel_event);
},
{x, y}
);
};

exports.dblclick = async (page, x = 310, y = 300) => {
await page.evaluate(
({x, y}) => {
const example = document
.querySelector("perspective-viewer")
.shadowRoot.querySelector("perspective-hypergrid")
.shadowRoot.querySelector("canvas");

const event = document.createEvent("MouseEvents");
event.initMouseEvent("dblclick", true, false, window, 0, x, y, x, y, false, false, false, false, 2, null);
example.dispatchEvent(event);
},
{x, y}
);
};

exports.click_details = async (page, x = 310, y = 300) => {
const viewer = await page.$("perspective-viewer");

const click_event = page.evaluate(
element =>
new Promise(resolve => {
element.addEventListener("perspective-click", e => {
resolve(e.detail);
});
}),
viewer
);
await page.mouse.click(x, y);
return await click_event;
};

exports.capture_update = async function capture_update(page, viewer, body) {
await page.evaluate(element => {
element.addEventListener("perspective-view-update", () => {
element.setAttribute("test-updated", true);
});
}, viewer);
await body();
try {
await page.waitFor(element => element.hasAttribute("test-updated"), {timeout: 3000}, viewer);
} catch (e) {
console.error("Missing 'test-updated' attribute");
}
await page.evaluate(element => element.removeAttribute("test-updated"), viewer);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"superstore_replaces_all_rows_": "033d42712f7abbc7295796ed342bc53d",
"__GIT_COMMIT__": "c4d724144c6d3cc61135f73e3342d6e2a9600d8c",
"empty_empty_grids_do_not_explode": "e44b5361e9999f09e9a96ea3dcf84c09",
"regressions_Updates_should_not_render_an_extra_row_for_column_only_views": "bf64ff24b6cf15946b37132dba55465e",
"regressions_Updates_regular_updates": "64a36c77967c1735f623cffee1adf155",
"regressions_Updates_saving_a_computed_column_does_not_interrupt_update_rendering": "c841a669ce0cbd7c4009f2a332494506",
"superstore_shows_a_grid_without_any_settings_applied_": "81f073a4c86c13f9ef4d0c28c76715c1",
"superstore_pivots_by_a_row_": "f8d371ca9cc15be29c946469a628446d",
"superstore_pivots_by_two_rows_": "d9c7b7c2ff0cd8e7c33a1cc2b7eaef8b",
"superstore_pivots_by_a_column_": "f7c151a2e22774d6cbb42c305e86ec44",
"superstore_pivots_by_a_row_and_a_column_": "5de990fbaa5ec9feddaa12f9a9652946",
"superstore_pivots_by_two_rows_and_two_columns_": "044c6bb8ea68d7afda49c29ae83b36f4",
"superstore_sorts_by_a_hidden_column_": "07fe179b433fc341931250faec24b100",
"superstore_sorts_by_a_numeric_column_": "23faec2f954d47bc9c46ee1920b88699",
"superstore_filters_by_a_numeric_column_": "6d59b57ef9592405081441a486221f59",
"superstore_filters_by_a_datetime_column_": "a82aeac9bc143af1fc8491d1f5ab1287",
"superstore_highlights_invalid_filter_": "e719fc631f7acd0cb60c750dd5661d68",
"superstore_sorts_by_an_alpha_column_": "4495bdc79b2731c92dbe491aad789692",
"superstore_displays_visible_columns_": "ed3688a5a5015be9b5e792923f289c08",
"superstore_resets_viewable_area_when_the_logical_size_expands_": "7de1e7887f2f292bee3fe711d6520b65",
"superstore_resets_viewable_area_when_the_physical_size_expands_": "81f073a4c86c13f9ef4d0c28c76715c1"
}