Skip to content

Commit 20b8e6e

Browse files
committed
tooltip vr tests
1 parent 9f5a799 commit 20b8e6e

File tree

9 files changed

+134
-11
lines changed

9 files changed

+134
-11
lines changed

pages/03-core/core-line-chart.page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ const baseline = [
5252
{ x: 1601013600000, y: 293910 },
5353
];
5454

55-
const dataA = baseline.map(({ x, y }) => ({ name: "A", x, y }));
56-
const dataB = baseline.map(({ x, y }) => ({ name: "B", x, y: y === null ? null : y + randomInt(-100000, 100000) }));
57-
const dataC = baseline.map(({ x, y }) => ({ name: "C", x, y: y === null ? null : y + randomInt(-150000, 50000) }));
55+
const dataA = baseline.map(({ x, y }) => ({ x, y }));
56+
const dataB = baseline.map(({ x, y }) => ({ x, y: y === null ? null : y + randomInt(-100000, 100000) }));
57+
const dataC = baseline.map(({ x, y }) => ({ x, y: y === null ? null : y + randomInt(-150000, 50000) }));
5858

5959
const series: Highcharts.SeriesOptionsType[] = [
6060
{

pages/03-core/debugger-module.page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default function () {
2424
<Page
2525
title="Debugger module demo"
2626
subtitle="The page demonstrates how debugger module (active in development mode only) helps finding issues."
27+
screenshotArea={false}
2728
>
2829
<ExampleMixedChart />
2930
</Page>

pages/03-core/simple-zooming.page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export default function () {
141141
]}
142142
/>
143143
}
144+
screenshotArea={false}
144145
>
145146
<Charts />
146147
</Page>

pages/03-core/synced-charts.page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default function () {
115115
title="Synched charts demo"
116116
subtitle="This page demonstrates how charts can have a synchronized tooltip and legend"
117117
settings={<PageSettingsForm selectedSettings={["showLegend", "tooltipSize", "tooltipPlacement"]} />}
118+
screenshotArea={false}
118119
>
119120
<Charts />
120121
</Page>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { omit } from "lodash";
5+
6+
import Button from "@cloudscape-design/components/button";
7+
8+
import CoreChart from "../../lib/components/internal-do-not-use/core-chart";
9+
import { dateFormatter } from "../common/formatters";
10+
import { useChartSettings } from "../common/page-settings";
11+
import { Page } from "../common/templates";
12+
13+
const baseline = [
14+
{ x: 1600984800000, y: 58020 },
15+
{ x: 1600985700000, y: 102402 },
16+
{ x: 1600986600000, y: 104920 },
17+
{ x: 1600987500000, y: 94031 },
18+
{ x: 1600988400000, y: 125021 },
19+
{ x: 1600989300000, y: 159219 },
20+
{ x: 1600990200000, y: 193082 },
21+
{ x: 1600991100000, y: 162592 },
22+
{ x: 1600992000000, y: 274021 },
23+
{ x: 1600992900000, y: 264286 },
24+
{ x: 1600993800000, y: 289210 },
25+
{ x: 1600994700000, y: 256362 },
26+
{ x: 1600995600000, y: 257306 },
27+
{ x: 1600996500000, y: 186776 },
28+
];
29+
30+
const dataA = baseline.map(({ x, y }) => ({ x, y }));
31+
const dataB = baseline.map(({ x, y }, index) => ({ x, y: y + index * 10000 }));
32+
33+
const series: Highcharts.SeriesOptionsType[] = [
34+
{ name: "A", type: "spline", data: dataA },
35+
{ name: "B", type: "spline", data: dataB },
36+
];
37+
38+
export default function () {
39+
const { chartProps } = useChartSettings();
40+
return (
41+
<Page title="Cartesian chart tooltip visual regression page">
42+
<CoreChart
43+
{...omit(chartProps.cartesian, "ref")}
44+
options={{
45+
lang: { accessibility: { chartContainerLabel: "Line chart" } },
46+
series: series,
47+
xAxis: [{ type: "datetime", title: { text: "Time (UTC)" }, valueFormatter: dateFormatter }],
48+
yAxis: [{ title: { text: "Events" } }],
49+
}}
50+
chartHeight={400}
51+
tooltip={{ placement: "outside" }}
52+
getTooltipContent={() => ({
53+
footer() {
54+
return <Button>Footer action</Button>;
55+
},
56+
})}
57+
callback={(api) => {
58+
setTimeout(() => {
59+
if (api.chart.series) {
60+
const point = api.chart.series[0].data.find((p) => p.x === 1600990200000)!;
61+
api.highlightChartPoint(point);
62+
}
63+
}, 0);
64+
}}
65+
/>
66+
</Page>
67+
);
68+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { omit } from "lodash";
5+
6+
import Button from "@cloudscape-design/components/button";
7+
8+
import CoreChart from "../../lib/components/internal-do-not-use/core-chart";
9+
import { useChartSettings } from "../common/page-settings";
10+
import { Page } from "../common/templates";
11+
12+
const series: Highcharts.SeriesOptionsType[] = [
13+
{
14+
name: "Resource count",
15+
type: "pie",
16+
data: [
17+
{ name: "Running", y: 60 },
18+
{ name: "Failed", y: 30 },
19+
{ name: "In-progress", y: 10 },
20+
],
21+
},
22+
];
23+
24+
export default function () {
25+
const { chartProps } = useChartSettings();
26+
return (
27+
<Page title="Pie chart tooltip visual regression page">
28+
<CoreChart
29+
{...omit(chartProps.cartesian, "ref")}
30+
options={{
31+
lang: { accessibility: { chartContainerLabel: "Pie chart" } },
32+
series: series,
33+
}}
34+
chartHeight={400}
35+
getTooltipContent={() => ({
36+
footer() {
37+
return <Button>Footer action</Button>;
38+
},
39+
})}
40+
callback={(api) => {
41+
setTimeout(() => {
42+
if (api.chart.series) {
43+
const point = api.chart.series[0].data.find((p) => p.y === 30)!;
44+
api.highlightChartPoint(point);
45+
}
46+
}, 0);
47+
}}
48+
/>
49+
</Page>
50+
);
51+
}

src/core/styles.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
@use "../../node_modules/@cloudscape-design/design-tokens/index.scss" as cs;
7-
@use "@cloudscape-design/component-toolkit/internal/focus-visible" as focus-visible;
87

98
$side-legend-max-inline-size: 30%;
109
$side-legend-min-inline-size: max(20%, 150px);
@@ -82,12 +81,6 @@ $side-legend-min-inline-size: max(20%, 150px);
8281
text-overflow: ellipsis;
8382
}
8483

85-
.focus-outline {
86-
@include focus-visible.when-visible-unfocused {
87-
stroke: cs.$color-border-item-focused;
88-
}
89-
}
90-
9184
.error-range {
9285
display: flex;
9386
justify-content: space-between;

src/internal/styles.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
SPDX-License-Identifier: Apache-2.0
44
*/
55
@use "../../node_modules/@cloudscape-design/design-tokens/index.scss" as cs;
6+
@use "@cloudscape-design/component-toolkit/internal/focus-visible" as focus-visible;
67

78
$base-size: 10px;
89
$font-family-base: cs.$font-family-base;
@@ -107,3 +108,9 @@ $font-weight-normal: 400;
107108
// But its replacement, `overflow-wrap: anywhere`, is not supported in Safari 14.0 and 15.0.
108109
word-break: break-word;
109110
}
111+
112+
.focus-outline {
113+
@include focus-visible.when-visible-unfocused {
114+
stroke: cs.$color-border-item-focused;
115+
}
116+
}

test/visual/index.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import { setupTest } from "../utils";
1111
const pagesMap = import.meta.glob("../../pages/**/*.page.tsx", { as: "raw" });
1212
const pages = Object.keys(pagesMap)
1313
.map((page) => page.replace(/\.page\.tsx$/, ""))
14-
.map((page) => "/#/" + path.relative("../../pages/", page));
14+
.map((page) => "/#/" + path.relative("../../pages/", page) + "?screenshotMode=true");
1515

1616
test.each(pages)("matches snapshot for %s", (route) =>
1717
setupTest(route, ScreenshotPageObject, async (page) => {
1818
const hasScreenshotArea = await page.isExisting(".screenshot-area");
1919

2020
if (hasScreenshotArea) {
21+
await page.waitForJsTimers(100);
2122
const pngString = await page.fullPageScreenshot();
2223
expect(pngString).toMatchImageSnapshot();
2324
}

0 commit comments

Comments
 (0)