Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ada-x64 committed Feb 23, 2024
1 parent 990a7f1 commit 1992abb
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 13 deletions.
1 change: 0 additions & 1 deletion rust/perspective-viewer/src/less/column-style.less
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@
border-radius: 0 6px 6px 0;
margin: 0 0 0 1px;
}

}

::-webkit-color-swatch-wrapper {
Expand Down
12 changes: 12 additions & 0 deletions rust/perspective-viewer/src/less/dom/scrollbar.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ 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). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

@mixin scrollbar {
&::-webkit-scrollbar-thumb {
border: 0 solid var(--icon--color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,23 @@ pub struct CustomNumberFormat {
impl CustomNumberFormat {
fn initialize(ctx: &yew::prelude::Context<Self>) -> Self {
let config = ctx.props().restored_config.clone();
let show_frac = config
.minimum_fraction_digits
.or(config.maximum_fraction_digits)
.or(config.rounding_increment)
.is_some();
let show_sig = config
.minimum_significant_digits
.or(config.maximum_significant_digits)
.is_some();
let disable_rounding_increment = show_sig
|| show_frac
|| !matches!(
config.rounding_priority,
Some(RoundingPriority::Auto) | None
);
let disable_rounding_priority = !(show_frac && show_sig);
Self {
show_frac: config
.minimum_fraction_digits
.or(config.maximum_fraction_digits)
.or(config.rounding_increment)
.is_some(),
show_sig: config
.minimum_significant_digits
.or(config.maximum_significant_digits)
.is_some(),
style: config
._style
.as_ref()
Expand All @@ -89,7 +96,11 @@ impl CustomNumberFormat {
})
.unwrap_or_default(),
config,
..Default::default()
show_frac,
show_sig,
disable_rounding_increment,
disable_rounding_priority,
notation: None,
}
}
}
Expand Down Expand Up @@ -245,7 +256,7 @@ impl Component for CustomNumberFormat {
self.config.rounding_priority,
Some(RoundingPriority::Auto) | None
);
self.disable_rounding_priority = self.show_sig || self.show_frac;
self.disable_rounding_priority = !(self.show_frac && self.show_sig);

let filtered_config = self.config.clone().filter_default(
self.show_sig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl CustomNumberFormat {
{ self.rounding_increment(ctx) }
<SelectField<RoundingPriority>
label="Rounding Priority"
disabled={!(self.show_frac && self.show_sig)}
disabled={self.disable_rounding_priority}
current_value={self.config.rounding_priority}
on_change={ctx.link().callback(CustomNumberFormatMsg::RoundingPriority)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ 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). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

import { Type } from "@finos/perspective";
import {
DEFAULT_CONFIG,
PageView,
compareContentsToSnapshot,
} from "@finos/perspective-test";
import { ColumnSelector } from "@finos/perspective-test/src/js/models/settings_panel";
import { test, expect } from "@finos/perspective-test";
import { DataGridPlugin } from "@finos/perspective-test/src/js/models/plugins";
import { DataGrid } from "@finos/perspective-test/src/js/models/plugins/datagrid";

test.beforeEach(async ({ page }) => {
await page.goto("/tools/perspective-test/src/html/basic-test.html");
await page.evaluate(async () => {
while (!window["__TEST_PERSPECTIVE_READY__"]) {
await new Promise((x) => setTimeout(x, 10));
}
});
});

test("Integer/float styles", async ({ page }) => {
const view = new PageView(page);
await view.restore({
settings: true,
plugin: "Datagrid",
columns: ["Profit", "Row ID"],
});
const profit = await view.settingsPanel.activeColumns.getColumnByName(
"Profit"
);
await profit.editBtn.click();
const styleContainer = view.columnSettingsSidebar.styleTab.container;
await styleContainer.getByText("Fractional Digits").waitFor();
const rowId = await view.settingsPanel.activeColumns.getColumnByName(
"Row ID"
);
await rowId.editBtn.click();
await styleContainer
.getByText("Fractional Digits")
.waitFor({ state: "detached" });
});
for (const name of ["Significant Digits", "Fractional Digits"]) {
test(`Rounding Increment doesn't send when ${name} is open`, async ({
page,
}) => {
let view = new PageView(page);
await view.restore({
settings: true,
plugin: "Datagrid",
columns: ["Profit"],
});
const profit = await view.settingsPanel.activeColumns.getColumnByName(
"Profit"
);
await profit.editBtn.click();
const styleContainer = view.columnSettingsSidebar.styleTab.container;
await styleContainer
.locator("#Rounding-Increment-checkbox ~ div > select")
.selectOption("20");
await styleContainer.getByText(name).click();
await expect(
styleContainer.locator("#Rounding-Increment-checkbox")
).toBeDisabled();
let config = await view.save();
expect(config).toMatchObject({
column_config: {},
});
await styleContainer.getByText(name).click();
config = await view.save();
expect(config).toMatchObject({
column_config: {
Profit: {
number_string_format: {
maximumFractionDigits: 0,
roundingIncrement: 20,
},
},
},
});
});
}
test("Rounding Priority doesn't send unless Fractional and Significant Digits are open", async ({
page,
}) => {
const view = new PageView(page);
await view.restore({
settings: true,
plugin: "Datagrid",
columns: ["Profit"],
});
const col = await view.settingsPanel.activeColumns.getColumnByName(
"Profit"
);
await col.editBtn.click();
const styleContainer = view.columnSettingsSidebar.styleTab.container;
await expect(
styleContainer.locator("#Rounding-Priority-checkbox")
).toBeDisabled();
await styleContainer.getByText("Fractional Digits").click();
await styleContainer.getByText("Significant Digits").click();
await expect(
styleContainer.locator("#Rounding-Priority-checkbox")
).toBeEnabled();
const select = styleContainer.locator(
"#Rounding-Priority-checkbox ~ div > select"
);
await select.scrollIntoViewIfNeeded();
await select.selectOption("MorePrecision");
const config = await view.save();
expect(config).toMatchObject({
column_config: {
Profit: {
number_string_format: {
roundingPriority: "morePrecision",
},
},
},
});
await styleContainer.getByText("Fractional Digits").click();
const config2 = await view.save();
expect(config2).toMatchObject({
column_config: {},
});
});

test("Datagrid integration", async ({ page }) => {
const view = new PageView(page);
const datagrid = new DataGrid(page);
await view.restore({
plugin: "Datagrid",
columns: ["Profit"],
column_config: {
Profit: {
number_string_format: {
minimumIntegerDigits: 3,
maximumFractionDigits: 0,
roundingIncrement: 50,
roundingMode: "ceil",
notation: "compact",
compactDisplay: "short",
signDisplay: "always",
},
},
},
});
const decimal = await datagrid.regularTable.table.innerHTML();
await compareContentsToSnapshot(decimal, [
"datagrid-integration-decimal.html",
]);
await view.restore({
plugin: "Datagrid",
columns: ["Profit"],
column_config: {
Profit: {
number_string_format: {
style: "currency",
currency: "USD",
currencySign: "accounting",
},
},
},
});
const currency = await datagrid.regularTable.table.innerHTML();
await compareContentsToSnapshot(currency, [
"datagrid-integration-currency.html",
]);

await view.restore({
plugin: "Datagrid",
columns: ["Profit"],
column_config: {
Profit: {
number_string_format: {
style: "unit",
unit: "byte",
},
},
},
});
const unit = await datagrid.regularTable.table.innerHTML();
await compareContentsToSnapshot(unit, ["datagrid-integration-unit.html"]);

await view.restore({
plugin: "Datagrid",
columns: ["Profit"],
column_config: {
Profit: {
number_string_format: {
style: "percent",
},
},
},
});
const data = await datagrid.regularTable.table.innerHTML();
await compareContentsToSnapshot(data, [
"datagrid-integration-percent.html",
]);
});
Binary file modified tools/perspective-test/results.tar.gz
Binary file not shown.

0 comments on commit 1992abb

Please sign in to comment.