Skip to content

Commit

Permalink
Tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Feb 10, 2020
1 parent b5da3b3 commit a3c0c1f
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 36 deletions.
36 changes: 18 additions & 18 deletions examples/workspace/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ const datasource = async () => {
return worker.table(buffer);
};

window.addEventListener("load", async () => {
const workspace = document.createElement("perspective-workspace");
document.body.append(workspace);
workspace.addTable("superstore", await datasource());
document.body.innerHTML = `
<perspective-workspace id="workspace">
<perspective-viewer slot="One" name="Test Widget One" table="superstore"></perspective-viewer>
<perspective-viewer slot="Two" name="Test Widget Two" table="superstore"></perspective-viewer>
<perspective-viewer slot="Three" name="Test Widget Three" table="superstore"></perspective-viewer>
</perspective-workspace>
`;

const config = {
window.addEventListener("load", () => {
window.workspace.tables.set("superstore", datasource());

window.workspace.restore({
master: {
widgets: [
{table: "superstore", title: "Three", "row-pivots": ["State"], columns: ["Sales", "Profit"]},
{table: "superstore", title: "Four", "row-pivots": ["Category", "Sub-Category"], columns: ["Sales", "Profit"]}
]
widgets: ["Four", "Three"]
},
detail: {
main: {
currentIndex: 0,
type: "tab-area",
widgets: [
{table: "superstore", title: "One"},
{table: "superstore", title: "Two"}
]
widgets: ["One", "Two"]
}
},
viewers: {
Three: {table: "superstore", name: "Test Widget III (modified)", "row-pivots": ["State"], columns: ["Sales", "Profit"]},
Four: {table: "superstore", name: "Test Widget IV (modified)", "row-pivots": ["Category", "Sub-Category"], columns: ["Sales", "Profit"]}
}
};

workspace.addEventListener("workspace-layout-update", console.log);
workspace.restore(config);
window.workspace = workspace;
});
});
6 changes: 3 additions & 3 deletions packages/perspective-workspace/test/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<script>

const xhr = new XMLHttpRequest();
const worker = perspective.worker();
window.__WORKER__ = perspective.worker();
xhr.open('GET', 'superstore.csv', true);
xhr.onload = function () {
window.__CSV__ = xhr.response;
const table = worker.table(xhr.response);
document.getElementById('workspace').addTable("superstore", table);
window.__TABLE__ = window.__WORKER__.table(xhr.response);
document.getElementById('workspace').tables.set("superstore", window.__TABLE__);
}
xhr.send(null);

Expand Down
123 changes: 123 additions & 0 deletions packages/perspective-workspace/test/js/integration/dom.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/******************************************************************************
*
* 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.
*
*/

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

const TEST_ROOT = path.join(__dirname, "..", "..", "..");
const PATHS = [
path.join(TEST_ROOT, "dist", "umd"),
path.join(TEST_ROOT, "dist", "themes"),
path.join(TEST_ROOT, "test", "html"),
path.join(TEST_ROOT, "test", "css"),
path.join(TEST_ROOT, "test", "csv")
];

utils.with_server({paths: PATHS}, () => {
describe.page(
"index.html",
() => {
describe("removeChild", () => {
test.capture(
"Remove One",
async page => {
await page.evaluate(() => {
const viewer = document.createElement("perspective-viewer");
viewer.setAttribute("table", "superstore");
viewer.setAttribute("name", "one");
viewer.setAttribute("slot", "one");
const viewer2 = document.createElement("perspective-viewer");
viewer2.setAttribute("table", "superstore");
viewer2.setAttribute("name", "two");
viewer2.setAttribute("slot", "two");
const workspace = document.getElementById("workspace");
workspace.appendChild(viewer);
workspace.appendChild(viewer2);
});
await page.waitForSelector("perspective-workspace perspective-viewer:not([updating])");
await page.evaluate(() => {
const viewer = document.body.querySelector('perspective-viewer[name="one"]');
const workspace = document.getElementById("workspace");
workspace.removeChild(viewer);
});
await page.waitForSelector("perspective-workspace perspective-viewer:not([updating])");
},
{wait_for_update: false, timeout: 30000}
);
});

describe("appendChild", () => {
test.capture(
"Create One",
async page => {
await page.evaluate(() => {
const viewer = document.createElement("perspective-viewer");
viewer.setAttribute("table", "superstore");
viewer.setAttribute("slot", "one");
const workspace = document.getElementById("workspace");
workspace.appendChild(viewer);
});
await page.waitForSelector("perspective-workspace perspective-viewer:not([updating])");
},
{wait_for_update: false, timeout: 30000}
);

test.capture(
"Create multiple",
async page => {
await page.evaluate(() => {
const viewer = document.createElement("perspective-viewer");
viewer.setAttribute("table", "superstore");
viewer.setAttribute("slot", "one");
const viewer2 = document.createElement("perspective-viewer");
viewer2.setAttribute("table", "superstore");
viewer2.setAttribute("slot", "two");
const workspace = document.getElementById("workspace");
workspace.appendChild(viewer);
workspace.appendChild(viewer2);
});
await page.waitForSelector("perspective-workspace perspective-viewer:not([updating])");
},
{wait_for_update: false, timeout: 30000}
);

test.capture(
"With name",
async page => {
await page.evaluate(() => {
const viewer = document.createElement("perspective-viewer");
viewer.setAttribute("table", "superstore");
viewer.setAttribute("name", "One");
viewer.setAttribute("slot", "one");
const workspace = document.getElementById("workspace");
workspace.appendChild(viewer);
});
await page.waitForSelector("perspective-workspace perspective-viewer:not([updating])");
},
{wait_for_update: false, timeout: 30000}
);

test.capture(
"Without slot",
async page => {
await page.evaluate(() => {
const viewer = document.createElement("perspective-viewer");
viewer.setAttribute("table", "superstore");
const workspace = document.getElementById("workspace");
workspace.appendChild(viewer);
});
await page.waitForSelector("perspective-workspace perspective-viewer:not([updating])");
},
{wait_for_update: false, timeout: 30000}
);
});
},
{root: TEST_ROOT}
);
});
83 changes: 83 additions & 0 deletions packages/perspective-workspace/test/js/integration/html.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/******************************************************************************
*
* 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.
*
*/

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

const TEST_ROOT = path.join(__dirname, "..", "..", "..");
const PATHS = [
path.join(TEST_ROOT, "dist", "umd"),
path.join(TEST_ROOT, "dist", "themes"),
path.join(TEST_ROOT, "test", "html"),
path.join(TEST_ROOT, "test", "css"),
path.join(TEST_ROOT, "test", "csv")
];

utils.with_server({paths: PATHS}, () => {
describe.page(
"index.html",
() => {
describe("HTML", () => {
test.capture(
"Create One",
async page => {
await page.evaluate(() => {
document.body.innerHTML = `
<perspective-workspace>
<perspective-viewer table="superstore"></perspective-viewer>
</perspective-workspace>
`;
const workspace = document.body.querySelector("perspective-workspace");
workspace.tables.set("superstore", window.__TABLE__);
});
await page.waitForSelector("perspective-workspace > perspective-viewer:not([updating])");
},
{wait_for_update: false, timeout: 30000}
);

test.capture(
"Create Multiple",
async page => {
await page.evaluate(() => {
document.body.innerHTML = `
<perspective-workspace>
<perspective-viewer table="superstore"></perspective-viewer>
<perspective-viewer table="superstore"></perspective-viewer>
</perspective-workspace>
`;
const workspace = document.body.querySelector("perspective-workspace");
workspace.tables.set("superstore", window.__TABLE__);
});
await page.waitForSelector("perspective-workspace > perspective-viewer:not([updating])");
},
{wait_for_update: false, timeout: 30000}
);

test.capture(
"Create multiple with names",
async page => {
await page.evaluate(() => {
document.body.innerHTML = `
<perspective-workspace>
<perspective-viewer name="Table 1" table="superstore"></perspective-viewer>
<perspective-viewer name="Table 2" table="superstore"></perspective-viewer>
</perspective-workspace>
`;
const workspace = document.body.querySelector("perspective-workspace");
workspace.tables.set("superstore", window.__TABLE__);
});
await page.waitForSelector("perspective-workspace > perspective-viewer:not([updating])");
},
{wait_for_update: false, timeout: 30000}
);
});
},
{root: TEST_ROOT}
);
});
18 changes: 14 additions & 4 deletions packages/perspective-workspace/test/js/integration/restore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ utils.with_server({paths: PATHS}, () => {

async page => {
const config = {
viewers: {
One: {id: "viewer", table: "superstore", name: "One"}
},
detail: {
main: {
currentIndex: 0,
type: "tab-area",
widgets: [{id: "viewer", table: "superstore", title: "One"}]
widgets: ["One"]
}
}
};
Expand All @@ -52,8 +55,11 @@ utils.with_server({paths: PATHS}, () => {

async page => {
const config = {
viewers: {
One: {table: "superstore", name: "Test", "row-pivots": ["State"], columns: ["Sales", "Profit"]}
},
master: {
widgets: [{table: "superstore", title: "Test", "row-pivots": ["State"], columns: ["Sales", "Profit"]}]
widgets: ["One"]
}
};

Expand All @@ -72,14 +78,18 @@ utils.with_server({paths: PATHS}, () => {

async page => {
const config = {
viewers: {
One: {table: "superstore", name: "Test", "row-pivots": ["State"], columns: ["Sales", "Profit"]},
Two: {id: "viewer", table: "superstore", name: "One"}
},
master: {
widgets: [{table: "superstore", title: "Test", "row-pivots": ["State"], columns: ["Sales", "Profit"]}]
widgets: ["One"]
},
detail: {
main: {
currentIndex: 0,
type: "tab-area",
widgets: [{id: "viewer", table: "superstore", title: "One"}]
widgets: ["Two"]
}
}
};
Expand Down
24 changes: 14 additions & 10 deletions packages/perspective-workspace/test/js/unit/workspace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {toArray} from "@phosphor/algorithm";

describe("workspace", () => {
test("restores detail to dockpanel", () => {
const widget = {table: "superstore", title: "One"};
const viewers = {One: {table: "superstore", name: "One"}};
const config = {
viewers,
detail: {
main: {
currentIndex: 0,
type: "tab-area",
widgets: [widget]
widgets: ["One"]
}
}
};
Expand All @@ -28,16 +29,17 @@ describe("workspace", () => {

const widgets = toArray(workspace.dockpanel.widgets());

const expected = {table: "superstore", title: "One", master: false};
const expected = {table: "superstore", name: "One", master: false};
expect(widgets.length).toBe(1);
expect(widgets[0].save()).toStrictEqual(expected);
});

test("restores master to masterpanel", () => {
const widget = {table: "superstore", title: "One"};
const viewers = {One: {table: "superstore", name: "One"}};
const config = {
viewers,
master: {
widgets: [widget]
widgets: ["One"]
}
};

Expand All @@ -46,21 +48,23 @@ describe("workspace", () => {

const widgets = workspace.masterPanel.widgets;

const expected = {table: "superstore", title: "One", master: true};
const expected = {table: "superstore", name: "One", master: true};
expect(widgets.length).toBe(1);
expect(widgets[0].save()).toStrictEqual(expected);
});

test("restores master to masterpanel and detail to dockpanel", () => {
const viewers = {One: {table: "superstore", name: "One"}, Two: {table: "superstore", name: "Two"}};
const config = {
viewers,
master: {
widgets: [{table: "superstore", title: "One"}]
widgets: ["One"]
},
detail: {
main: {
currentIndex: 0,
type: "tab-area",
widgets: [{table: "superstore", title: "Two"}]
widgets: ["Two"]
}
}
};
Expand All @@ -71,8 +75,8 @@ describe("workspace", () => {
const masterWidgets = workspace.masterPanel.widgets;
const detailWidgets = toArray(workspace.dockpanel.widgets());

const master = {table: "superstore", title: "One", master: true};
const detail = {table: "superstore", title: "Two", master: false};
const master = {table: "superstore", name: "One", master: true};
const detail = {table: "superstore", name: "Two", master: false};

expect(masterWidgets.length).toBe(1);
expect(masterWidgets[0].save()).toStrictEqual(master);
Expand Down
Loading

0 comments on commit a3c0c1f

Please sign in to comment.