@oanda/labs-crowd-view-widget 1.0.47 → 1.0.48

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 (39) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/dist/main/CrowdViewWidget/Main.js +4 -2
  3. package/dist/main/CrowdViewWidget/Main.js.map +1 -1
  4. package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js +8 -3
  5. package/dist/main/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -1
  6. package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js +4 -1
  7. package/dist/main/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -1
  8. package/dist/main/CrowdViewWidget/components/Legend/Legend.js +4 -1
  9. package/dist/main/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
  10. package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js +4 -2
  11. package/dist/main/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
  12. package/dist/main/CrowdViewWidget/constants.js +9 -2
  13. package/dist/main/CrowdViewWidget/constants.js.map +1 -1
  14. package/dist/module/CrowdViewWidget/Main.js +4 -2
  15. package/dist/module/CrowdViewWidget/Main.js.map +1 -1
  16. package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js +9 -4
  17. package/dist/module/CrowdViewWidget/components/Chart/chartOptions.js.map +1 -1
  18. package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js +4 -1
  19. package/dist/module/CrowdViewWidget/components/Chart/utils/chartUtils.js.map +1 -1
  20. package/dist/module/CrowdViewWidget/components/Legend/Legend.js +4 -1
  21. package/dist/module/CrowdViewWidget/components/Legend/Legend.js.map +1 -1
  22. package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js +4 -2
  23. package/dist/module/CrowdViewWidget/components/Legend/LegendBar.js.map +1 -1
  24. package/dist/module/CrowdViewWidget/constants.js +9 -2
  25. package/dist/module/CrowdViewWidget/constants.js.map +1 -1
  26. package/dist/types/CrowdViewWidget/components/Chart/utils/chartUtils.d.ts +1 -1
  27. package/dist/types/CrowdViewWidget/components/Legend/Legend.d.ts +2 -1
  28. package/dist/types/CrowdViewWidget/components/Legend/LegendBar.d.ts +2 -1
  29. package/dist/types/CrowdViewWidget/constants.d.ts +8 -2
  30. package/package.json +3 -3
  31. package/src/CrowdViewWidget/Main.tsx +2 -2
  32. package/src/CrowdViewWidget/components/Chart/chartOptions.ts +15 -3
  33. package/src/CrowdViewWidget/components/Chart/utils/chartUtils.ts +11 -4
  34. package/src/CrowdViewWidget/components/Legend/Legend.tsx +4 -0
  35. package/src/CrowdViewWidget/components/Legend/LegendBar.tsx +4 -2
  36. package/src/CrowdViewWidget/constants.ts +10 -2
  37. package/test/components/Chart/utils/chartUtils.test.ts +23 -6
  38. package/test/components/Legend.test.tsx +44 -0
  39. package/test/components/LegendBar.test.tsx +73 -2
@@ -48,20 +48,37 @@ describe('chartUtils', () => {
48
48
  });
49
49
 
