diff --git a/packages/perspective-viewer-d3fc/test/js/barWidth.spec.ts b/packages/perspective-viewer-d3fc/test/js/barWidth.spec.ts index 58c12110ca..31f768f05a 100644 --- a/packages/perspective-viewer-d3fc/test/js/barWidth.spec.ts +++ b/packages/perspective-viewer-d3fc/test/js/barWidth.spec.ts @@ -10,7 +10,7 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { test, expect } from "@finos/perspective-test"; +import { test, expect, DEFAULT_CONFIG } from "@finos/perspective-test"; import { API_VERSION, compareSVGContentsToSnapshot, @@ -41,19 +41,12 @@ test.describe("Bar Width", () => { ); expect(config).toEqual({ - version: API_VERSION, + ...DEFAULT_CONFIG, plugin: "Y Bar", columns: ["Profit"], group_by: ["Order Date"], split_by: ["Profit"], - aggregates: {}, - filter: [], - sort: [], - plugin_config: {}, - settings: false, - expressions: {}, theme: "Pro Light", - title: null, }); await compareSVGContentsToSnapshot( diff --git a/packages/perspective-viewer-datagrid/test/js/column_style.spec.js b/packages/perspective-viewer-datagrid/test/js/column_style.spec.js index 880d37d85a..d1809dd562 100644 --- a/packages/perspective-viewer-datagrid/test/js/column_style.spec.js +++ b/packages/perspective-viewer-datagrid/test/js/column_style.spec.js @@ -153,9 +153,9 @@ test.describe("Column Style Tests", () => { await viewer.restore({ plugin: "Datagrid", columns: ["Row ID", "Sales"], - plugin_config: { - columns: { - Sales: { number_bg_mode: "pulse" }, + column_config: { + Sales: { + datagrid_number_style: { number_bg_mode: "pulse" }, }, }, }); @@ -190,9 +190,9 @@ test.describe("Column Style Tests", () => { plugin: "Datagrid", columns: ["Row ID", "Sales"], settings: true, - plugin_config: { - columns: { - Sales: { number_bg_mode: "pulse" }, + column_config: { + Sales: { + datagrid_number_style: { number_bg_mode: "pulse" }, }, }, }); diff --git a/packages/perspective-workspace/test/js/migrate_workspace.spec.js b/packages/perspective-workspace/test/js/migrate_workspace.spec.js index 3a602c131f..acfe185021 100644 --- a/packages/perspective-workspace/test/js/migrate_workspace.spec.js +++ b/packages/perspective-workspace/test/js/migrate_workspace.spec.js @@ -65,6 +65,7 @@ const TESTS = [ table: "superstore", title: "One", plugin: "Y Area", + column_config: {}, plugin_config: {}, group_by: ["bucket(\"Order Date\", 'M')"], split_by: ["Ship Mode"], diff --git a/rust/perspective-viewer/src/ts/column_config.ts b/rust/perspective-viewer/src/ts/column_config.ts index 83eca56099..a97fc6f6d2 100644 --- a/rust/perspective-viewer/src/ts/column_config.ts +++ b/rust/perspective-viewer/src/ts/column_config.ts @@ -25,8 +25,8 @@ export type PerspectiveColumnConfig = { export type PerspectiveColumnConfigValue = { datagrid_number_style?: { - number_fg_mode?: "color" | "bar"; - number_bg_mode?: "color" | "gradient" | "pulse"; + number_fg_mode?: "color" | "bar" | "disabled"; + number_bg_mode?: "color" | "gradient" | "pulse" | "disabled"; fixed?: number; pos_fg_color?: string; neg_fg_color?: string; diff --git a/rust/perspective-viewer/test/js/column_settings/datagrid.spec.ts b/rust/perspective-viewer/test/js/column_settings/datagrid.spec.ts index a0230ba5e0..7c9e6bf2f3 100644 --- a/rust/perspective-viewer/test/js/column_settings/datagrid.spec.ts +++ b/rust/perspective-viewer/test/js/column_settings/datagrid.spec.ts @@ -49,10 +49,8 @@ test.describe("Regressions", function () { const token = await view.save(); test.expect(token.column_config).toEqual({ "Row ID": { - integer: { - styles: { - fixed: 4, - }, + datagrid_number_style: { + fixed: 4, }, }, }); diff --git a/rust/perspective-viewer/test/js/migrate_viewer.spec.ts b/rust/perspective-viewer/test/js/migrate_viewer.spec.ts index 28c1357ce3..542384813f 100644 --- a/rust/perspective-viewer/test/js/migrate_viewer.spec.ts +++ b/rust/perspective-viewer/test/js/migrate_viewer.spec.ts @@ -10,7 +10,7 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { test, expect } from "@finos/perspective-test"; +import { test, expect, DEFAULT_CONFIG } from "@finos/perspective-test"; import { compareContentsToSnapshot, API_VERSION, @@ -33,20 +33,12 @@ async function get_contents(page) { }); } -const DEFAULT_CONFIG: PerspectiveViewerConfig = { - aggregates: {}, - column_config: {}, - columns: [], - expressions: {}, - filter: [], - group_by: [], - plugin: "", - plugin_config: {}, - sort: [], - split_by: [], - version: API_VERSION, - title: null, -}; +const MIGRATE_BASE_CONFIG = (() => { + const config = DEFAULT_CONFIG; + delete config.theme; + delete config.settings; + return config; +})(); const TESTS: [string, any, PerspectiveViewerConfig][] = [ [ @@ -101,7 +93,10 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ plugin: "Datagrid", column_config: { Sales: { - styles: { number_bg_mode: "gradient", bg_gradient: 10 }, + datagrid_number_style: { + number_bg_mode: "gradient", + bg_gradient: 10, + }, }, }, plugin_config: { @@ -143,7 +138,7 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ plugin: "Datagrid", column_config: { Sales: { - styles: { + datagrid_number_style: { bg_gradient: 10, number_bg_mode: "gradient", }, @@ -189,11 +184,11 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ aggregates: {}, }, { - ...DEFAULT_CONFIG, + ...MIGRATE_BASE_CONFIG, plugin: "Datagrid", column_config: { Sales: { - styles: { + datagrid_number_style: { fg_gradient: 10, number_fg_mode: "bar", neg_fg_color: "#115599", @@ -212,29 +207,36 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ [ "New API, reflexive (new API is unmodified)", { - version: API_VERSION, + ...MIGRATE_BASE_CONFIG, plugin: "Datagrid", - plugin_config: { - columns: { - Discount: { + column_config: { + Discount: { + datagrid_number_style: { neg_bg_color: "#780aff", number_bg_mode: "color", number_fg_mode: "disabled", pos_bg_color: "#f5ac0f", }, - Profit: { + }, + Profit: { + datagrid_number_style: { neg_bg_color: "#f50fed", number_bg_mode: "color", number_fg_mode: "disabled", pos_bg_color: "#32cd82", }, - Sales: { + }, + Sales: { + datagrid_number_style: { neg_bg_color: "#f5ac0f", number_bg_mode: "color", number_fg_mode: "disabled", pos_bg_color: "#780aff", }, }, + }, + plugin_config: { + columns: {}, editable: false, scroll_lock: true, }, @@ -247,19 +249,13 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ "Order Date", ], sort: [["Sub-Category", "desc"]], - aggregates: {}, - filter: [], - group_by: [], - expressions: {}, - split_by: [], - title: null, }, { - ...DEFAULT_CONFIG, + ...MIGRATE_BASE_CONFIG, plugin: "Datagrid", column_config: { Discount: { - styles: { + datagrid_number_style: { neg_bg_color: "#780aff", number_bg_mode: "color", number_fg_mode: "disabled", @@ -267,7 +263,7 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ }, }, Profit: { - styles: { + datagrid_number_style: { neg_bg_color: "#f50fed", number_bg_mode: "color", number_fg_mode: "disabled", @@ -275,7 +271,7 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ }, }, Sales: { - styles: { + datagrid_number_style: { neg_bg_color: "#f5ac0f", number_bg_mode: "color", number_fg_mode: "disabled", @@ -311,24 +307,24 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ title: null, group_by: [], split_by: [], - columns: ["'hello'", "expr"], + columns: ["'hello'", "expr", null, null, "Region"], filter: [], sort: [], expressions: ["// expr\n1+1", "'hello'"], aggregates: {}, }, { - ...DEFAULT_CONFIG, + ...MIGRATE_BASE_CONFIG, version: API_VERSION, plugin: "X/Y Scatter", column_config: { Region: { - Symbols: { + symbols: { Central: "circle", }, }, }, - columns: ["'hello'", "expr"], + columns: ["'hello'", "expr", null, null, "Region"], expressions: { expr: "1+1", "'hello'": "'hello'", @@ -338,51 +334,113 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ [ "From 2.7.1 - Datagrid", { - ...DEFAULT_CONFIG, version: "2.7.1", plugin: "Datagrid", plugin_config: { columns: { + datetime: { + format: "custom", + fractionalSecondDigits: 3, + second: "2-digit", + minute: "disabled", + hour: "2-digit", + day: "2-digit", + weekday: "short", + month: "narrow", + year: "numeric", + hour12: false, + timeZone: "America/Curacao", + datetime_color_mode: "foreground", + }, + "Order ID": { + format: "link", + string_color_mode: "foreground", + color: "#ff0000", + }, "Row ID": { - column_width_override: 100, - neg_bg_color: "#000", - number_bg_mode: "color", - pos_bg_color: "#fff", + number_bg_mode: "gradient", + fixed: 1, + pos_fg_color: "#000000", + neg_fg_color: "#000000", + bg_gradient: 9, + }, + "Order Date": { + dateStyle: "disabled", + datetime_color_mode: "foreground", + color: "#00ff00", }, }, editable: true, scroll_lock: false, }, - columns: ["Row ID"], + columns: ["Row ID", "Order ID", "Order Date", "datetime"], + expressions: { datetime: "datetime(100)" }, + aggregates: {}, + filter: [], + group_by: [], + sort: [], + split_by: [], + title: null, }, { - ...DEFAULT_CONFIG, + ...MIGRATE_BASE_CONFIG, + version: "2.7.1", plugin: "Datagrid", + plugin_config: { + columns: {}, + editable: true, + scroll_lock: false, + }, column_config: { + datetime: { + datagrid_datetime_style: { + format: "custom", + fractionalSecondDigits: 3, + second: "2-digit", + minute: "disabled", + hour: "2-digit", + day: "2-digit", + weekday: "short", + month: "narrow", + year: "numeric", + hour12: false, + timeZone: "America/Curacao", + datetime_color_mode: "foreground", + }, + }, + "Order ID": { + datagrid_string_style: { + format: "link", + string_color_mode: "foreground", + color: "#ff0000", + }, + }, "Row ID": { - styles: { - neg_bg_color: "#000", - number_bg_mode: "color", - pos_bg_color: "#fff", + datagrid_number_style: { + number_bg_mode: "gradient", + fixed: 1, + pos_fg_color: "#000000", + neg_fg_color: "#000000", + bg_gradient: 9, }, }, - }, - plugin_config: { - columns: { - "Row ID": { - column_width_override: 100, + "Order Date": { + datagrid_datetime_style: { + dateStyle: "disabled", + datetime_color_mode: "foreground", + color: "#00ff00", }, }, - editable: true, - scroll_lock: false, }, - columns: ["Row ID"], + columns: ["Row ID", "Order ID", "Order Date", "datetime"], + expressions: { + datetime: "datetime(100)", + }, }, ], [ "From 2.7.1 - X/Y Scatter", { - ...DEFAULT_CONFIG, version: "2.7.1", plugin: "X/Y Scatter", plugin_config: { @@ -395,13 +453,20 @@ const TESTS: [string, any, PerspectiveViewerConfig][] = [ }, }, columns: ["Row ID", "City", null, null, "Category"], + aggregates: {}, + expressions: {}, + filter: [], + group_by: [], + sort: [], + split_by: [], + title: null, }, { - ...DEFAULT_CONFIG, + ...MIGRATE_BASE_CONFIG, plugin: "X/Y Scatter", column_config: { Category: { - Symbols: { + symbols: { Furniture: "star", }, }, @@ -439,33 +504,29 @@ test.describe("Migrate Viewer", () => { }); test.describe("migrate", async () => { - for (const [name, old, current] of TESTS) { - // NOTE: these tests were previously skipped. + for (const [name, given, expected] of TESTS) { + // TODO: PR comment: Previously this test tested that 1) the migration script did what was expected + // and that 2) the viewer restored to the expected value. This caused a lot of noise when debugging, so the test + // has been reconfigured to only test 2) since we test 1) above. test(`restore '${name}'`, async ({ page }) => { - const converted = convert(JSON.parse(JSON.stringify(old)), { - replace_defaults: true, - }) as PerspectiveViewerConfig; - const config = await page.evaluate(async (old) => { + const saved = await page.evaluate(async (converted) => { const viewer = document.querySelector("perspective-viewer")!; await viewer.getTable(); - old.settings = true; - await viewer.restore(old); - const current = await viewer.save(); - current.settings = false; - return current; - }, converted); + converted.settings = true; + await viewer.restore(converted); + const saved = await viewer.save(); + saved.settings = false; + return saved; + }, expected); - expect(config.theme).toEqual("Pro Light"); - delete config["theme"]; + expect(saved.theme).toEqual("Pro Light"); + delete saved["theme"]; - expect(config.settings).toEqual(false); - delete config.settings; + expect(saved.settings).toEqual(false); + delete saved.settings; - expect(config).toEqual(current); - expect(convert(old, { replace_defaults: true })).toEqual( - current - ); + expect(saved).toEqual(expected); const contents = await get_contents(page); await compareContentsToSnapshot(contents, [ diff --git a/rust/perspective-viewer/test/js/plugins.spec.js b/rust/perspective-viewer/test/js/plugins.spec.js index d17dd64039..46c408ff6a 100644 --- a/rust/perspective-viewer/test/js/plugins.spec.js +++ b/rust/perspective-viewer/test/js/plugins.spec.js @@ -10,7 +10,7 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { test, expect } from "@finos/perspective-test"; +import { test, expect, DEFAULT_CONFIG } from "@finos/perspective-test"; import { API_VERSION } from "@finos/perspective-test"; test.beforeEach(async ({ page }) => { @@ -35,8 +35,8 @@ test.describe("Plugin Priority Order", () => { }); const expected = { + ...DEFAULT_CONFIG, version: API_VERSION, - aggregates: {}, columns: [ "Row ID", "Order ID", @@ -58,16 +58,7 @@ test.describe("Plugin Priority Order", () => { "Discount", "Profit", ], - expressions: {}, - filter: [], - group_by: [], plugin: "HighPriority", - plugin_config: {}, - settings: false, - sort: [], - split_by: [], - theme: "Pro Light", - title: null, }; expect(saved).toEqual(expected); diff --git a/rust/perspective-viewer/test/js/regressions.spec.js b/rust/perspective-viewer/test/js/regressions.spec.js index 83b93cd348..fa8c6e3528 100644 --- a/rust/perspective-viewer/test/js/regressions.spec.js +++ b/rust/perspective-viewer/test/js/regressions.spec.js @@ -10,7 +10,7 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { test, expect } from "@finos/perspective-test"; +import { test, expect, DEFAULT_CONFIG } from "@finos/perspective-test"; import { API_VERSION, compareContentsToSnapshot, @@ -114,19 +114,12 @@ test.describe("Regression tests", () => { }); expect(config).toEqual({ - version: API_VERSION, - aggregates: {}, + ...DEFAULT_CONFIG, columns: ["Sales"], - expressions: {}, filter: [["State", "in", ["California"]]], group_by: ["State"], plugin: "Debug", - plugin_config: {}, settings: true, - sort: [], - split_by: [], - theme: "Pro Light", - title: null, }); const contents = await get_contents(page); diff --git a/rust/perspective-viewer/test/js/save_restore.spec.js b/rust/perspective-viewer/test/js/save_restore.spec.js index 61868ad41e..5ff604bcea 100644 --- a/rust/perspective-viewer/test/js/save_restore.spec.js +++ b/rust/perspective-viewer/test/js/save_restore.spec.js @@ -10,7 +10,7 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -import { test, expect } from "@finos/perspective-test"; +import { test, expect, DEFAULT_CONFIG } from "@finos/perspective-test"; import { compareContentsToSnapshot, API_VERSION, @@ -54,19 +54,11 @@ test.describe("Save/Restore", async () => { }); expect(config).toEqual({ - version: API_VERSION, - aggregates: {}, - split_by: [], + ...DEFAULT_CONFIG, columns: ["Profit", "Sales"], - expressions: {}, - filter: [], plugin: "Debug", - plugin_config: {}, group_by: ["State"], settings: true, - sort: [], - theme: "Pro Light", - title: null, }); const contents = await get_contents(page); @@ -89,19 +81,11 @@ test.describe("Save/Restore", async () => { }); expect(config).toEqual({ - version: API_VERSION, - aggregates: {}, - split_by: [], + ...DEFAULT_CONFIG, columns: ["Profit", "Sales"], - expressions: {}, - filter: [], plugin: "Debug", - plugin_config: {}, group_by: ["State"], settings: true, - sort: [], - theme: "Pro Light", - title: null, }); const config2 = await page.evaluate(async () => { @@ -111,9 +95,7 @@ test.describe("Save/Restore", async () => { }); expect(config2).toEqual({ - version: API_VERSION, - aggregates: {}, - split_by: [], + ...DEFAULT_CONFIG, columns: [ "Row ID", "Order ID", @@ -135,15 +117,9 @@ test.describe("Save/Restore", async () => { "Discount", "Profit", ], - expressions: {}, - filter: [], plugin: "Debug", - plugin_config: {}, - group_by: [], settings: true, - sort: [], theme: "Pro Light", - title: null, }); const config3 = await page.evaluate(async (config) => { @@ -153,19 +129,12 @@ test.describe("Save/Restore", async () => { }, config); expect(config3).toEqual({ - version: API_VERSION, - aggregates: {}, - split_by: [], + ...DEFAULT_CONFIG, columns: ["Profit", "Sales"], - expressions: {}, - filter: [], plugin: "Debug", - plugin_config: {}, group_by: ["State"], settings: true, - sort: [], theme: "Pro Light", - title: null, }); const contents = await get_contents(page); diff --git a/tools/perspective-test/results.tar.gz b/tools/perspective-test/results.tar.gz index e5aa057946..fae59535cd 100644 Binary files a/tools/perspective-test/results.tar.gz and b/tools/perspective-test/results.tar.gz differ diff --git a/tools/perspective-test/src/js/utils.ts b/tools/perspective-test/src/js/utils.ts index 7ff52f2abd..54b4d2e952 100644 --- a/tools/perspective-test/src/js/utils.ts +++ b/tools/perspective-test/src/js/utils.ts @@ -10,12 +10,29 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ +import { PerspectiveViewerConfig } from "@finos/perspective-viewer"; import { expect, Locator, Page } from "@playwright/test"; import * as fs from "fs"; export const API_VERSION = JSON.parse( fs.readFileSync(__dirname + "/../../package.json").toString() )["version"]; +export const DEFAULT_CONFIG: PerspectiveViewerConfig = { + aggregates: {}, + column_config: {}, + columns: [], + expressions: {}, + filter: [], + group_by: [], + plugin: "", + plugin_config: {}, + settings: false, + sort: [], + split_by: [], + version: API_VERSION, + title: null, + theme: "Pro Light", +}; /** * Clean a `` for serialization/comparison.