From e927bd9482ca60b23cf8588f54ed5171c3360d8e Mon Sep 17 00:00:00 2001 From: ada mandala Date: Mon, 12 Feb 2024 15:18:15 -0600 Subject: [PATCH] tests, lint better column_config update repr --- .../test/js/barWidth.spec.ts | 11 +- .../test/js/column_style.spec.js | 12 +- .../test/js/migrate_workspace.spec.js | 1 + .../column_settings_sidebar/style_tab.rs | 7 +- .../style_tab/symbol.rs | 38 +-- .../style_tab/symbol/symbol_pairs.rs | 1 + .../rust/components/containers/radio_list.rs | 11 +- .../rust/components/datetime_column_style.rs | 9 +- .../rust/components/number_column_style.rs | 9 +- .../rust/components/string_column_style.rs | 9 +- .../src/rust/config/column_config.rs | 48 ++-- .../src/rust/presentation.rs | 28 +-- .../src/ts/column_config.ts | 4 +- .../test/js/column_settings/datagrid.spec.ts | 6 +- .../test/js/migrate_viewer.spec.ts | 220 +++++++++++------- .../test/js/plugins.spec.js | 13 +- .../test/js/regressions.spec.js | 11 +- .../test/js/save_restore.spec.js | 41 +--- tools/perspective-test/src/js/utils.ts | 17 ++ 19 files changed, 258 insertions(+), 238 deletions(-) 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/rust/components/column_settings_sidebar/style_tab.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab.rs index b95cdd7866..937ca63ad4 100644 --- a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab.rs +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab.rs @@ -10,9 +10,6 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -// pub mod color; -// pub mod numeric_precision; -// pub mod radio; pub mod stub; mod symbol; @@ -23,7 +20,7 @@ use crate::components::column_settings_sidebar::style_tab::symbol::SymbolStyle; use crate::components::datetime_column_style::DatetimeColumnStyle; use crate::components::number_column_style::NumberColumnStyle; use crate::components::string_column_style::StringColumnStyle; -use crate::config::{ColumnConfigValuesUpdate, Type, ViewConfigUpdate}; +use crate::config::{ColumnConfigValueUpdate, Type, ViewConfigUpdate}; use crate::custom_events::CustomEvents; use crate::model::{PluginColumnStyles, UpdateAndRender}; use crate::presentation::Presentation; @@ -45,7 +42,7 @@ pub struct StyleTabProps { derive_model!(Session, Renderer, Presentation, CustomEvents for StyleTabProps); impl StyleTabProps { - fn send_plugin_config(&self, update: ColumnConfigValuesUpdate) { + fn send_plugin_config(&self, update: ColumnConfigValueUpdate) { clone!(props = self); ApiFuture::spawn(async move { props diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol.rs index 4fcd55d658..805194ec61 100644 --- a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol.rs +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol.rs @@ -24,17 +24,17 @@ use yew::{html, Callback, Html, Properties}; use self::symbol_config::SymbolKVPair; use crate::components::column_settings_sidebar::style_tab::symbol::symbol_pairs::PairsList; use crate::components::style::LocalStyle; -use crate::config::{ColumnConfigValuesUpdate, KeyValueOpts}; +use crate::config::{ColumnConfigValueUpdate, KeyValueOpts}; +use crate::css; use crate::custom_elements::FilterDropDownElement; use crate::session::Session; -use crate::{css, html_template}; #[derive(Properties, PartialEq, Clone)] pub struct SymbolAttrProps { pub session: Session, pub column_name: String, pub restored_config: Option>, - pub on_change: Callback, + pub on_change: Callback, pub default_config: KeyValueOpts, } impl SymbolAttrProps { @@ -91,10 +91,9 @@ impl yew::Component for SymbolStyle { .filter_map(|pair| Some((pair.key?, pair.value))) .collect::>(); let update = Some(symbols).filter(|x| !x.is_empty()); - ctx.props().on_change.emit(ColumnConfigValuesUpdate { - symbols: Some(update), - ..Default::default() - }); + ctx.props() + .on_change + .emit(ColumnConfigValueUpdate::Symbols(update)); let has_last_key = new_pairs .last() @@ -114,16 +113,21 @@ impl yew::Component for SymbolStyle { fn view(&self, ctx: &yew::Context) -> Html { let update_pairs = ctx.link().callback(SymbolAttrMsg::UpdatePairs); - html_template! { - - + html! { + <> + + + } } } diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs.rs index fb687f20bc..867b8bd206 100644 --- a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs.rs +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs.rs @@ -19,6 +19,7 @@ use super::symbol_config::SymbolKVPair; use crate::components::column_settings_sidebar::style_tab::symbol::row_selector::RowSelector; use crate::components::column_settings_sidebar::style_tab::symbol::symbol_selector::SymbolSelector; use crate::components::style::LocalStyle; +use crate::css; use crate::custom_elements::FilterDropDownElement; #[derive(Properties, PartialEq)] diff --git a/rust/perspective-viewer/src/rust/components/containers/radio_list.rs b/rust/perspective-viewer/src/rust/components/containers/radio_list.rs index 12488e9161..a0ec81b88e 100644 --- a/rust/perspective-viewer/src/rust/components/containers/radio_list.rs +++ b/rust/perspective-viewer/src/rust/components/containers/radio_list.rs @@ -200,14 +200,15 @@ where class={class.to_string()} > + oninput={on_change} + disabled={ctx.props().disabled} + checked={selected.as_ref() == Some(&val)} + /> { child } } diff --git a/rust/perspective-viewer/src/rust/components/datetime_column_style.rs b/rust/perspective-viewer/src/rust/components/datetime_column_style.rs index 1092af11f0..8c6e7952bd 100644 --- a/rust/perspective-viewer/src/rust/components/datetime_column_style.rs +++ b/rust/perspective-viewer/src/rust/components/datetime_column_style.rs @@ -77,7 +77,7 @@ pub struct DatetimeColumnStyleProps { pub default_config: DatetimeColumnStyleDefaultConfig, #[prop_or_default] - pub on_change: Callback, + pub on_change: Callback, #[prop_or_default] #[derivative(Debug = "ignore")] @@ -110,10 +110,9 @@ impl DatetimeColumnStyle { fn dispatch_config(&self, ctx: &Context) { let update = Some(self.config.clone()).filter(|x| x != &DatetimeColumnStyleConfig::default()); - ctx.props().on_change.emit(ColumnConfigValuesUpdate { - datagrid_datetime_style: Some(update), - ..Default::default() - }); + ctx.props() + .on_change + .emit(ColumnConfigValueUpdate::DatagridDatetimeStyle(update)); } /// Generate a color selector component for a specific `StringColorMode` diff --git a/rust/perspective-viewer/src/rust/components/number_column_style.rs b/rust/perspective-viewer/src/rust/components/number_column_style.rs index 1b80e84dae..97a1a3f4f5 100644 --- a/rust/perspective-viewer/src/rust/components/number_column_style.rs +++ b/rust/perspective-viewer/src/rust/components/number_column_style.rs @@ -63,7 +63,7 @@ pub struct NumberColumnStyleProps { pub default_config: NumberColumnStyleDefaultConfig, #[prop_or_default] - pub on_change: Callback, + pub on_change: Callback, #[prop_or_default] pub weak_link: WeakScope, @@ -567,10 +567,9 @@ impl NumberColumnStyle { let update = Some(config).filter(|config| config != &NumberColumnStyleConfig::default()); - ctx.props().on_change.emit(ColumnConfigValuesUpdate { - datagrid_number_style: Some(update), - ..Default::default() - }); + ctx.props() + .on_change + .emit(ColumnConfigValueUpdate::DatagridNumberStyle(update)); } fn color_props(&self, side: Side, is_gradient: bool, ctx: &Context) -> ColorRangeProps { diff --git a/rust/perspective-viewer/src/rust/components/string_column_style.rs b/rust/perspective-viewer/src/rust/components/string_column_style.rs index 6baa4cbc69..eb9e44653e 100644 --- a/rust/perspective-viewer/src/rust/components/string_column_style.rs +++ b/rust/perspective-viewer/src/rust/components/string_column_style.rs @@ -39,7 +39,7 @@ pub struct StringColumnStyleProps { pub default_config: StringColumnStyleDefaultConfig, #[prop_or_default] - pub on_change: Callback, + pub on_change: Callback, #[prop_or_default] weak_link: WeakScope, @@ -69,10 +69,9 @@ impl StringColumnStyle { /// When this config has changed, we must signal the wrapper element. fn dispatch_config(&self, ctx: &Context) { let update = Some(self.config.clone()).filter(|x| x != &StringColumnStyleConfig::default()); - ctx.props().on_change.emit(ColumnConfigValuesUpdate { - datagrid_string_style: Some(update), - ..Default::default() - }); + ctx.props() + .on_change + .emit(ColumnConfigValueUpdate::DatagridStringStyle(update)); } /// Generate a color selector component for a specific `StringColorMode` diff --git a/rust/perspective-viewer/src/rust/config/column_config.rs b/rust/perspective-viewer/src/rust/config/column_config.rs index 7cdec2a899..f5173272aa 100644 --- a/rust/perspective-viewer/src/rust/config/column_config.rs +++ b/rust/perspective-viewer/src/rust/config/column_config.rs @@ -33,33 +33,31 @@ pub struct ColumnConfigValues { pub symbols: Option>, } -/// Updates the ColumnConfig. If the outer option is set, then the config value -/// will be updated. Otherwise it will be ignored. -/// This type is essentially a `Partial`, or a builder for -/// ColumnConfig. -#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Default)] -pub struct ColumnConfigValuesUpdate { - pub datagrid_number_style: Option>, - pub datagrid_string_style: Option>, - pub datagrid_datetime_style: Option>, - pub symbols: Option>>, +pub enum ColumnConfigValueUpdate { + DatagridNumberStyle(Option), + DatagridStringStyle(Option), + DatagridDatetimeStyle(Option), + Symbols(Option>), } impl ColumnConfigValues { - pub fn update(self, update: ColumnConfigValuesUpdate) -> Self { - ColumnConfigValues { - datagrid_number_style: update - .datagrid_number_style - .and_then(|x| x) - .or(self.datagrid_number_style), - datagrid_string_style: update - .datagrid_string_style - .and_then(|x| x) - .or(self.datagrid_string_style), - datagrid_datetime_style: update - .datagrid_datetime_style - .and_then(|x| x) - .or(self.datagrid_datetime_style), - symbols: update.symbols.and_then(|x| x).or(self.symbols), + pub fn update(self, update: ColumnConfigValueUpdate) -> Self { + match update { + ColumnConfigValueUpdate::DatagridNumberStyle(update) => Self { + datagrid_number_style: update, + ..self + }, + ColumnConfigValueUpdate::DatagridStringStyle(update) => Self { + datagrid_string_style: update, + ..self + }, + ColumnConfigValueUpdate::DatagridDatetimeStyle(update) => Self { + datagrid_datetime_style: update, + ..self + }, + ColumnConfigValueUpdate::Symbols(update) => Self { + symbols: update, + ..self + }, } } } diff --git a/rust/perspective-viewer/src/rust/presentation.rs b/rust/perspective-viewer/src/rust/presentation.rs index 97df499191..4a5b023e3d 100644 --- a/rust/perspective-viewer/src/rust/presentation.rs +++ b/rust/perspective-viewer/src/rust/presentation.rs @@ -23,7 +23,7 @@ use yew::html::ImplicitClone; use crate::components::column_settings_sidebar::ColumnSettingsTab; use crate::components::viewer::ColumnLocator; -use crate::config::{ColumnConfigUpdate, ColumnConfigValues, ColumnConfigValuesUpdate}; +use crate::config::{ColumnConfigUpdate, ColumnConfigValueUpdate, ColumnConfigValues}; use crate::utils::*; /// The available themes as detected in the browser environment or set @@ -259,23 +259,25 @@ impl Presentation { crate::config::OptionalUpdate::Missing => {}, crate::config::OptionalUpdate::Update(update) => { for (col_name, new_config) in update.into_iter() { - let update = ColumnConfigValuesUpdate { - datagrid_number_style: new_config.datagrid_number_style.map(Some), - datagrid_string_style: new_config.datagrid_string_style.map(Some), - datagrid_datetime_style: new_config.datagrid_datetime_style.map(Some), - symbols: new_config.symbols.map(Some), - }; - self.update_column_config_value(col_name, update) + self.column_config.borrow_mut().insert(col_name, new_config); + // let mut config = self.column_config.borrow_mut(); + // let value = config.remove() + // let update = ColumnConfigValuesUpdate{ + // datagrid_number_style: + // new_config.datagrid_number_style.map(Some), + // datagrid_string_style: + // new_config.datagrid_string_style.map(Some), + // datagrid_datetime_style: + // new_config.datagrid_datetime_style.map(Some), + // symbols: new_config.symbols.map(Some), + // }; + // self.update_column_config_value(col_name, update) } }, } } - pub fn update_column_config_value( - &self, - column_name: String, - update: ColumnConfigValuesUpdate, - ) { + pub fn update_column_config_value(&self, column_name: String, update: ColumnConfigValueUpdate) { let mut config = self.column_config.borrow_mut(); let value = config.remove(&column_name).unwrap_or_default(); config.insert(column_name, value.update(update)); 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..e68798932b 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,26 @@ 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) { 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/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.