@umituz/web-dashboard 10.2.0 → 10.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/package.json +3 -8
  2. package/src/domains/layouts/components/FilterPanel.test.tsx +0 -21
  3. package/src/domains/notifications/components/NotificationsPage.tsx +1 -1
  4. package/src/domains/settings/components/index.ts +0 -1
  5. package/src/styles/dashboard.contract.test.ts +9 -7
  6. package/src/styles/dashboard.css +0 -1
  7. package/src/domains/charts/charts.css +0 -455
  8. package/src/domains/charts/components/ActivityHeatmap.test.tsx +0 -48
  9. package/src/domains/charts/components/ActivityHeatmap.tsx +0 -58
  10. package/src/domains/charts/components/BarChart.test.tsx +0 -91
  11. package/src/domains/charts/components/BarChart.tsx +0 -143
  12. package/src/domains/charts/components/ChartCard.tsx +0 -39
  13. package/src/domains/charts/components/ChartPrimitives.test.tsx +0 -90
  14. package/src/domains/charts/components/ChartTip.tsx +0 -18
  15. package/src/domains/charts/components/Donut.test.tsx +0 -51
  16. package/src/domains/charts/components/Donut.tsx +0 -97
  17. package/src/domains/charts/components/HBars.tsx +0 -31
  18. package/src/domains/charts/components/Legend.tsx +0 -21
  19. package/src/domains/charts/components/LineChart.test.tsx +0 -81
  20. package/src/domains/charts/components/LineChart.tsx +0 -244
  21. package/src/domains/charts/components/Sparkline.tsx +0 -35
  22. package/src/domains/charts/components/index.ts +0 -16
  23. package/src/domains/charts/index.ts +0 -28
  24. package/src/domains/charts/ssr.test.tsx +0 -35
  25. package/src/domains/charts/types/index.ts +0 -8
  26. package/src/domains/charts/utils.ts +0 -57
  27. package/src/domains/settings/components/AuditLogList.tsx +0 -57
