|
| 1 | +import { test, describe, afterEach, expect } from "vitest"; |
| 2 | +import { cleanup, render, waitFor } from "@self/tootils/render"; |
| 3 | +import { run_shared_prop_tests } from "@self/tootils/shared-prop-tests"; |
| 4 | + |
| 5 | +import NativePlot from "./Index.svelte"; |
| 6 | +import type { NativePlotProps } from "./types"; |
| 7 | + |
| 8 | +const plot_value = { |
| 9 | + columns: ["x", "y", "series"], |
| 10 | + data: [ |
| 11 | + [1, 4, "alpha"], |
| 12 | + [2, 5, "alpha"], |
| 13 | + [1, 7, "beta"], |
| 14 | + [2, 8, "beta"] |
| 15 | + ], |
| 16 | + datatypes: { |
| 17 | + x: "quantitative", |
| 18 | + y: "quantitative", |
| 19 | + series: "nominal" |
| 20 | + }, |
| 21 | + mark: "line" |
| 22 | +} satisfies NativePlotProps["value"]; |
| 23 | + |
| 24 | +const default_props = { |
| 25 | + value: plot_value, |
| 26 | + x: "x", |
| 27 | + y: "y", |
| 28 | + color: null, |
| 29 | + title: null, |
| 30 | + x_title: null, |
| 31 | + y_title: null, |
| 32 | + color_title: null, |
| 33 | + x_bin: null, |
| 34 | + y_aggregate: undefined, |
| 35 | + color_map: null, |
| 36 | + colors_in_legend: null, |
| 37 | + x_lim: null, |
| 38 | + y_lim: null, |
| 39 | + x_label_angle: 0, |
| 40 | + y_label_angle: 0, |
| 41 | + x_axis_format: null, |
| 42 | + y_axis_format: null, |
| 43 | + x_axis_labels_visible: true, |
| 44 | + caption: null, |
| 45 | + sort: null, |
| 46 | + tooltip: "axis" as const, |
| 47 | + buttons: null, |
| 48 | + _selectable: false, |
| 49 | + label: "Native Plot", |
| 50 | + show_label: false, |
| 51 | + scale: null, |
| 52 | + min_width: 160, |
| 53 | + loading_status: undefined, |
| 54 | + height: 260 |
| 55 | +}; |
| 56 | + |
| 57 | +run_shared_prop_tests({ |
| 58 | + component: NativePlot, |
| 59 | + name: "NativePlot", |
| 60 | + base_props: { ...default_props, value: null }, |
| 61 | + has_label: false |
| 62 | +}); |
| 63 | + |
| 64 | +async function waitForChart(container: HTMLElement): Promise<void> { |
| 65 | + await waitFor(() => { |
| 66 | + expect(container.querySelector("svg")).toBeInTheDocument(); |
| 67 | + }); |
| 68 | +} |
| 69 | + |
| 70 | +describe("Props: colors_in_legend", () => { |
| 71 | + afterEach(() => cleanup()); |
| 72 | + |
| 73 | + test("colors_in_legend: [] hides all color legend entries", async () => { |
| 74 | + const { container } = await render(NativePlot, { |
| 75 | + ...default_props, |
| 76 | + color: "series", |
| 77 | + colors_in_legend: [] |
| 78 | + }); |
| 79 | + |
| 80 | + await waitForChart(container); |
| 81 | + |
| 82 | + expect(container).not.toHaveTextContent("alpha"); |
| 83 | + expect(container).not.toHaveTextContent("beta"); |
| 84 | + expect(container).not.toHaveTextContent("series"); |
| 85 | + }); |
| 86 | + |
| 87 | + test("colors_in_legend limits visible color legend entries", async () => { |
| 88 | + const { container } = await render(NativePlot, { |
| 89 | + ...default_props, |
| 90 | + color: "series", |
| 91 | + colors_in_legend: ["alpha"] |
| 92 | + }); |
| 93 | + |
| 94 | + await waitForChart(container); |
| 95 | + |
| 96 | + expect(container).toHaveTextContent("alpha"); |
| 97 | + expect(container).not.toHaveTextContent("beta"); |
| 98 | + }); |
| 99 | +}); |
0 commit comments