@hero-design/rn 8.99.4 → 8.100.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 (121) hide show
  1. package/.turbo/turbo-build.log +8 -3
  2. package/CHANGELOG.md +17 -0
  3. package/es/index.js +5621 -690
  4. package/jest.config.js +1 -1
  5. package/lib/index.js +5545 -613
  6. package/package.json +4 -2
  7. package/src/components/Avatar/AvatarStack/utils.ts +6 -4
  8. package/src/components/Badge/Status.tsx +1 -1
  9. package/src/components/Badge/__tests__/Status.spec.tsx +20 -0
  10. package/src/components/Badge/__tests__/__snapshots__/Status.spec.tsx.snap +2 -0
  11. package/src/components/Chart/ChartSelect/StyledChartSelect.tsx +9 -0
  12. package/src/components/Chart/ChartSelect/__tests__/StyledChartSelect.spec.tsx +15 -0
  13. package/src/components/Chart/ChartSelect/__tests__/__snapshots__/StyledChartSelect.spec.tsx.snap +20 -0
  14. package/src/components/Chart/ChartSelect/__tests__/index.spec.tsx +111 -0
  15. package/src/components/Chart/ChartSelect/index.tsx +137 -0
  16. package/src/components/Chart/ColumnChart/ColumnChartContent.tsx +84 -0
  17. package/src/components/Chart/ColumnChart/Segment.tsx +66 -0
  18. package/src/components/Chart/ColumnChart/StackedSegment.tsx +99 -0
  19. package/src/components/Chart/ColumnChart/StyledColumnChart.tsx +9 -0
  20. package/src/components/Chart/ColumnChart/__tests__/ColumnChartContent.spec.tsx +68 -0
  21. package/src/components/Chart/ColumnChart/__tests__/Segment.spec.tsx +99 -0
  22. package/src/components/Chart/ColumnChart/__tests__/StackedSegment.spec.tsx +115 -0
  23. package/src/components/Chart/ColumnChart/__tests__/__snapshots__/StackedSegment.spec.tsx.snap +120 -0
  24. package/src/components/Chart/ColumnChart/__tests__/__snapshots__/index.spec.tsx.snap +1405 -0
  25. package/src/components/Chart/ColumnChart/__tests__/index.spec.tsx +134 -0
  26. package/src/components/Chart/ColumnChart/index.tsx +216 -0
  27. package/src/components/Chart/Line/Line.tsx +81 -0
  28. package/src/components/Chart/Line/__tests__/Line.spec.tsx +148 -0
  29. package/src/components/Chart/Line/__tests__/__snapshots__/Line.spec.tsx.snap +56 -0
  30. package/src/components/Chart/Line/__tests__/__snapshots__/index.spec.tsx.snap +1461 -0
  31. package/src/components/Chart/Line/__tests__/index.spec.tsx +112 -0
  32. package/src/components/Chart/Line/index.tsx +143 -0
  33. package/src/components/Chart/StyledChart.tsx +16 -0
  34. package/src/components/Chart/index.tsx +13 -0
  35. package/src/components/Chart/shared/AxisLabel.tsx +25 -0
  36. package/src/components/Chart/shared/ChartFrame.tsx +131 -0
  37. package/src/components/Chart/shared/ChartHeader.tsx +19 -0
  38. package/src/components/Chart/shared/EmptyState.tsx +83 -0
  39. package/src/components/Chart/shared/XAxis.tsx +69 -0
  40. package/src/components/Chart/shared/XAxisGrid.tsx +42 -0
  41. package/src/components/Chart/shared/YAxis.tsx +104 -0
  42. package/src/components/Chart/shared/YAxisGrid.tsx +58 -0
  43. package/src/components/Chart/shared/__tests__/ChartFrame.spec.tsx +125 -0
  44. package/src/components/Chart/shared/__tests__/ChartHeader.spec.tsx +22 -0
  45. package/src/components/Chart/shared/__tests__/EmptyState.spec.tsx +29 -0
  46. package/src/components/Chart/shared/__tests__/XAXisGrid.spec.tsx +30 -0
  47. package/src/components/Chart/shared/__tests__/XAxis.spec.tsx +42 -0
  48. package/src/components/Chart/shared/__tests__/YAxis.spec.tsx +72 -0
  49. package/src/components/Chart/shared/__tests__/YAxisGrid.spec.tsx +35 -0
  50. package/src/components/Chart/shared/__tests__/__snapshots__/ChartFrame.spec.tsx.snap +3058 -0
  51. package/src/components/Chart/shared/__tests__/__snapshots__/ChartHeader.spec.tsx.snap +160 -0
  52. package/src/components/Chart/shared/__tests__/__snapshots__/EmptyState.spec.tsx.snap +155 -0
  53. package/src/components/Chart/shared/__tests__/__snapshots__/XAXisGrid.spec.tsx.snap +197 -0
  54. package/src/components/Chart/shared/__tests__/__snapshots__/XAxis.spec.tsx.snap +369 -0
  55. package/src/components/Chart/shared/__tests__/__snapshots__/YAxis.spec.tsx.snap +1013 -0
  56. package/src/components/Chart/shared/__tests__/__snapshots__/YAxisGrid.spec.tsx.snap +228 -0
  57. package/src/components/Chart/shared/__tests__/niceNumbers.spec.tsx +127 -0
  58. package/src/components/Chart/shared/constants.ts +2 -0
  59. package/src/components/Chart/shared/hooks/useColorScale.ts +25 -0
  60. package/src/components/Chart/shared/hooks/useGenerateTicks.ts +27 -0
  61. package/src/components/Chart/shared/hooks/useScaleBandX.ts +17 -0
  62. package/src/components/Chart/shared/hooks/useScaleLinearY.ts +30 -0
  63. package/src/components/Chart/shared/niceNumbers.ts +68 -0
  64. package/src/components/Chart/types.ts +100 -0
  65. package/src/components/Select/MultiSelect/OptionList.tsx +1 -1
  66. package/src/components/Select/MultiSelect/index.tsx +2 -6
  67. package/src/components/Select/MultiSelect/utils.ts +1 -1
  68. package/src/components/Select/SingleSelect/OptionList.tsx +1 -1
  69. package/src/components/Select/SingleSelect/index.tsx +2 -7
  70. package/src/components/Select/__tests__/helpers.spec.tsx +0 -36
  71. package/src/components/Select/helpers.tsx +0 -75
  72. package/src/components/Switch/SelectorSwitch/__tests__/__snapshots__/Option.spec.tsx.snap +3 -0
  73. package/src/components/Switch/SelectorSwitch/__tests__/__snapshots__/index.spec.tsx.snap +1 -0
  74. package/src/components/Tabs/__tests__/__snapshots__/ScrollableTabs.spec.tsx.snap +3 -0
  75. package/src/components/Tabs/__tests__/__snapshots__/ScrollableTabsHeader.spec.tsx.snap +2 -0
  76. package/src/components/Tabs/__tests__/__snapshots__/TabWithBadge.spec.tsx.snap +1 -0
  77. package/src/components/Tabs/__tests__/__snapshots__/index.spec.tsx.snap +3 -0
  78. package/src/index.ts +2 -0
  79. package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +28 -0
  80. package/src/theme/components/chart.ts +28 -0
  81. package/src/theme/components/columnChart.ts +15 -0
  82. package/src/theme/getTheme.ts +6 -0
  83. package/src/types.ts +4 -0
  84. package/src/utils/__tests__/helpers.spec.ts +36 -1
  85. package/src/utils/helpers.ts +76 -1
  86. package/stats/8.100.0/rn-stats.html +4842 -0
  87. package/stats/8.99.4/rn-stats.html +1 -1
  88. package/types/components/Badge/Status.d.ts +0 -1
  89. package/types/components/Chart/ChartSelect/StyledChartSelect.d.ts +8 -0
  90. package/types/components/Chart/ChartSelect/index.d.ts +63 -0
  91. package/types/components/Chart/ColumnChart/ColumnChartContent.d.ts +25 -0
  92. package/types/components/Chart/ColumnChart/Segment.d.ts +14 -0
  93. package/types/components/Chart/ColumnChart/StackedSegment.d.ts +28 -0
  94. package/types/components/Chart/ColumnChart/StyledColumnChart.d.ts +8 -0
  95. package/types/components/Chart/ColumnChart/index.d.ts +80 -0
  96. package/types/components/Chart/Line/Line.d.ts +21 -0
  97. package/types/components/Chart/Line/index.d.ts +35 -0
  98. package/types/components/Chart/StyledChart.d.ts +9 -0
  99. package/types/components/Chart/index.d.ts +9 -0
  100. package/types/components/Chart/shared/AxisLabel.d.ts +7 -0
  101. package/types/components/Chart/shared/ChartFrame.d.ts +30 -0
  102. package/types/components/Chart/shared/ChartHeader.d.ts +8 -0
  103. package/types/components/Chart/shared/EmptyState.d.ts +8 -0
  104. package/types/components/Chart/shared/XAxis.d.ts +8 -0
  105. package/types/components/Chart/shared/XAxisGrid.d.ts +8 -0
  106. package/types/components/Chart/shared/YAxis.d.ts +10 -0
  107. package/types/components/Chart/shared/YAxisGrid.d.ts +10 -0
  108. package/types/components/Chart/shared/constants.d.ts +2 -0
  109. package/types/components/Chart/shared/hooks/useColorScale.d.ts +7 -0
  110. package/types/components/Chart/shared/hooks/useGenerateTicks.d.ts +6 -0
  111. package/types/components/Chart/shared/hooks/useScaleBandX.d.ts +8 -0
  112. package/types/components/Chart/shared/hooks/useScaleLinearY.d.ts +9 -0
  113. package/types/components/Chart/shared/niceNumbers.d.ts +12 -0
  114. package/types/components/Chart/types.d.ts +84 -0
  115. package/types/components/Select/helpers.d.ts +0 -5
  116. package/types/index.d.ts +2 -1
  117. package/types/theme/components/chart.d.ts +22 -0
  118. package/types/theme/components/columnChart.d.ts +10 -0
  119. package/types/theme/getTheme.d.ts +4 -0
  120. package/types/types.d.ts +3 -1
  121. package/types/utils/helpers.d.ts +5 -0
