@terreno/ui 57.8.0 → 57.9.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 (134) hide show
  1. package/dist/AreaChart.d.ts +1 -1
  2. package/dist/AreaChart.d.ts.map +1 -1
  3. package/dist/AreaChart.js +70 -22
  4. package/dist/AreaChart.js.map +1 -1
  5. package/dist/BarChart.d.ts.map +1 -1
  6. package/dist/BarChart.js +55 -13
  7. package/dist/BarChart.js.map +1 -1
  8. package/dist/ChartCard.d.ts +5 -0
  9. package/dist/ChartCard.d.ts.map +1 -0
  10. package/dist/ChartCard.js +18 -0
  11. package/dist/ChartCard.js.map +1 -0
  12. package/dist/Common.d.ts +79 -5
  13. package/dist/Common.d.ts.map +1 -1
  14. package/dist/Common.js.map +1 -1
  15. package/dist/DashboardGrid.d.ts +6 -2
  16. package/dist/DashboardGrid.d.ts.map +1 -1
  17. package/dist/DashboardGrid.js +43 -10
  18. package/dist/DashboardGrid.js.map +1 -1
  19. package/dist/DonutChart.d.ts.map +1 -1
  20. package/dist/DonutChart.js +20 -10
  21. package/dist/DonutChart.js.map +1 -1
  22. package/dist/DropdownMenuItem.d.ts +16 -0
  23. package/dist/DropdownMenuItem.d.ts.map +1 -0
  24. package/dist/DropdownMenuItem.js +11 -0
  25. package/dist/DropdownMenuItem.js.map +1 -0
  26. package/dist/FilePickerButton.d.ts.map +1 -1
  27. package/dist/FilePickerButton.js +70 -10
  28. package/dist/FilePickerButton.js.map +1 -1
  29. package/dist/GPTChat.d.ts.map +1 -1
  30. package/dist/GPTChat.js +103 -14
  31. package/dist/GPTChat.js.map +1 -1
  32. package/dist/LineChart.d.ts +1 -1
  33. package/dist/LineChart.d.ts.map +1 -1
  34. package/dist/LineChart.js +62 -21
  35. package/dist/LineChart.js.map +1 -1
  36. package/dist/Scorecard.d.ts +5 -0
  37. package/dist/Scorecard.d.ts.map +1 -0
  38. package/dist/Scorecard.js +11 -0
  39. package/dist/Scorecard.js.map +1 -0
  40. package/dist/SparklineChart.d.ts +5 -0
  41. package/dist/SparklineChart.d.ts.map +1 -0
  42. package/dist/SparklineChart.js +35 -0
  43. package/dist/SparklineChart.js.map +1 -0
  44. package/dist/TextField.d.ts.map +1 -1
  45. package/dist/TextField.js +12 -4
  46. package/dist/TextField.js.map +1 -1
  47. package/dist/ToastNotifications.d.ts.map +1 -1
  48. package/dist/ToastNotifications.js +29 -6
  49. package/dist/ToastNotifications.js.map +1 -1
  50. package/dist/WebDropdownMenu.d.ts +2 -1
  51. package/dist/WebDropdownMenu.d.ts.map +1 -1
  52. package/dist/WebDropdownMenu.js +2 -6
  53. package/dist/WebDropdownMenu.js.map +1 -1
  54. package/dist/charts/ChartFacadeContainer.d.ts +10 -0
  55. package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
  56. package/dist/charts/ChartFacadeContainer.js +10 -0
  57. package/dist/charts/ChartFacadeContainer.js.map +1 -0
  58. package/dist/charts/ChartFrame.d.ts +4 -0
  59. package/dist/charts/ChartFrame.d.ts.map +1 -1
  60. package/dist/charts/ChartFrame.js +4 -2
  61. package/dist/charts/ChartFrame.js.map +1 -1
  62. package/dist/charts/layout.d.ts +9 -2
  63. package/dist/charts/layout.d.ts.map +1 -1
  64. package/dist/charts/layout.js +28 -6
  65. package/dist/charts/layout.js.map +1 -1
  66. package/dist/charts/scales.d.ts +3 -1
  67. package/dist/charts/scales.d.ts.map +1 -1
  68. package/dist/charts/scales.js +7 -7
  69. package/dist/charts/scales.js.map +1 -1
  70. package/dist/charts/series.d.ts +15 -0
  71. package/dist/charts/series.d.ts.map +1 -0
  72. package/dist/charts/series.js +19 -0
  73. package/dist/charts/series.js.map +1 -0
  74. package/dist/charts/types/chartTypes.d.ts +7 -0
  75. package/dist/charts/types/chartTypes.d.ts.map +1 -1
  76. package/dist/dashboardGridLayout.d.ts +6 -0
  77. package/dist/dashboardGridLayout.d.ts.map +1 -1
  78. package/dist/dashboardGridLayout.js +19 -3
  79. package/dist/dashboardGridLayout.js.map +1 -1
  80. package/dist/index.d.ts +4 -1
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +1 -1
  83. package/dist/index.js.map +1 -1
  84. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +9 -0
  85. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  86. package/dist/lazyBoundaries/heavyOptionalExports.js +6 -0
  87. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  88. package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
  89. package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
  90. package/dist/resolveDocumentBodyPortalTarget.js +12 -0
  91. package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
  92. package/package.json +1 -1
  93. package/src/AIRequestExplorer.test.tsx +2 -2
  94. package/src/AreaChart.test.tsx +81 -0
  95. package/src/AreaChart.tsx +171 -62
  96. package/src/BarChart.test.tsx +119 -0
  97. package/src/BarChart.tsx +94 -20
  98. package/src/ChartCard.test.tsx +79 -0
  99. package/src/ChartCard.tsx +80 -0
  100. package/src/Common.ts +69 -2
  101. package/src/DashboardGrid.test.tsx +98 -1
  102. package/src/DashboardGrid.tsx +71 -20
  103. package/src/DonutChart.test.tsx +73 -0
  104. package/src/DonutChart.tsx +87 -14
  105. package/src/DropdownMenuItem.tsx +48 -0
  106. package/src/FilePickerButton.test.tsx +60 -6
  107. package/src/FilePickerButton.tsx +116 -28
  108. package/src/GPTChat.test.tsx +133 -6
  109. package/src/GPTChat.tsx +196 -38
  110. package/src/LineChart.test.tsx +104 -0
  111. package/src/LineChart.tsx +154 -58
  112. package/src/Scorecard.test.tsx +65 -0
  113. package/src/Scorecard.tsx +45 -0
  114. package/src/SparklineChart.test.tsx +69 -0
  115. package/src/SparklineChart.tsx +85 -0
  116. package/src/TextField.test.tsx +16 -0
  117. package/src/TextField.tsx +13 -3
  118. package/src/ToastNotifications.tsx +33 -6
  119. package/src/ToastNotifications.webModal.test.tsx +285 -0
  120. package/src/WebDropdownMenu.tsx +3 -7
  121. package/src/bunSetup.ts +1 -0
  122. package/src/charts/ChartFacadeContainer.tsx +35 -0
  123. package/src/charts/ChartFrame.tsx +39 -1
  124. package/src/charts/layout.test.ts +22 -1
  125. package/src/charts/layout.ts +37 -4
  126. package/src/charts/scales.test.ts +33 -0
  127. package/src/charts/scales.ts +10 -6
  128. package/src/charts/series.ts +43 -0
  129. package/src/charts/types/chartTypes.ts +8 -0
  130. package/src/dashboardGridLayout.test.ts +59 -1
  131. package/src/dashboardGridLayout.ts +30 -3
  132. package/src/index.tsx +6 -0
  133. package/src/lazyBoundaries/heavyOptionalExports.tsx +21 -0
  134. package/src/resolveDocumentBodyPortalTarget.ts +11 -0