@@ -1,91 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { fireEvent, render } from "@testing-library/react";
3
- import { BarChart } from "./BarChart";
4
-
5
- const labels = ["Oca", "Şub", "Mar"];
6
-
7
- describe("BarChart", () => {
8
- it("renders one column per label with a bar per grouped series", () => {
9
- const { container } = render(
10
- <BarChart
11
- labels={labels}
12
- series={[
13
- { label: "A", values: [1, 2, 3] },
14
- { label: "B", values: [3, 2, 1] },
15
- ]}
16
- />,
17
- );
18
- const cols = container.querySelectorAll(".udb-barchart__col");
19
- expect(cols).toHaveLength(3);
20
- expect(cols[0]!.querySelectorAll(".udb-barchart__bar")).toHaveLength(2);
21
- });
22
-
23
- it("scales grouped heights against the global max", () => {
24
- const { container } = render(
25
- <BarChart labels={labels} series={[{ label: "A", values: [4, 1, 2] }]} />,
26
- );
27
- const bars = [...container.querySelectorAll(".udb-barchart__bar")] as HTMLElement[];
28
- expect(bars.map((b) => b.style.height)).toEqual(["100%", "25%", "50%"]);
29
- });
30
-
31
- it("scales stacked segments against column totals", () => {
32
- const { container } = render(
33
- <BarChart
34
- labels={labels}
35
- stacking="stacked"
36
- series={[
37
- { label: "A", values: [2, 1, 0] },
38
- { label: "B", values: [2, 3, 2] },
39
- ]}
40
- />,
41
- );
42
- const cols = container.querySelectorAll(".udb-barchart__col");
43
- const first = [...cols[0]!.querySelectorAll(".udb-barchart__bar")] as HTMLElement[];
44
- expect(first.map((b) => b.style.height)).toEqual(["50%", "50%"]);
45
- const third = [...cols[2]!.querySelectorAll(".udb-barchart__bar")] as HTMLElement[];
46
- expect(third[0]!.style.height).toBe("0%");
47
- });
48
-
49
- it("shows per-series rows plus a total row in the stacked tooltip", () => {
50
- const { container } = render(
51
- <BarChart
52
- labels={labels}
53
- stacking="stacked"
54
- totalLabel="Toplam"
55
- series={[
56
- { label: "A", values: [2, 1, 0] },
57
- { label: "B", values: [2, 3, 2] },
58
- ]}
59
- />,
60
- );
61
- fireEvent.mouseEnter(container.querySelectorAll(".udb-barchart__col")[0]!);
62
- const tip = container.querySelector(".udb-barchart__tip");
63
- expect(tip).not.toBeNull();
64
- expect(tip!.textContent).toContain("A");
65
- expect(tip!.textContent).toContain("B");
66
- expect(tip!.textContent).toContain("Toplam");
67
- expect(tip!.querySelector(".udb-barchart__tiprow--total")!.textContent).toContain("4");
68
- });
69
-
70
- it("positions the goal line relative to the max", () => {
71
- const { container } = render(
72
- <BarChart
73
- labels={labels}
74
- goalLine={{ value: 2, label: "Hedef" }}
75
- series={[{ label: "A", values: [4, 4, 4] }]}
76
- />,
77
- );
78
- const goal = container.querySelector(".udb-barchart__goal") as HTMLElement;
79
- expect(goal.style.bottom).toBe("50%");
80
- expect(goal.textContent).toContain("Hedef");
81
- });
82
-
83
- it("colors series through the --udb-chart tokens by default", () => {
84
- const { container } = render(
85
- <BarChart labels={labels} series={[{ label: "A", values: [1, 2, 3] }]} />,
86
- );
87
- const bar = container.querySelector(".udb-barchart__bar") as HTMLElement;
88
- expect(bar.style.background).toContain("var(--udb-chart-1");
89
- expect(bar.style.background).toContain("#357344");
90
- });
91
- });
@@ -1,143 +0,0 @@
1
- import { useState } from 'react';
2
- import { seriesColor } from '../utils';
3
-
4
- export interface BarSeries {
5
- key?: string;
6
- label: string;
7
- values?: readonly number[];
8
- data?: readonly number[];
9
- tone?: string;
10
- color?: string;
11
- accents?: readonly (string | undefined)[];
12
- }
13
-
14
- export interface BarChartGoalLine {
15
- value: number;
16
- label?: string;
17
- tone?: string;
18
- }
19
-
20
- export interface BarChartProps {
21
- labels: readonly string[];
22
- series: BarSeries[];
23
- stacking?: 'grouped' | 'stacked';
24
- totalLabel?: string;
25
- height?: number;
26
- formatValue?: (v: number) => string;
27
- formatLabel?: (l: string) => string;
28
- goalLine?: BarChartGoalLine;
29
- }
30
-
31
- export function BarChart({
32
- labels,
33
- series,
34
- stacking = 'grouped',
35
- totalLabel = 'Σ',
36
- height = 130,
37
- formatValue = (v: number) => String(v),
38
- formatLabel = (l: string) => l,
39
- goalLine,
40
- }: BarChartProps) {
41
- const [hover, setHover] = useState<number | null>(null);
42
- const vals = (s: BarSeries) => s.values ?? s.data ?? [];
43
- const columnTotals = labels.map((_, i) => series.reduce((sum, s) => sum + (vals(s)[i] ?? 0), 0));
44
- const max =
45
- stacking === 'stacked'
46
- ? Math.max(1, ...columnTotals, goalLine?.value ?? 0)
47
- : Math.max(1, ...series.flatMap((s) => vals(s)), goalLine?.value ?? 0);
48
- const toneOf = (s: BarSeries, i: number) => s.tone ?? s.color ?? seriesColor(i);
49
- const accentOf = (s: BarSeries, si: number, i: number) => s.accents?.[i] ?? toneOf(s, si);
50
- const goalPct = goalLine !== undefined ? Math.min(100, (goalLine.value / max) * 100) : null;
51
- return (
52
- <div className="udb-barchart" style={{ height }}>
53
- {goalLine !== undefined && goalPct !== null && (
54
- <div
55
- className="udb-barchart__goal"
56
- style={{
57
- bottom: `${goalPct}%`,
58
- ...(goalLine.tone !== undefined ? { borderTopColor: goalLine.tone } : {}),
59
- }}
60
- title={goalLine.label ?? formatValue(goalLine.value)}
61
- aria-hidden="true"
62
- >
63
- {goalLine.label !== undefined && (
64
- <span
65
- className="udb-barchart__goallabel"
66
- style={
67
- goalLine.tone !== undefined
68
- ? { color: goalLine.tone, borderColor: goalLine.tone }
69
- : undefined
70
- }
71
- >
72
- {goalLine.label}
73
- </span>
74
- )}
75
- </div>
76
- )}
77
- {labels.map((label, i) => (
78
- <div
79
- key={label}
80
- className="udb-barchart__col"
81
- onMouseEnter={() => setHover(i)}
82
- onMouseLeave={() => setHover(null)}
83
- >
84
- {stacking === 'stacked' ? (
85
- <div className="udb-barchart__bars udb-barchart__bars--stacked">
86
- {series.map((s, si) => {
87
- const v = vals(s)[i] ?? 0;
88
- return (
89
- <div
90
- key={s.key ?? s.label}
91
- className="udb-barchart__bar"
92
- style={{
93
- height: `${(v / max) * 100}%`,
94
- background: accentOf(s, si, i),
95
- opacity: hover === null || hover === i ? 1 : 0.4,
96
- ...(v === 0 ? { minHeight: 0 } : {}),
97
- }}
98
- />
99
- );
100
- })}
101
- </div>
102
- ) : (
103
- <div className="udb-barchart__bars">
104
- {series.map((s, si) => (
105
- <div
106
- key={s.key ?? s.label}
107
- className="udb-barchart__bar"
108
- style={{
109
- height: `${Math.max(2, ((vals(s)[i] ?? 0) / max) * 100)}%`,
110
- background: accentOf(s, si, i),
111
- opacity: hover === null || hover === i ? 1 : 0.4,
112
- }}
113
- />
114
- ))}
115
- </div>
116
- )}
117
- {hover === i && (
118
- <div className="udb-barchart__tip">
119
- <div className="udb-barchart__tiptitle">{formatLabel(label)}</div>
120
- {series.map((s, si) => (
121
- <div key={s.key ?? s.label} className="udb-barchart__tiprow">
122
- <span className="udb-barchart__tiplabel">
123
- <span className="udb-chartlegend__dot" style={{ background: accentOf(s, si, i) }} />
124
- {s.label}
125
- </span>
126
- <b>{formatValue(vals(s)[i] ?? 0)}</b>
127
- </div>
128
- ))}
129
- {stacking === 'stacked' && (
130
- <div className="udb-barchart__tiprow udb-barchart__tiprow--total">
131
- <span className="udb-barchart__tiplabel">
132
- <b>{totalLabel}</b>
133
- </span>
134
- <b>{formatValue(columnTotals[i] ?? 0)}</b>
135
- </div>
136
- )}
137
- </div>
138
- )}
139
- </div>
140
- ))}
141
- </div>
142
- );
143
- }
@@ -1,39 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { TipState } from '../utils';
3
- import { ChartTip } from './ChartTip';
4
-
5
- export interface ChartCardProps {
6
- title: string;
7
- subtitle?: string;
8
- legend?: ReactNode;
9
- actions?: ReactNode;
10
- children: ReactNode;
11
- tip: TipState | null;
12
- hostRef?: React.Ref<HTMLDivElement>;
13
- onMouseLeave?: () => void;
14
- bare?: boolean;
15
- className?: string;
16
- }
17
-
18
- export function ChartCard({ title, subtitle, legend, actions, children, tip, hostRef, onMouseLeave, bare, className }: ChartCardProps) {
19
- return (
20
- <div className={['udb-chartcard', className].filter(Boolean).join(' ')}>
21
- <div className="udb-chartcard__head">
22
- <div className="udb-chartcard__heading">
23
- <div className="udb-chartcard__title">{title}</div>
24
- {subtitle && <div className="udb-chartcard__sub">{subtitle}</div>}
25
- </div>
26
- <div className="udb-chartcard__tools">
27
- {legend}
28
- {actions}
29
- </div>
30
- </div>
31
- <div className="udb-chartcard__body" style={bare ? { padding: 0 } : undefined}>
32
- <div ref={hostRef} className="udb-chartcard__plot" onMouseLeave={onMouseLeave}>
33
- {children}
34
- {tip && <ChartTip tip={tip} />}
35
- </div>
36
- </div>
37
- </div>
38
- );
39
- }
@@ -1,90 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { render } from "@testing-library/react";
3
- import { ChartCard } from "./ChartCard";
4
- import { Legend } from "./Legend";
5
- import { HBars } from "./HBars";
6
- import { Sparkline } from "./Sparkline";
7
- import type { TipState } from "../utils";
8
-
9
- describe("ChartCard", () => {
10
- const tip: TipState = { x: 10, y: 20, title: "bugün", rows: [{ label: "A", value: "7", color: "#111111" }] };
11
-
12
- it("renders the heading, tools, body and tooltip", () => {
13
- const { container } = render(
14
- <ChartCard
15
- title="Gelir"
16
- subtitle="son 30 gün"
17
- legend={<Legend items={[{ label: "A", color: "#111111", value: "7" }]} />}
18
- actions={<button type="button">act</button>}
19
- tip={tip}
20
- >
21
- <div>plot</div>
22
- </ChartCard>,
23
- );
24
- expect(container.querySelector(".udb-chartcard__title")!.textContent).toBe("Gelir");
25
- expect(container.querySelector(".udb-chartcard__sub")!.textContent).toBe("son 30 gün");
26
- expect(container.querySelector(".udb-chartlegend__value")!.textContent).toBe("7");
27
- expect(container.querySelector(".udb-chartcard__tools button")).not.toBeNull();
28
- expect(container.querySelector(".udb-charttip__title")!.textContent).toBe("bugün");
29
- expect(container.querySelector(".udb-charttip")!.textContent).toContain("7");
30
- });
31
-
32
- it("omits the tooltip when tip is null and zeroes body padding when bare", () => {
33
- const { container } = render(
34
- <ChartCard title="T" tip={null} bare>
35
- <div>x</div>
36
- </ChartCard>,
37
- );
38
- expect(container.querySelector(".udb-charttip")).toBeNull();
39
- expect(container.querySelector<HTMLElement>(".udb-chartcard__body")!.style.padding).toBe("0px");
40
- });
41
- });
42
-
43
- describe("Legend", () => {
44
- it("renders items with optional value and hint", () => {
45
- const { container } = render(
46
- <Legend
47
- items={[
48
- { label: "A", color: "#111111", value: "3" },
49
- { label: "B", color: "#222222", hint: "tahmini" },
50
- ]}
51
- />,
52
- );
53
- const items = container.querySelectorAll(".udb-chartlegend__item");
54
- expect(items).toHaveLength(2);
55
- expect(items[0]!.textContent).toContain("3");
56
- expect(items[1]!.textContent).toContain("tahmini");
57
- });
58
- });
59
-
60
- describe("HBars", () => {
61
- it("scales fill widths against the largest row and applies tones", () => {
62
- const { container } = render(
63
- <HBars
64
- rows={[
65
- { label: "A", value: 5 },
66
- { label: "B", value: 10, tone: "#00ff00" },
67
- ]}
68
- formatValue={(n) => `${n}₺`}
69
- />,
70
- );
71
- const fills = [...container.querySelectorAll(".udb-hbars__fill")] as HTMLElement[];
72
- expect(fills.map((f) => f.style.width)).toEqual(["50%", "100%"]);
73
- expect(fills[1]!.style.background).toBe("rgb(0, 255, 0)");
74
- expect(container.querySelector(".udb-hbars__value")!.textContent).toBe("5₺");
75
- });
76
- });
77
-
78
- describe("Sparkline", () => {
79
- it("renders a gradient area, line and end dot", () => {
80
- const { container } = render(<Sparkline data={[1, 5, 3]} />);
81
- expect(container.querySelector("linearGradient")).not.toBeNull();
82
- expect(container.querySelector("circle")).not.toBeNull();
83
- expect(container.querySelectorAll("path")).toHaveLength(2);
84
- });
85
-
86
- it("renders nothing for fewer than two points", () => {
87
- const { container } = render(<Sparkline data={[1]} />);
88
- expect(container.firstChild).toBeNull();
89
- });
90
- });
@@ -1,18 +0,0 @@
1
- import type { TipState } from '../utils';
2
-
3
- export function ChartTip({ tip }: { tip: TipState }) {
4
- return (
5
- <div className="udb-charttip" style={{ left: tip.x, top: tip.y }}>
6
- <div className="udb-charttip__title">{tip.title}</div>
7
- {tip.rows.map((r, i) => (
8
- <div key={i} className="udb-charttip__row">
9
- <span className="udb-charttip__label">
10
- {r.color && <span className="udb-chartlegend__dot" style={{ background: r.color }} />}
11
- {r.label}
12
- </span>
13
- <b>{r.value}</b>
14
- </div>
15
- ))}
16
- </div>
17
- );
18
- }
@@ -1,51 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { fireEvent, render } from "@testing-library/react";
3
- import { Donut } from "./Donut";
4
-
5
- describe("Donut", () => {
6
- it("renders one segment per entry with computed percentages", () => {
7
- const { container } = render(
8
- <Donut
9
- segments={[
10
- { label: "A", value: 3 },
11
- { label: "B", value: 1 },
12
- ]}
13
- centerValue="4"
14
- centerLabel="total"
15
- />,
16
- );
17
- expect(container.querySelectorAll(".udb-donut__seg")).toHaveLength(2);
18
- expect(container.querySelectorAll(".udb-donut__item")).toHaveLength(2);
19
- expect(container.querySelector(".udb-donut__pct")!.textContent).toBe("75%");
20
- expect(container.querySelector(".udb-donut__value")!.textContent).toBe("4");
21
- expect(container.querySelector(".udb-donut__label")!.textContent).toBe("total");
22
- });
23
-
24
- it("swaps the center readout to the hovered segment", () => {
25
- const { container } = render(
26
- <Donut
27
- segments={[
28
- { label: "A", value: 3 },
29
- { label: "B", value: 1 },
30
- ]}
31
- centerValue="4"
32
- />,
33
- );
34
- fireEvent.mouseEnter(container.querySelectorAll(".udb-donut__seg")[1]!);
35
- expect(container.querySelector(".udb-donut__value")!.textContent).toBe("1");
36
- expect(container.querySelector(".udb-donut__label")!.textContent).toBe("B");
37
- });
38
-
39
- it("colors segments through the --udb-chart tokens by default", () => {
40
- const { container } = render(<Donut segments={[{ label: "A", value: 1 }]} />);
41
- const seg = container.querySelector(".udb-donut__seg")!;
42
- expect(seg.getAttribute("stroke")).toContain("var(--udb-chart-1");
43
- });
44
-
45
- it("lets an explicit tone win over the series tokens", () => {
46
- const { container } = render(
47
- <Donut segments={[{ label: "A", value: 1, tone: "#ff0000" }]} />,
48
- );
49
- expect(container.querySelector(".udb-donut__seg")!.getAttribute("stroke")).toBe("#ff0000");
50
- });
51
- });
@@ -1,97 +0,0 @@
1
- import { useState } from 'react';
2
- import { seriesColor } from '../utils';
3
-
4
- export interface DonutSegment {
5
- label: string;
6
- value: number;
7
- tone?: string;
8
- color?: string;
9
- }
10
-
11
- export interface DonutProps {
12
- segments: DonutSegment[];
13
- size?: number;
14
- thickness?: number;
15
- centerValue?: string;
16
- centerLabel?: string;
17
- formatValue?: (v: number) => string;
18
- }
19
-
20
- export function Donut({
21
- segments,
22
- size = 148,
23
- thickness = 18,
24
- centerValue,
25
- centerLabel,
26
- formatValue = (v: number) => String(v),
27
- }: DonutProps) {
28
- const [active, setActive] = useState<number | null>(null);
29
- const total = segments.reduce((sum, seg) => sum + seg.value, 0) || 1;
30
- const radius = (size - thickness) / 2;
31
- const circumference = 2 * Math.PI * radius;
32
- let offset = 0;
33
- return (
34
- <div className="udb-donut">
35
- <div className="udb-donut__wrap" style={{ width: size, height: size }}>
36
- <svg width={size} height={size} style={{ transform: 'rotate(-90deg)' }}>
37
- <circle
38
- cx={size / 2}
39
- cy={size / 2}
40
- r={radius}
41
- fill="none"
42
- stroke="var(--color-muted)"
43
- strokeWidth={thickness}
44
- />
45
- {segments.map((seg, i) => {
46
- const dash = (seg.value / total) * circumference;
47
- const el = (
48
- <circle
49
- key={seg.label}
50
- cx={size / 2}
51
- cy={size / 2}
52
- r={radius}
53
- fill="none"
54
- stroke={seg.tone ?? seg.color ?? seriesColor(i)}
55
- strokeWidth={active === i ? thickness + 3 : thickness}
56
- strokeDasharray={`${dash} ${circumference - dash}`}
57
- strokeDashoffset={-offset}
58
- strokeLinecap="butt"
59
- opacity={active === null || active === i ? 1 : 0.35}
60
- className="udb-donut__seg"
61
- onMouseEnter={() => setActive(i)}
62
- onMouseLeave={() => setActive(null)}
63
- />
64
- );
65
- offset += dash;
66
- return el;
67
- })}
68
- </svg>
69
- <div className="udb-donut__center">
70
- <span className="udb-donut__value">
71
- {active !== null ? formatValue(segments[active]!.value) : centerValue}
72
- </span>
73
- <span className="udb-donut__label">{active !== null ? segments[active]!.label : centerLabel}</span>
74
- </div>
75
- </div>
76
- <div className="udb-donut__list">
77
- {segments.map((seg, i) => (
78
- <div
79
- key={seg.label}
80
- className="udb-donut__item"
81
- onMouseEnter={() => setActive(i)}
82
- onMouseLeave={() => setActive(null)}
83
- >
84
- <span className="udb-donut__itemlabel">
85
- <span className="udb-donut__dot" style={{ background: seg.tone ?? seg.color ?? seriesColor(i) }} />
86
- {seg.label}
87
- </span>
88
- <span className="udb-donut__itemvalue">
89
- {formatValue(seg.value)}
90
- <span className="udb-donut__pct">{Math.round((seg.value / total) * 100)}%</span>
91
- </span>
92
- </div>
93
- ))}
94
- </div>
95
- </div>
96
- );
97
- }
@@ -1,31 +0,0 @@
1
- import type { ReactNode } from 'react';
2
-
3
- export interface HBarRow {
4
- label: ReactNode;
5
- sub?: ReactNode;
6
- value: number;
7
- tone?: string;
8
- }
9
-
10
- export function HBars({ rows, formatValue = (n: number) => String(n) }: { rows: HBarRow[]; formatValue?: (n: number) => string }) {
11
- const max = Math.max(1, ...rows.map((r) => r.value));
12
- return (
13
- <div className="udb-hbars">
14
- {rows.map((r, i) => (
15
- <div key={i} className="udb-hbars__row">
16
- <div className="udb-hbars__label">
17
- <div className="udb-hbars__name">{r.label}</div>
18
- {r.sub && <div className="udb-hbars__sub">{r.sub}</div>}
19
- </div>
20
- <div className="udb-hbars__track">
21
- <div
22
- className="udb-hbars__fill"
23
- style={{ width: `${(r.value / max) * 100}%`, ...(r.tone ? { background: r.tone } : {}) }}
24
- />
25
- </div>
26
- <span className="udb-hbars__value">{formatValue(r.value)}</span>
27
- </div>
28
- ))}
29
- </div>
30
- );
31
- }
@@ -1,21 +0,0 @@
1
- export interface LegendItem {
2
- label: string;
3
- color: string;
4
- value?: string;
5
- hint?: string;
6
- }
7
-
8
- export function Legend({ items }: { items: LegendItem[] }) {
9
- return (
10
- <div className="udb-chartlegend">
11
- {items.map((i) => (
12
- <span key={i.label} className="udb-chartlegend__item">
13
- <span className="udb-chartlegend__dot" style={{ background: i.color }} />
14
- {i.label}
15
- {i.value && <span className="udb-chartlegend__value">{i.value}</span>}
16
- {i.hint && <span className="udb-chartlegend__hint">{i.hint}</span>}
17
- </span>
18
- ))}
19
- </div>
20
- );
21
- }
@@ -1,81 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { fireEvent, render } from "@testing-library/react";
3
- import { LineChart } from "./LineChart";
4
-
5
- const labels = ["1", "2", "3", "4"];
6
-
7
- describe("LineChart", () => {
8
- it("renders nothing without points", () => {
9
- const { container } = render(<LineChart labels={[]} series={[]} />);
10
- expect(container.firstChild).toBeNull();
11
- });
12
-
13
- it("renders a flat area by default", () => {
14
- const { container } = render(
15
- <LineChart labels={labels} series={[{ label: "A", values: [1, 2, 3, 4] }]} />,
16
- );
17
- const paths = container.querySelectorAll("path");
18
- expect(paths).toHaveLength(2);
19
- expect(paths[0]!.getAttribute("opacity")).toBe("0.07");
20
- expect(container.querySelector("linearGradient")).toBeNull();
21
- });
22
-
23
- it("paints the area with a per-series gradient when requested", () => {
24
- const { container } = render(
25
- <LineChart
26
- labels={labels}
27
- series={[{ label: "A", values: [1, 2, 3, 4], areaFill: "gradient" }]}
28
- />,
29
- );
30
- const gradient = container.querySelector("linearGradient");
31
- expect(gradient).not.toBeNull();
32
- expect(gradient!.querySelectorAll("stop")).toHaveLength(2);
33
- const areaPath = [...container.querySelectorAll("path")].find((p) =>
34
- p.getAttribute("fill")?.startsWith("url(#"),
35
- );
36
- expect(areaPath).toBeDefined();
37
- expect(areaPath!.getAttribute("opacity")).toBeNull();
38
- });
39
-
40
- it("drops the area for dashed series", () => {
41
- const { container } = render(
42
- <LineChart labels={labels} series={[{ label: "A", values: [1, 2, 3, 4], dashed: true }]} />,
43
- );
44
- expect(container.querySelectorAll("path")).toHaveLength(1);
45
- expect(container.querySelector("linearGradient")).toBeNull();
46
- });
47
-
48
- it("renders the band and a crosshair with tooltip on hover", () => {
49
- const { container } = render(
50
- <LineChart
51
- labels={labels}
52
- band={{ from: 1, to: 2 }}
53
- series={[{ label: "A", values: [1, 2, 3, 4] }]}
54
- />,
55
- );
56
- expect(container.querySelector(".udb-linechart__band")).not.toBeNull();
57
-
58
- const svg = container.querySelector("svg")!;
59
- fireEvent.mouseMove(svg, { clientX: 700, clientY: 50 });
60
- expect(container.querySelector(".udb-linechart__crosshair")).not.toBeNull();
61
- const tip = container.querySelector(".udb-linechart__tip");
62
- expect(tip).not.toBeNull();
63
- expect(tip!.textContent).toContain("A");
64
- });
65
-
66
- it("renders the built-in legend from the series", () => {
67
- const { container } = render(
68
- <LineChart
69
- labels={labels}
70
- series={[
71
- { label: "A", values: [1, 2, 3, 4] },
72
- { label: "B", values: [4, 3, 2, 1], axis: "right" },
73
- ]}
74
- />,
75
- );
76
- const items = container.querySelectorAll(".udb-chartlegend__item");
77
- expect(items).toHaveLength(2);
78
- expect(items[0]!.textContent).toContain("A");
79
- expect(items[1]!.textContent).toContain("B");
80
- });
81
- });