50
50
  describe('getRectColor', () => {
51
- it('uses long color scale for positive sentiment', () => {
52
- const color = getRectColor(BOOKS_THRESHOLDS.MAX);
51
+ it('uses long color scale for positive sentiment in light mode', () => {
52
+ const color = getRectColor(BOOKS_THRESHOLDS.MAX, false);
53
53
  expect(typeof color).toBe('string');
54
54
  // At max threshold, should be at or near target color
55
55
  expect(color.toLowerCase()).toContain(
56
- COLOR_MAP.long[1].slice(1).toLowerCase().substring(0, 3)
56
+ COLOR_MAP.light.long[1].slice(1).toLowerCase().substring(0, 3)
57
57
  );
58
58
  });
59
59
 
60
- it('uses short color scale for negative sentiment', () => {
61
- const color = getRectColor(-BOOKS_THRESHOLDS.MAX);
60
+ it('uses short color scale for negative sentiment in light mode', () => {
61
+ const color = getRectColor(-BOOKS_THRESHOLDS.MAX, false);
62
62
  expect(typeof color).toBe('string');
63
63
  expect(color.toLowerCase()).toContain(
64
- COLOR_MAP.short[1].slice(1).toLowerCase().substring(0, 3)
64
+ COLOR_MAP.light.short[1].slice(1).toLowerCase().substring(0, 3)
65
+ );
66
+ });
67
+
68
+ it('uses long color scale for positive sentiment in dark mode', () => {
69
+ const color = getRectColor(BOOKS_THRESHOLDS.MAX, true);
70
+ expect(typeof color).toBe('string');
71
+ // At max threshold, should be at or near target color
72
+ expect(color.toLowerCase()).toContain(
73
+ COLOR_MAP.dark.long[1].slice(1).toLowerCase().substring(0, 3)
74
+ );
75
+ });
76
+
77
+ it('uses short color scale for negative sentiment in dark mode', () => {
78
+ const color = getRectColor(-BOOKS_THRESHOLDS.MAX, true);
79
+ expect(typeof color).toBe('string');
80
+ expect(color.toLowerCase()).toContain(
81
+ COLOR_MAP.dark.short[1].slice(1).toLowerCase().substring(0, 3)
65
82
  );
66
83
  });
67
84
  });
@@ -6,6 +6,7 @@ import { render } from '@testing-library/react';
6
6
  import React from 'react';
7
7
 
8
8
  import { Legend } from '../../src/CrowdViewWidget/components';
9
+ import { COLOR_MAP } from '../../src/CrowdViewWidget/constants';
9
10
  import { BookType } from '../../src/gql/types/graphql';
10
11
 
11
12
  describe('Crowd View Widget', () => {
@@ -15,6 +16,7 @@ describe('Crowd View Widget', () => {
15
16
  const { getAllByText } = render(
16
17
  <Legend
17
18
  bookType={BookType.Position}
19
+ isDark={false}
18
20
  longValues={[0.15, 0.55]}
19
21
  shortValues={[0.15, 0.55]}
20
22
  />
@@ -23,6 +25,48 @@ describe('Crowd View Widget', () => {
23
25
  expect(getAllByText(/long/)).toHaveLength(1);
24
26
  expect(getAllByText(/short/)).toHaveLength(1);
25
27
  });
28
+
29
+ it('passes isDark prop to LegendBar components in light mode', () => {
30
+ const { getAllByTestId } = render(
31
+ <Legend
32
+ bookType={BookType.Position}
33
+ isDark={false}
34
+ longValues={[0.15, 0.55]}
35
+ shortValues={[0.15, 0.55]}
36
+ />
37
+ );
38
+ const segments = getAllByTestId('legend-bar-segment');
39
+ expect(segments.length).toBe(2);
40
+ // Check that segments use light mode colors (either long or short)
41
+ const styles = segments.map((segment) => segment.getAttribute('style'));
42
+ const hasLightColors = styles.some(
43
+ (style) =>
44
+ style?.includes(COLOR_MAP.light.long[0]) ||
45
+ style?.includes(COLOR_MAP.light.short[0])
46
+ );
47
+ expect(hasLightColors).toBe(true);
48
+ });
49
+
50
+ it('passes isDark prop to LegendBar components in dark mode', () => {
51
+ const { getAllByTestId } = render(
52
+ <Legend
53
+ bookType={BookType.Position}
54
+ isDark={true}
55
+ longValues={[0.15, 0.55]}
56
+ shortValues={[0.15, 0.55]}
57
+ />
58
+ );
59
+ const segments = getAllByTestId('legend-bar-segment');
60
+ expect(segments.length).toBe(2);
61
+ // Check that segments use dark mode colors (either long or short)
62
+ const styles = segments.map((segment) => segment.getAttribute('style'));
63
+ const hasDarkColors = styles.some(
64
+ (style) =>
65
+ style?.includes(COLOR_MAP.dark.long[0]) ||
66
+ style?.includes(COLOR_MAP.dark.short[0])
67
+ );
68
+ expect(hasDarkColors).toBe(true);
69
+ });
26
70
  });
27
71
  });
28
72
  });
@@ -6,6 +6,7 @@ import { render } from '@testing-library/react';
6
6
  import React from 'react';
7
7
 
8
8
  import { LegendBar } from '../../src/CrowdViewWidget/components';
9
+ import { COLOR_MAP } from '../../src/CrowdViewWidget/constants';
9
10
 
10
11
  describe('Crowd View Widget', () => {
11
12
  describe('components', () => {
@@ -14,7 +15,12 @@ describe('Crowd View Widget', () => {
14
15
 
15
16
  it('renders LegendBar with min and max values', () => {
16
17
  const { getByText } = render(
17
- <LegendBar label="long" type="long" values={mockValues} />
18
+ <LegendBar
19
+ isDark={false}
20
+ label="long"
21
+ type="long"
22
+ values={mockValues}
23
+ />
18
24
  );
19
25
 
20
26
  expect(getByText('long')).toBeInTheDocument();
@@ -24,11 +30,76 @@ describe('Crowd View Widget', () => {
24
30
 
25
31
  it('renders exactly 1 segment', () => {
26
32
  const { getAllByTestId } = render(
27
- <LegendBar label="short" type="short" values={mockValues} />
33
+ <LegendBar
34
+ isDark={false}
35
+ label="short"
36
+ type="short"
37
+ values={mockValues}
38
+ />
28
39
  );
29
40
  const segments = getAllByTestId('legend-bar-segment');
30
41
  expect(segments.length).toBe(1);
31
42
  });
43
+
44
+ it('uses light mode colors when isDark is false', () => {
45
+ const { getByTestId } = render(
46
+ <LegendBar
47
+ isDark={false}
48
+ label="long"
49
+ type="long"
50
+ values={mockValues}
51
+ />
52
+ );
53
+ const segment = getByTestId('legend-bar-segment');
54
+ const style = segment.getAttribute('style');
55
+ expect(style).toContain(COLOR_MAP.light.long[0]);
56
+ expect(style).toContain(COLOR_MAP.light.long[1]);
57
+ });
58
+
59
+ it('uses dark mode colors when isDark is true', () => {
60
+ const { getByTestId } = render(
61
+ <LegendBar
62
+ isDark={true}
63
+ label="long"
64
+ type="long"
65
+ values={mockValues}
66
+ />
67
+ );
68
+ const segment = getByTestId('legend-bar-segment');
69
+ const style = segment.getAttribute('style');
70
+ expect(style).toContain(COLOR_MAP.dark.long[0]);
71
+ expect(style).toContain(COLOR_MAP.dark.long[1]);
72
+ });
73
+
74
+ it('uses light mode short colors when isDark is false', () => {
75
+ const { getByTestId } = render(
76
+ <LegendBar
77
+ isDark={false}
78
+ label="short"
79
+ type="short"
80
+ values={mockValues}
81
+ />
82
+ );
83
+ const segment = getByTestId('legend-bar-segment');
84
+ const style = segment.getAttribute('style');
85
+ expect(style).toContain(COLOR_MAP.light.short[0]);
86
+ expect(style).toContain(COLOR_MAP.light.short[1]);
87
+ });
88
+
89
+ it('uses dark mode short colors when isDark is true', () => {
90
+ const { getByTestId } = render(
91
+ <LegendBar
92
+ isDark={true}
93
+ label="short"
94
+ type="short"
95
+ values={mockValues}
96
+ />
97
+ );
98
+ const segment = getByTestId('legend-bar-segment');
99
+ const style = segment.getAttribute('style');
100
+ expect(style).toContain(COLOR_MAP.dark.short[0]);
101
+ expect(style).toContain(COLOR_MAP.dark.short[1]);
102
+ });
32
103
  });
33
104
  });
34
105
  });