@@ -0,0 +1,104 @@
1
+ import React, { useMemo } from 'react';
2
+ import { Platform } from 'react-native';
3
+ import { ForeignObject, G } from 'react-native-svg';
4
+ import { useTheme } from '../../../theme';
5
+ import Box from '../../Box';
6
+ import { AxisCoordinates, YAxisConfig } from '../types';
7
+ import AxisLabel from './AxisLabel';
8
+ import useGenerateTicks from './hooks/useGenerateTicks';
9
+ import useScaleLinearY from './hooks/useScaleLinearY';
10
+
11
+ export type YAxisProps = {
12
+ yAxisConfig: YAxisConfig & { minValue?: number };
13
+ coordinates: AxisCoordinates;
14
+ };
15
+
16
+ const YAxis = ({ yAxisConfig, coordinates }: YAxisProps) => {
17
+ const theme = useTheme();
18
+ const { maxValue, minValue, step, labels } = yAxisConfig;
19
+ const { yStart, yEnd, xEnd, xStart } = coordinates;
20
+ const { yAxisDefaultTextWidth } = theme.__hd__.chart.sizes;
21
+
22
+ // Whether to use custom labels instead of generated ticks
23
+ const shouldUseCustomLabels = labels && labels.length > 0;
24
+
25
+ const maxValueOrZero = maxValue || 0;
26
+ const minValueOrZero = minValue || 0;
27
+
28
+ // Adjust scaleY to fit within the chart area, leaving space for the bottom space for the X axis
29
+ const scaleY = useScaleLinearY({
30
+ maxValue: maxValueOrZero,
31
+ minValue: minValueOrZero,
32
+ yStart,
33
+ yEnd,
34
+ });
35
+
36
+ // Generate ticks, including maxValue if needed
37
+ const ticks = useGenerateTicks({
38
+ maxValue: maxValueOrZero,
39
+ minValue: minValueOrZero,
40
+ step,
41
+ });
42
+
43
+ const data = useMemo(
44
+ () =>
45
+ ticks.map((tick, index) => {
46
+ if (shouldUseCustomLabels) {
47
+ return { tick, label: labels[index] };
48
+ }
49
+ return {
50
+ tick,
51
+ label: Number.isInteger(tick)
52
+ ? tick.toString()
53
+ : Number(tick).toFixed(2),
54
+ };
55
+ }),
56
+ [ticks, shouldUseCustomLabels, labels]
57
+ );
58
+
59
+ return (
60
+ <G>
61
+ {data.map(({ label, tick }) => (
62
+ <G key={label}>
63
+ {/*
64
+ Cross-platform Y-axis label rendering:
65
+ - On web: Use ForeignObject to allow HTML/CSS styling and ellipsis with Typography.Label.
66
+ The x position is set to xStart - yAxisDefaultTextWidth to right-align the label box.
67
+ - On native: Use Box with absolute positioning and Typography.Label for compatibility.
68
+ The transform centers the label vertically.
69
+ */}
70
+ {Platform.OS === 'web' ? (
71
+ <ForeignObject
72
+ x={xStart - yAxisDefaultTextWidth}
73
+ y={scaleY(tick) - theme.__hd__.typography.lineHeights.label / 2}
74
+ width={yAxisDefaultTextWidth}
75
+ height={theme.__hd__.typography.lineHeights.label}
76
+ >
77
+ <AxisLabel label={label} />
78
+ </ForeignObject>
79
+ ) : (
80
+ <Box
81
+ testID={`y-axis-label-${tick}-container`}
82
+ style={{
83
+ position: 'absolute',
84
+ maxWidth: yAxisDefaultTextWidth,
85
+ top: scaleY(tick),
86
+ transform: [
87
+ {
88
+ translateY:
89
+ 0 - theme.__hd__.typography.lineHeights.label / 2, // center label vertically
90
+ },
91
+ ],
92
+ right: xEnd - yAxisDefaultTextWidth,
93
+ }}
94
+ >
95
+ <AxisLabel label={label} />
96
+ </Box>
97
+ )}
98
+ </G>
99
+ ))}
100
+ </G>
101
+ );
102
+ };
103
+
104
+ export default YAxis;
@@ -0,0 +1,58 @@
1
+ import React from 'react';
2
+ import { G, Line } from 'react-native-svg';
3
+ import { useTheme } from '../../../theme';
4
+ import { AxisCoordinates, YAxisConfig } from '../types';
5
+ import { DASH_ARRAY } from './constants';
6
+ import useGenerateTicks from './hooks/useGenerateTicks';
7
+ import useScaleLinearY from './hooks/useScaleLinearY';
8
+
9
+ export type YAxisGridProps = {
10
+ yAxisConfig: Omit<YAxisConfig, 'labels'> & { minValue?: number };
11
+ coordinates: AxisCoordinates;
12
+ };
13
+
14
+ const YAxisGrid = ({ yAxisConfig, coordinates }: YAxisGridProps) => {
15
+ const theme = useTheme();
16
+ const { maxValue, minValue, step, tick } = yAxisConfig;
17
+ const { xStart, xEnd, yStart, yEnd } = coordinates;
18
+ const {
19
+ colors: { gridStroke },
20
+ } = theme.__hd__.chart;
21
+
22
+ const maxValueOrZero = maxValue || 0;
23
+ const minValueOrZero = minValue || 0;
24
+
25
+ const scaleY = useScaleLinearY({
26
+ maxValue: maxValueOrZero,
27
+ minValue: minValueOrZero,
28
+ yStart,
29
+ yEnd,
30
+ });
31
+
32
+ const tickInterval = tick?.interval || step;
33
+
34
+ const ticks = useGenerateTicks({
35
+ maxValue: maxValueOrZero,
36
+ minValue: minValueOrZero,
37
+ step: tickInterval,
38
+ });
39
+
40
+ return (
41
+ <G testID="y-axis-grid">
42
+ {ticks.map((value) => (
43
+ <Line
44
+ testID={`y-axis-grid-${value}`}
45
+ key={value}
46
+ x1={xStart}
47
+ y1={scaleY(value)}
48
+ x2={xEnd}
49
+ y2={scaleY(value)}
50
+ stroke={gridStroke}
51
+ strokeDasharray={DASH_ARRAY}
52
+ />
53
+ ))}
54
+ </G>
55
+ );
56
+ };
57
+
58
+ export default YAxisGrid;
@@ -0,0 +1,125 @@
1
+ import { fireEvent } from '@testing-library/react-native';
2
+ import React from 'react';
3
+ import { Button, Typography } from '../../../..';
4
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
5
+ import ChartFrame, { ChartFrameProps } from '../ChartFrame';
6
+
7
+ const onButtonPress = jest.fn();
8
+
9
+ const chartFrameProps: ChartFrameProps = {
10
+ xAxisConfig: {
11
+ labels: ['May 2025', 'Jun 2025', 'Jul 2025', 'Aug 2025'],
12
+ },
13
+ yAxisConfig: {
14
+ labels: ['$0', '$20', '$40', '$60', '$80'],
15
+ maxValue: 80,
16
+ step: 20,
17
+ },
18
+ width: 100,
19
+ height: 100,
20
+ headerConfig: {
21
+ title: 'Chart title',
22
+ actionsExtra: <Button text="Button" onPress={onButtonPress} />,
23
+ },
24
+ renderContent: () => <Typography.Body>Chart content</Typography.Body>,
25
+ };
26
+
27
+ describe('ChartFrame', () => {
28
+ it('should render correctly', () => {
29
+ const { toJSON, getByText, getByTestId } = renderWithTheme(
30
+ <ChartFrame {...chartFrameProps} />
31
+ );
32
+
33
+ expect(toJSON()).toMatchSnapshot();
34
+
35
+ // Chart header
36
+ expect(getByText('Chart title')).toBeVisible();
37
+ expect(getByText('Button')).toBeVisible();
38
+ fireEvent.press(getByText('Button'));
39
+ expect(onButtonPress).toHaveBeenCalled();
40
+
41
+ // Y Axis labels
42
+ expect(getByText('$0')).toBeVisible();
43
+ expect(getByText('$20')).toBeVisible();
44
+ expect(getByText('$40')).toBeVisible();
45
+ expect(getByText('$60')).toBeVisible();
46
+ expect(getByText('$80')).toBeVisible();
47
+
48
+ // Y Axis grid
49
+ expect(getByTestId('y-axis-grid')).toBeVisible();
50
+
51
+ // X Axis labels
52
+ expect(getByText('May 2025')).toBeVisible();
53
+ expect(getByText('Jun 2025')).toBeVisible();
54
+ expect(getByText('Jul 2025')).toBeVisible();
55
+ expect(getByText('Aug 2025')).toBeVisible();
56
+
57
+ // X Axis grid
58
+ expect(getByTestId('x-axis-grid')).toBeVisible();
59
+
60
+ // Chart content
61
+ expect(getByText('Chart content')).toBeVisible();
62
+ });
63
+
64
+ it('should render empty state when data is empty', () => {
65
+ const { toJSON, getByText, queryByText } = renderWithTheme(
66
+ <ChartFrame {...chartFrameProps} isEmpty emptyText="NO RECENT DATA" />
67
+ );
68
+
69
+ expect(toJSON()).toMatchSnapshot();
70
+
71
+ // Empty state
72
+ expect(getByText('NO RECENT DATA')).toBeVisible();
73
+ expect(queryByText('Chart content')).toBeNull();
74
+
75
+ // Y Axis labels
76
+ expect(getByText('$0')).toBeVisible();
77
+ expect(getByText('$20')).toBeVisible();
78
+ expect(getByText('$40')).toBeVisible();
79
+ expect(getByText('$60')).toBeVisible();
80
+ expect(getByText('$80')).toBeVisible();
81
+
82
+ // X Axis labels
83
+ expect(getByText('May 2025')).toBeVisible();
84
+ expect(getByText('Jun 2025')).toBeVisible();
85
+ expect(getByText('Jul 2025')).toBeVisible();
86
+ expect(getByText('Aug 2025')).toBeVisible();
87
+ });
88
+
89
+ it('should not render empty state when emptyText is provided', () => {
90
+ const { toJSON, getByText, queryByText } = renderWithTheme(
91
+ <ChartFrame {...chartFrameProps} isEmpty />
92
+ );
93
+
94
+ expect(toJSON()).toMatchSnapshot();
95
+
96
+ expect(queryByText('Chart content')).toBeNull();
97
+
98
+ // Y Axis labels
99
+ expect(getByText('$0')).toBeVisible();
100
+ expect(getByText('$20')).toBeVisible();
101
+ expect(getByText('$40')).toBeVisible();
102
+ expect(getByText('$60')).toBeVisible();
103
+ expect(getByText('$80')).toBeVisible();
104
+
105
+ // X Axis labels
106
+ expect(getByText('May 2025')).toBeVisible();
107
+ expect(getByText('Jun 2025')).toBeVisible();
108
+ expect(getByText('Jul 2025')).toBeVisible();
109
+ expect(getByText('Aug 2025')).toBeVisible();
110
+ });
111
+
112
+ it('should not render X Axis grid when hideXAxisGrid is true', () => {
113
+ const { queryByTestId } = renderWithTheme(
114
+ <ChartFrame {...chartFrameProps} hideXAxisGrid />
115
+ );
116
+ expect(queryByTestId('x-axis-grid')).toBeNull();
117
+ });
118
+
119
+ it('should not render Y Axis grid when hideYAxisGrid is true', () => {
120
+ const { queryByTestId } = renderWithTheme(
121
+ <ChartFrame {...chartFrameProps} hideYAxisGrid />
122
+ );
123
+ expect(queryByTestId('y-axis-grid')).toBeNull();
124
+ });
125
+ });
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { fireEvent } from '@testing-library/react-native';
3
+ import { Button } from '../../../..';
4
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
5
+ import ChartHeader from '../ChartHeader';
6
+
7
+ describe('ChartHeader', () => {
8
+ it('should render correctly', () => {
9
+ const onPress = jest.fn();
10
+ const { toJSON, getByText } = renderWithTheme(
11
+ <ChartHeader
12
+ title="Chart title"
13
+ actionsExtra={<Button onPress={onPress} text="Button" />}
14
+ />
15
+ );
16
+
17
+ expect(toJSON()).toMatchSnapshot();
18
+
19
+ fireEvent.press(getByText('Button'));
20
+ expect(onPress).toHaveBeenCalled();
21
+ });
22
+ });
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import EmptyState from '../EmptyState';
3
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
4
+
5
+ describe('EmptyState', () => {
6
+ it('should render', () => {
7
+ const { getByText, toJSON } = renderWithTheme(
8
+ <EmptyState
9
+ coordinates={{ xStart: 50, xEnd: 300, yStart: 50, yEnd: 300 }}
10
+ content="No data"
11
+ />
12
+ );
13
+
14
+ expect(toJSON()).toMatchSnapshot();
15
+ expect(getByText('No data')).toBeVisible();
16
+ });
17
+
18
+ it('renders correctly on web', () => {
19
+ const { getByText, toJSON } = renderWithTheme(
20
+ <EmptyState
21
+ coordinates={{ xStart: 50, xEnd: 300, yStart: 50, yEnd: 300 }}
22
+ content="No data"
23
+ />
24
+ );
25
+
26
+ expect(toJSON()).toMatchSnapshot();
27
+ expect(getByText('No data')).toBeVisible();
28
+ });
29
+ });
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
3
+ import XAxisGrid, { XAxisGridProps } from '../XAxisGrid';
4
+
5
+ const xAxisGridProps: XAxisGridProps = {
6
+ xAxisConfig: {
7
+ labels: ['1', '2', '3', '4', '5'],
8
+ },
9
+ coordinates: {
10
+ xStart: 0,
11
+ xEnd: 100,
12
+ yStart: 0,
13
+ yEnd: 100,
14
+ },
15
+ };
16
+
17
+ describe('XAxisGrid', () => {
18
+ it('should render correctly', () => {
19
+ const { toJSON, getByTestId } = renderWithTheme(
20
+ <XAxisGrid {...xAxisGridProps} />
21
+ );
22
+ expect(toJSON()).toMatchSnapshot();
23
+
24
+ expect(getByTestId('x-axis-grid-1')).toBeVisible();
25
+ expect(getByTestId('x-axis-grid-2')).toBeVisible();
26
+ expect(getByTestId('x-axis-grid-3')).toBeVisible();
27
+ expect(getByTestId('x-axis-grid-4')).toBeVisible();
28
+ expect(getByTestId('x-axis-grid-5')).toBeVisible();
29
+ });
30
+ });
@@ -0,0 +1,42 @@
1
+ import React from 'react';
2
+ import { Platform } from 'react-native';
3
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
4
+ import XAxis, { XAxisProps } from '../XAxis';
5
+
6
+ const mockXAxisProps: XAxisProps = {
7
+ xAxisConfig: {
8
+ labels: ['Label 1', 'Label 2', 'Label 3'],
9
+ },
10
+ coordinates: {
11
+ xStart: 0,
12
+ xEnd: 100,
13
+ yStart: 0,
14
+ yEnd: 100,
15
+ },
16
+ };
17
+
18
+ describe('XAxis', () => {
19
+ it('should render correctly', () => {
20
+ const { getByText, toJSON } = renderWithTheme(
21
+ <XAxis {...mockXAxisProps} />
22
+ );
23
+
24
+ expect(toJSON()).toMatchSnapshot();
25
+ expect(getByText('Label 1')).toBeVisible();
26
+ expect(getByText('Label 2')).toBeVisible();
27
+ expect(getByText('Label 3')).toBeVisible();
28
+ });
29
+
30
+ it('renders correctly on web', () => {
31
+ Platform.OS = 'web';
32
+
33
+ const { getByText, toJSON } = renderWithTheme(
34
+ <XAxis {...mockXAxisProps} />
35
+ );
36
+
37
+ expect(toJSON()).toMatchSnapshot();
38
+ expect(getByText('Label 1')).toBeVisible();
39
+ expect(getByText('Label 2')).toBeVisible();
40
+ expect(getByText('Label 3')).toBeVisible();
41
+ });
42
+ });
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+ import { Platform } from 'react-native';
3
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
4
+ import YAxis, { YAxisProps } from '../YAxis';
5
+
6
+ const mockYAxisProps: YAxisProps = {
7
+ yAxisConfig: {
8
+ maxValue: 100,
9
+ step: 20,
10
+ },
11
+ coordinates: {
12
+ xStart: 0,
13
+ xEnd: 100,
14
+ yStart: 0,
15
+ yEnd: 100,
16
+ },
17
+ };
18
+
19
+ const mockYAxisConfigWithLabels: YAxisProps = {
20
+ yAxisConfig: {
21
+ maxValue: 100,
22
+ step: 20,
23
+ labels: ['Label 1', 'Label 2', 'Label 3', 'Label 4', 'Label 5'],
24
+ },
25
+ coordinates: {
26
+ xStart: 0,
27
+ xEnd: 100,
28
+ yStart: 0,
29
+ yEnd: 100,
30
+ },
31
+ };
32
+
33
+ describe('YAxis', () => {
34
+ it('should render correctly', () => {
35
+ const { getByText, toJSON } = renderWithTheme(
36
+ <YAxis {...mockYAxisProps} />
37
+ );
38
+ expect(toJSON()).toMatchSnapshot();
39
+ expect(getByText('20')).toBeVisible();
40
+ expect(getByText('40')).toBeVisible();
41
+ expect(getByText('60')).toBeVisible();
42
+ expect(getByText('80')).toBeVisible();
43
+ expect(getByText('100')).toBeVisible();
44
+ });
45
+
46
+ it('should render correctly with labels', () => {
47
+ const { getByText, toJSON } = renderWithTheme(
48
+ <YAxis {...mockYAxisConfigWithLabels} />
49
+ );
50
+ expect(toJSON()).toMatchSnapshot();
51
+ expect(getByText('Label 1')).toBeVisible();
52
+ expect(getByText('Label 2')).toBeVisible();
53
+ expect(getByText('Label 3')).toBeVisible();
54
+ expect(getByText('Label 4')).toBeVisible();
55
+ expect(getByText('Label 5')).toBeVisible();
56
+ });
57
+
58
+ it('renders correctly on web', () => {
59
+ Platform.OS = 'web';
60
+
61
+ const { getByText, toJSON } = renderWithTheme(
62
+ <YAxis {...mockYAxisProps} />
63
+ );
64
+
65
+ expect(toJSON()).toMatchSnapshot();
66
+ expect(getByText('20')).toBeVisible();
67
+ expect(getByText('40')).toBeVisible();
68
+ expect(getByText('60')).toBeVisible();
69
+ expect(getByText('80')).toBeVisible();
70
+ expect(getByText('100')).toBeVisible();
71
+ });
72
+ });
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import renderWithTheme from '../../../../testHelpers/renderWithTheme';
3
+ import YAxisGrid, { YAxisGridProps } from '../YAxisGrid';
4
+
5
+ const yAxisGridProps: YAxisGridProps = {
6
+ yAxisConfig: {
7
+ maxValue: 10000,
8
+ step: 5000,
9
+ tick: {
10
+ interval: 2000,
11
+ },
12
+ },
13
+ coordinates: {
14
+ xStart: 0,
15
+ xEnd: 100,
16
+ yStart: 0,
17
+ yEnd: 100,
18
+ },
19
+ };
20
+
21
+ describe('YAxisGrid', () => {
22
+ it('should render correctly', () => {
23
+ const { toJSON, getByTestId } = renderWithTheme(
24
+ <YAxisGrid {...yAxisGridProps} />
25
+ );
26
+ expect(toJSON()).toMatchSnapshot();
27
+
28
+ expect(getByTestId('y-axis-grid-0')).toBeVisible();
29
+ expect(getByTestId('y-axis-grid-2000')).toBeVisible();
30
+ expect(getByTestId('y-axis-grid-4000')).toBeVisible();
31
+ expect(getByTestId('y-axis-grid-6000')).toBeVisible();
32
+ expect(getByTestId('y-axis-grid-8000')).toBeVisible();
33
+ expect(getByTestId('y-axis-grid-10000')).toBeVisible();
34
+ });
35
+ });