package/src/GPTChat.tsx CHANGED
@@ -1,3 +1,4 @@
1
+ import {DateTime} from "luxon";
1
2
  import React, {useCallback, useEffect, useRef, useState} from "react";
2
3
  import {
3
4
  Platform,
@@ -9,6 +10,8 @@ import {
9
10
  import {AttachmentPreview} from "./AttachmentPreview";
10
11
  import {Box} from "./Box";
11
12
  import {Button} from "./Button";
13
+ import {DropdownMenuItem} from "./DropdownMenuItem";
14
+ import {DropdownPanel} from "./DropdownPanel";
12
15
  import type {SelectedFile} from "./FilePickerButton";
13
16
  import {FilePickerButton} from "./FilePickerButton";
14
17
  import {Heading} from "./Heading";
@@ -228,18 +231,103 @@ const handleDownloadFile = (url: string, filename: string): void => {
228
231
  document.body.removeChild(link);
229
232
  };
230
233
 
234
+ const IMAGE_EXTENSIONS: Record<string, string> = {
235
+ "image/gif": "gif",
236
+ "image/jpeg": "jpg",
237
+ "image/png": "png",
238
+ "image/webp": "webp",
239
+ };
240
+
241
+ const getImageFilename = (part: ImageContentPart): string => {
242
+ const extension = IMAGE_EXTENSIONS[part.mimeType ?? ""] ?? "png";
243
+ return `image-${DateTime.now().toMillis()}.${extension}`;
244
+ };
245
+
246
+ // Browsers reliably accept only PNG on the clipboard, so other formats are redrawn as PNG.
247
+ const convertBlobToPng = async (blob: Blob): Promise<Blob> => {
248
+ if (blob.type === "image/png") {
249
+ return blob;
250
+ }
251
+ const bitmap = await createImageBitmap(blob);
252
+ const canvas = document.createElement("canvas");
253
+ canvas.width = bitmap.width;
254
+ canvas.height = bitmap.height;
255
+ canvas.getContext("2d")?.drawImage(bitmap, 0, 0);
256
+ return new Promise((resolve, reject) => {
257
+ canvas.toBlob((png) => (png ? resolve(png) : reject(new Error("PNG conversion failed"))));
258
+ });
259
+ };
260
+
261
+ /** Copies the image itself (not a text placeholder) to the clipboard. */
262
+ const copyImageToClipboard = async (part: ImageContentPart): Promise<void> => {
263
+ if (Platform.OS === "web") {
264
+ if (typeof ClipboardItem === "undefined" || !navigator.clipboard?.write) {
265
+ console.warn("Copying images is not supported in this browser");
266
+ return;
267
+ }
268
+ const response = await fetch(part.url);
269
+ const png = await convertBlobToPng(await response.blob());
270
+ await navigator.clipboard.write([new ClipboardItem({"image/png": png})]);
271
+ return;
272
+ }
273
+ const Clipboard = await import("expo-clipboard");
274
+ const base64 = part.url.startsWith("data:") ? part.url.split(",")[1] : undefined;
275
+ if (base64) {
276
+ await Clipboard.setImageAsync(base64);
277
+ } else {
278
+ await Clipboard.setStringAsync(part.url);
279
+ }
280
+ };
281
+
282
+ const ImageActions = ({part}: {part: ImageContentPart}): React.ReactElement => {
283
+ const handleCopy = useCallback(async (): Promise<void> => {
284
+ try {
285
+ await copyImageToClipboard(part);
286
+ } catch (error) {
287
+ console.warn("Failed to copy image", error);
288
+ }
289
+ }, [part]);
290
+
291
+ const handleDownload = useCallback((): void => {
292
+ handleDownloadFile(part.url, getImageFilename(part));
293
+ }, [part]);
294
+
295
+ return (
296
+ <Box direction="row" gap={1} testID="gpt-image-actions">
297
+ <IconButton
298
+ accessibilityLabel="Copy image"
299
+ iconName="copy"
300
+ onClick={handleCopy}
301
+ testID="gpt-copy-image"
302
+ variant="ghost"
303
+ />
304
+ {Platform.OS === "web" ? (
305
+ <IconButton
306
+ accessibilityLabel="Download image"
307
+ iconName="download"
308
+ onClick={handleDownload}
309
+ testID="gpt-download-image"
310
+ variant="ghost"
311
+ />
312
+ ) : null}
313
+ </Box>
314
+ );
315
+ };
316
+
231
317
  const MessageContentParts = ({parts}: {parts: MessageContentPart[]}): React.ReactElement => {
232
318
  return (
233
319
  <Box gap={2}>
234
320
  {parts.map((part, index) => {
235
321
  if (part.type === "image") {
236
322
  return (
237
- <RNImage
238
- key={`content-${index}`}
239
- resizeMode="contain"
240
- source={{uri: part.url}}
241
- style={{borderRadius: 8, height: 400, maxWidth: 800, minWidth: 400, width: "100%"}}
242
- />
323
+ <Box gap={1} key={`content-${index}`}>
324
+ <RNImage
325
+ resizeMode="contain"
326
+ source={{uri: part.url}}
327
+ style={{borderRadius: 8, height: 400, maxWidth: 800, minWidth: 400, width: "100%"}}
328
+ />
329
+ <ImageActions part={part} />
330
+ </Box>
243
331
  );
244
332
  }
245
333
  if (part.type === "file") {
@@ -464,25 +552,44 @@ const HistoryItemTitle = ({
464
552
  );
465
553
  }
466
554
  return (
467
- <Text color={history.id === currentHistoryId ? "inverted" : "primary"} size="sm" truncate>
468
- {history.title ?? "New Chat"}
469
- </Text>
555
+ <Box flex="grow" minWidth={0}>
556
+ <Text color={history.id === currentHistoryId ? "inverted" : "primary"} size="sm" truncate>
557
+ {history.title ?? "New Chat"}
558
+ </Text>
559
+ </Box>
470
560
  );
471
561
  };
472
562
 
473
- const HistoryItemActionButton = ({
563
+ const HistoryItemActions = ({
474
564
  editingHistoryId,
475
565
  handleFinishRename,
476
566
  handleStartRename,
477
567
  history,
568
+ isSelected,
569
+ onDeleteHistory,
478
570
  onUpdateTitle,
479
571
  }: {
480
572
  editingHistoryId: string | null;
481
573
  handleFinishRename: () => void;
482
574
  handleStartRename: (id: string, title: string) => void;
483
575
  history: GPTChatHistory;
576
+ isSelected: boolean;
577
+ onDeleteHistory: (id: string) => void;
484
578
  onUpdateTitle?: (id: string, title: string) => void;
485
- }): React.ReactElement | null => {
579
+ }): React.ReactElement => {
580
+ const [isMenuOpen, setIsMenuOpen] = useState(false);
581
+ const title = history.title ?? "New Chat";
582
+
583
+ const handleRename = useCallback((): void => {
584
+ setIsMenuOpen(false);
585
+ handleStartRename(history.id, history.title ?? "");
586
+ }, [handleStartRename, history.id, history.title]);
587
+
588
+ const handleDelete = useCallback((): void => {
589
+ setIsMenuOpen(false);
590
+ onDeleteHistory(history.id);
591
+ }, [history.id, onDeleteHistory]);
592
+
486
593
  if (editingHistoryId === history.id) {
487
594
  return (
488
595
  <IconButton
@@ -493,16 +600,45 @@ const HistoryItemActionButton = ({
493
600
  />
494
601
  );
495
602
  }
496
- if (!onUpdateTitle) {
497
- return null;
498
- }
603
+
499
604
  return (
500
- <IconButton
501
- accessibilityLabel={`Rename chat: ${history.title ?? "New Chat"}`}
502
- iconName="pencil"
503
- onClick={() => handleStartRename(history.id, history.title ?? "")}
504
- testID={`gpt-rename-history-${history.id}`}
505
- />
605
+ <DropdownPanel
606
+ align="auto"
607
+ isOpen={isMenuOpen}
608
+ onOpenChange={setIsMenuOpen}
609
+ renderTrigger={({toggle}) => (
610
+ <IconButton
611
+ accessibilityLabel={`Chat actions: ${title}`}
612
+ iconName="ellipsis-vertical"
613
+ onClick={toggle}
614
+ testID={`gpt-history-menu-${history.id}`}
615
+ variant={isSelected ? "primary" : "ghost"}
616
+ />
617
+ )}
618
+ showActionButtons={false}
619
+ testID={`gpt-history-menu-panel-${history.id}`}
620
+ width={180}
621
+ >
622
+ <Box gap={1}>
623
+ {onUpdateTitle ? (
624
+ <DropdownMenuItem
625
+ accessibilityLabel={`Rename chat: ${title}`}
626
+ iconName="pen-to-square"
627
+ label="Rename"
628
+ onClick={handleRename}
629
+ testID={`gpt-rename-history-${history.id}`}
630
+ />
631
+ ) : null}
632
+ <DropdownMenuItem
633
+ accessibilityLabel={`Delete chat: ${title}`}
634
+ color="error"
635
+ iconName="trash-can"
636
+ label="Delete"
637
+ onClick={handleDelete}
638
+ testID={`gpt-delete-history-${history.id}`}
639
+ />
640
+ </Box>
641
+ </DropdownPanel>
506
642
  );
507
643
  };
508
644
 
@@ -569,7 +705,7 @@ const AssistantActions = ({
569
705
  message,
570
706
  onRateFeedback,
571
707
  }: {
572
- handleCopyMessage: (text: string) => void;
708
+ handleCopyMessage: (message: GPTChatMessage) => void;
573
709
  index: number;
574
710
  message: GPTChatMessage;
575
711
  onRateFeedback?: (promptIndex: number, rating: "up" | "down" | null) => void;
@@ -583,7 +719,7 @@ const AssistantActions = ({
583
719
  <IconButton
584
720
  accessibilityLabel="Copy message"
585
721
  iconName="copy"
586
- onClick={() => handleCopyMessage(message.content)}
722
+ onClick={() => handleCopyMessage(message)}
587
723
  testID={`gpt-copy-msg-${index}`}
588
724
  />
589
725
  </Box>
@@ -657,7 +793,7 @@ const MessageList = ({
657
793
  onRateFeedback,
658
794
  }: {
659
795
  currentMessages: GPTChatMessage[];
660
- handleCopyMessage: (text: string) => void;
796
+ handleCopyMessage: (message: GPTChatMessage) => void;
661
797
  onRateFeedback?: (promptIndex: number, rating: "up" | "down" | null) => void;
662
798
  }): React.ReactElement => {
663
799
  return (
@@ -858,6 +994,11 @@ const ApiKeyModal = ({
858
994
  // Main Component
859
995
  // ============================================================
860
996
 
997
+ /** Pixels of content below the viewport before "Scroll to bottom" appears. */
998
+ const SCROLL_TO_BOTTOM_THRESHOLD = 100;
999
+ /** Height the composer grows to before its text scrolls. */
1000
+ const COMPOSER_MAX_HEIGHT = 200;
1001
+
861
1002
  export const GPTChat = ({
862
1003
  attachments = [],
863
1004
  availableModels,
@@ -943,9 +1084,21 @@ export const GPTChat = ({
943
1084
  return () => el.removeEventListener("keydown", handler);
944
1085
  }, [inputElement]);
945
1086
 
946
- const handleCopyMessage = useCallback(async (text: string) => {
1087
+ // Image-only replies have no meaningful text, so copy the image instead of a placeholder.
1088
+ const handleCopyMessage = useCallback(async (message: GPTChatMessage) => {
1089
+ const firstImage = message.contentParts?.find(
1090
+ (part): part is ImageContentPart => part.type === "image"
1091
+ );
1092
+ if (firstImage && !message.content.trim()) {
1093
+ try {
1094
+ await copyImageToClipboard(firstImage);
1095
+ } catch (error) {
1096
+ console.warn("Failed to copy image", error);
1097
+ }
1098
+ return;
1099
+ }
947
1100
  const Clipboard = await import("expo-clipboard");
948
- await Clipboard.setStringAsync(text);
1101
+ await Clipboard.setStringAsync(message.content);
949
1102
  }, []);
950
1103
 
951
1104
  const scrollToBottom = useCallback(() => {
@@ -963,12 +1116,17 @@ export const GPTChat = ({
963
1116
  const handleScroll = useCallback((offsetY: number) => {
964
1117
  scrollOffsetRef.current = offsetY;
965
1118
  const distanceFromBottom = contentHeightRef.current - offsetY - viewportHeightRef.current;
966
- setIsScrolledUp(distanceFromBottom > 100);
1119
+ setIsScrolledUp(distanceFromBottom > SCROLL_TO_BOTTOM_THRESHOLD);
967
1120
  }, []);
968
1121
 
1122
+ // Growing content (a streaming reply) must not count as the user scrolling up, but content
1123
+ // that shrinks to fit the viewport (switching to a short or empty chat) clears the flag.
969
1124
  const handleContentLayout = useCallback(
970
- (_event: {nativeEvent: {layout: {height: number; width: number; x: number; y: number}}}) => {
971
- contentHeightRef.current = _event.nativeEvent.layout.height;
1125
+ (event: {nativeEvent: {layout: {height: number; width: number; x: number; y: number}}}) => {
1126
+ contentHeightRef.current = event.nativeEvent.layout.height;
1127
+ if (contentHeightRef.current <= viewportHeightRef.current + SCROLL_TO_BOTTOM_THRESHOLD) {
1128
+ setIsScrolledUp(false);
1129
+ }
972
1130
  },
973
1131
  []
974
1132
  );
@@ -1095,21 +1253,16 @@ export const GPTChat = ({
1095
1253
  history={history}
1096
1254
  setEditingTitle={setEditingTitle}
1097
1255
  />
1098
- <Box direction="row" gap={1}>
1099
- <HistoryItemActionButton
1256
+ <Box marginLeft={1}>
1257
+ <HistoryItemActions
1100
1258
  editingHistoryId={editingHistoryId}
1101
1259
  handleFinishRename={handleFinishRename}
1102
1260
  handleStartRename={handleStartRename}
1103
1261
  history={history}
1262
+ isSelected={history.id === currentHistoryId}
1263
+ onDeleteHistory={onDeleteHistory}
1104
1264
  onUpdateTitle={onUpdateTitle}
1105
1265
  />
1106
- <IconButton
1107
- accessibilityLabel={`Delete chat: ${history.title ?? "New Chat"}`}
1108
- iconName="trash"
1109
- onClick={() => onDeleteHistory(history.id)}
1110
- testID={`gpt-delete-history-${history.id}`}
1111
- variant="destructive"
1112
- />
1113
1266
  </Box>
1114
1267
  </Box>
1115
1268
  ))}
@@ -1143,7 +1296,10 @@ export const GPTChat = ({
1143
1296
  </Box>
1144
1297
  </Box>
1145
1298
 
1146
- <ScrollToBottomButton isScrolledUp={isScrolledUp} scrollToBottom={scrollToBottom} />
1299
+ <ScrollToBottomButton
1300
+ isScrolledUp={isScrolledUp && !isEmptyChat}
1301
+ scrollToBottom={scrollToBottom}
1302
+ />
1147
1303
  <AttachmentSection attachments={attachments} onRemoveAttachment={onRemoveAttachment} />
1148
1304
 
1149
1305
  {/* Input */}
@@ -1171,7 +1327,9 @@ export const GPTChat = ({
1171
1327
  <TextArea
1172
1328
  blurOnSubmit={false}
1173
1329
  disabled={isStreaming}
1330
+ grow
1174
1331
  inputRef={handleInputRef}
1332
+ maxHeight={COMPOSER_MAX_HEIGHT}
1175
1333
  onChange={setInputValue}
1176
1334
  placeholder="Type a message..."
1177
1335
  testID="gpt-input"
@@ -1,5 +1,6 @@
1
1
  import {describe, expect, it, spyOn} from "bun:test";
2
2
  import {act, fireEvent} from "@testing-library/react-native";
3
+ import {assert} from "chai";
3
4
  import {Linking} from "react-native";
4
5
 
5
6
  import {LineChart} from "./LineChart";
@@ -11,7 +12,110 @@ const POINTS = [
11
12
  {label: "C", value: 100},
12
13
  ];
13
14
 
15
+ const SERIES = [
16
+ {data: POINTS, id: "rank", label: "Search lost IS (rank)"},
17
+ {
18
+ data: POINTS.map((point) => ({...point, value: point.value / 2})),
19
+ id: "share",
20
+ label: "Search impr. share",
21
+ },
22
+ {
23
+ data: POINTS.map((point) => ({...point, value: point.value / 4})),
24
+ id: "budget",
25
+ label: "Search lost IS (budget)",
26
+ },
27
+ ];
28
+
14
29
  describe("LineChart", () => {
30
+ it("applies explicit tick rotation and chart-card header shortcuts", async (): Promise<void> => {
31
+ let pressCount = 0;
32
+ const {getByTestId, getByText} = renderWithTheme(
33
+ <LineChart
34
+ data={POINTS}
35
+ onPeriodPress={(): void => {
36
+ pressCount += 1;
37
+ }}
38
+ periodLabel="Last 30 days"
39
+ testID="chart"
40
+ title="Search share"
41
+ xTickPolicy="rotate"
42
+ />
43
+ );
44
+ const tickStyle = getByTestId("chart.xtick.0").props.style;
45
+ const tickStyles = Array.isArray(tickStyle) ? tickStyle : [tickStyle];
46
+
47
+ assert.isTrue(tickStyles.some((style) => Array.isArray(style?.transform)));
48
+ assert.exists(getByText("Search share"));
49
+ assert.exists(getByText("Last 30 days"));
50
+ fireEvent.press(getByTestId("chart.card.period-clickable"));
51
+ await new Promise((resolve) => setTimeout(resolve, 0));
52
+ assert.equal(pressCount, 1);
53
+ });
54
+
55
+ it("renders one path and legend item per named series", () => {
56
+ const {getByTestId, getByText} = renderWithTheme(
57
+ <LineChart data={[]} series={SERIES} testID="chart" />
58
+ );
59
+
60
+ for (let index = 0; index < SERIES.length; index += 1) {
61
+ assert.exists(getByTestId(`chart.series.${index}.path`));
62
+ assert.exists(getByTestId(`chart.series.${index}.marker.0`));
63
+ assert.exists(getByTestId(`chart.legend.${index}`));
64
+ assert.exists(getByTestId(`chart.legend.${index}.swatch`));
65
+ const legendStyle = getByTestId(`chart.legend.${index}.item`).props.style;
66
+ const legendStyles = Array.isArray(legendStyle) ? legendStyle : [legendStyle];
67
+ assert.isTrue(
68
+ legendStyles.some(
69
+ (style: {flexGrow?: number; minWidth?: number} | undefined) =>
70
+ style?.flexGrow === 1 && style.minWidth === 0
71
+ )
72
+ );
73
+ assert.exists(getByText(SERIES[index]?.label ?? ""));
74
+ }
75
+ assert.isBelow(
76
+ getByTestId("chart.series.0.marker.2").props.cy,
77
+ getByTestId("chart.series.2.marker.2").props.cy
78
+ );
79
+ });
80
+
81
+ it("identifies the active series in a multi-series tooltip", async (): Promise<void> => {
82
+ const {getByTestId, getByText} = renderWithTheme(
83
+ <LineChart data={[]} series={SERIES} testID="chart" />
84
+ );
85
+
86
+ await act(async () => {
87
+ fireEvent.press(getByTestId("chart.series.1.point.1-clickable"));
88
+ await new Promise((resolve) => setTimeout(resolve, 0));
89
+ });
90
+
91
+ assert.exists(getByText("Search impr. share — B: 25"));
92
+ });
93
+
94
+ it("renders a dotted comparison path on the shared scale", () => {
95
+ const {getByTestId} = renderWithTheme(
96
+ <LineChart comparisonData={POINTS} data={POINTS} testID="chart" />
97
+ );
98
+
99
+ assert.isString(getByTestId("chart.comparison").props.strokeDasharray);
100
+ });
101
+
102
+ it("renders comparison-only data instead of the empty state", () => {
103
+ const {getByTestId, queryByText} = renderWithTheme(
104
+ <LineChart comparisonData={POINTS} data={[]} testID="chart" />
105
+ );
106
+
107
+ assert.exists(getByTestId("chart.comparison"));
108
+ assert.notExists(queryByText("No data"));
109
+ });
110
+
111
+ it("shows the empty state when every named series is empty", () => {
112
+ const {getByText} = renderWithTheme(
113
+ <LineChart data={POINTS} series={[{data: [], id: "empty", label: "Empty"}]} />
114
+ );
115
+
116
+ assert.exists(getByText("No data"));
117
+ });
118
+
15
119
  it("renders one mark testID per point", () => {
16
120
  const {getByTestId, queryByTestId} = renderWithTheme(
17
121
  <LineChart data={POINTS} testID="chart" />