forked from perspective-dev/perspective
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_workspace.spec.js
More file actions
135 lines (125 loc) · 5.81 KB
/
migrate_workspace.spec.js
File metadata and controls
135 lines (125 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
const { convert } = require("@finos/perspective-viewer/dist/cjs/migrate.js");
import { test, expect } from "@playwright/test";
import {
API_VERSION,
compareLightDOMContents,
compareShadowDOMContents,
} from "@finos/perspective-test";
async function setupTestWorkspace(page) {
await page.goto("/tools/perspective-test/src/html/workspace-test.html");
await page.evaluate(async () => {
while (!window["__TEST_PERSPECTIVE_READY__"]) {
await new Promise((x) => setTimeout(x, 10));
}
});
}
const TESTS = [
[
"Bucket by year",
{
viewers: {
One: {
table: "superstore",
name: "One",
columns: ["Sales"],
plugin: "d3_y_area",
"computed-columns": ['month_bucket("Order Date")'],
"row-pivots": ["month_bucket(Order Date)"],
"column-pivots": ["Ship Mode"],
filters: [["Category", "==", "Office Supplies"]],
selectable: null,
editable: null,
aggregates: null,
sort: null,
plugin_config: {},
},
},
mode: "globalFilters",
sizes: [1],
detail: {
main: {
currentIndex: 0,
type: "tab-area",
widgets: ["One"],
},
},
},
{
viewers: {
One: {
version: API_VERSION,
table: "superstore",
title: "One",
plugin: "Y Area",
plugin_config: {},
group_by: ["bucket(\"Order Date\", 'M')"],
split_by: ["Ship Mode"],
columns: ["Sales"],
filter: [["Category", "==", "Office Supplies"]],
sort: [],
expressions: {
"bucket(\"Order Date\", 'M')":
"bucket(\"Order Date\", 'M')",
},
aggregates: {},
master: false,
linked: false,
},
},
mode: "globalFilters",
sizes: [1],
detail: {
main: {
currentIndex: 0,
type: "tab-area",
widgets: ["One"],
},
},
},
],
];
function runTests(context, compare) {
for (const [name, old, current] of TESTS) {
test(`Restore workspace - ${name}`, async ({ page }) => {
await setupTestWorkspace(page);
const converted = convert(JSON.parse(JSON.stringify(old)));
const config = await page.evaluate(async (config) => {
if (!window.__TABLE__) {
return;
}
const workspace = document.getElementById("workspace");
await workspace.restore(config);
return await workspace.save();
}, converted);
expect(config.viewers.One.theme).toEqual("Pro Light");
delete config.viewers.One["theme"];
expect(config.viewers.One.settings).toEqual(false);
delete config.viewers.One["settings"];
expect(config).toEqual(current);
expect(convert(old, { replace_defaults: true })).toEqual(current);
await compare(
page,
`${context}-${name.toLowerCase().replace(" ", "-")}.txt`
);
});
}
}
test.describe("Migrate Workspace", () => {
test.describe("Light DOM", () => {
runTests("migrate-workspace-light-dom", compareLightDOMContents);
});
test.describe("Shadow DOM", () => {
runTests("migrate-workspace-shadow-dom", compareShadowDOMContents);
});
});