@times-components/ts-components 1.145.1-cfea81c4084e6f91221ea00fec9fc730d5b933cb.4 → 1.145.1-d1253ed8e87e7cdf861fbf772a5f9026182434db.4

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 (136) hide show
  1. package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.js +10 -2
  2. package/dist/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.js +94 -17
  3. package/dist/components/opta/football/summary/OptaFootballSummary.js +10 -2
  4. package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +95 -18
  5. package/dist/components/opta/rugby/summary/OptaRugbySummary.js +10 -2
  6. package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +94 -17
  7. package/dist/components/opta/utils/__tests__/emitEvent.test.js +264 -0
  8. package/dist/components/opta/utils/emitEvent.d.ts +1 -0
  9. package/dist/components/opta/utils/emitEvent.js +15 -0
  10. package/dist/index.d.ts +0 -1
  11. package/dist/index.js +1 -2
  12. package/package.json +3 -3
  13. package/rnw.js +1 -1
  14. package/src/components/opta/cricket/scorecard/OptaCricketScorecard.tsx +13 -0
  15. package/src/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.tsx +126 -16
  16. package/src/components/opta/cricket/scorecard/__tests__/__snapshots__/OptaCricketScorecard.test.tsx.snap +5 -6
  17. package/src/components/opta/football/summary/OptaFootballSummary.tsx +13 -0
  18. package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +127 -18
  19. package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +5 -6
  20. package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +13 -0
  21. package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +127 -17
  22. package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +5 -6
  23. package/src/components/opta/utils/__tests__/emitEvent.test.tsx +415 -0
  24. package/src/components/opta/utils/emitEvent.ts +20 -0
  25. package/src/index.ts +0 -2
  26. package/dist/components/carousel-component/CarouselComponent.stories.js +0 -146
  27. package/dist/components/carousel-component/CarouselItem.d.ts +0 -3
  28. package/dist/components/carousel-component/CarouselItem.js +0 -11
  29. package/dist/components/carousel-component/DefaultNavigationArrow.d.ts +0 -8
  30. package/dist/components/carousel-component/DefaultNavigationArrow.js +0 -6
  31. package/dist/components/carousel-component/DefaultPageDot.d.ts +0 -8
  32. package/dist/components/carousel-component/DefaultPageDot.js +0 -4
  33. package/dist/components/carousel-component/__tests__/CarouselComponent.test.d.ts +0 -1
  34. package/dist/components/carousel-component/__tests__/CarouselComponent.test.js +0 -163
  35. package/dist/components/carousel-component/__tests__/CarouselItem.test.d.ts +0 -1
  36. package/dist/components/carousel-component/__tests__/CarouselItem.test.js +0 -80
  37. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.d.ts +0 -1
  38. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.js +0 -62
  39. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.d.ts +0 -1
  40. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.js +0 -68
  41. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.d.ts +0 -1
  42. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.js +0 -314
  43. package/dist/components/carousel-component/hooks/useCarousel.d.ts +0 -2
  44. package/dist/components/carousel-component/hooks/useCarousel.js +0 -140
  45. package/dist/components/carousel-component/index.d.ts +0 -4
  46. package/dist/components/carousel-component/index.js +0 -20
  47. package/dist/components/carousel-component/styles.d.ts +0 -30
  48. package/dist/components/carousel-component/styles.js +0 -120
  49. package/dist/components/carousel-component/types.d.ts +0 -46
  50. package/dist/components/carousel-component/types.js +0 -2
  51. package/dist/components/trip-cards/SkeletonCard.d.ts +0 -2
  52. package/dist/components/trip-cards/SkeletonCard.js +0 -21
  53. package/dist/components/trip-cards/TripCard.d.ts +0 -3
  54. package/dist/components/trip-cards/TripCard.js +0 -47
  55. package/dist/components/trip-cards/TripCards.stories.d.ts +0 -1
  56. package/dist/components/trip-cards/TripCards.stories.js +0 -40
  57. package/dist/components/trip-cards/TripCardsLayout.d.ts +0 -3
  58. package/dist/components/trip-cards/TripCardsLayout.js +0 -26
  59. package/dist/components/trip-cards/__tests__/SkeletonCard.test.d.ts +0 -1
  60. package/dist/components/trip-cards/__tests__/SkeletonCard.test.js +0 -139
  61. package/dist/components/trip-cards/__tests__/TripCard.test.d.ts +0 -1
  62. package/dist/components/trip-cards/__tests__/TripCard.test.js +0 -95
  63. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.d.ts +0 -1
  64. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.js +0 -277
  65. package/dist/components/trip-cards/__tests__/assets.test.d.ts +0 -1
  66. package/dist/components/trip-cards/__tests__/assets.test.js +0 -165
  67. package/dist/components/trip-cards/__tests__/helpers.test.d.ts +0 -1
  68. package/dist/components/trip-cards/__tests__/helpers.test.js +0 -135
  69. package/dist/components/trip-cards/__tests__/index.test.d.ts +0 -1
  70. package/dist/components/trip-cards/__tests__/index.test.js +0 -437
  71. package/dist/components/trip-cards/__tests__/mockData.test.d.ts +0 -1
  72. package/dist/components/trip-cards/__tests__/mockData.test.js +0 -57
  73. package/dist/components/trip-cards/__tests__/skeletonStyles.test.d.ts +0 -1
  74. package/dist/components/trip-cards/__tests__/skeletonStyles.test.js +0 -194
  75. package/dist/components/trip-cards/assets/BoatIcon.d.ts +0 -1
  76. package/dist/components/trip-cards/assets/BoatIcon.js +0 -4
  77. package/dist/components/trip-cards/assets/CalendarIcon.d.ts +0 -1
  78. package/dist/components/trip-cards/assets/CalendarIcon.js +0 -4
  79. package/dist/components/trip-cards/assets/ChevronRightIcon.d.ts +0 -1
  80. package/dist/components/trip-cards/assets/ChevronRightIcon.js +0 -4
  81. package/dist/components/trip-cards/assets/LocationIcon.d.ts +0 -1
  82. package/dist/components/trip-cards/assets/LocationIcon.js +0 -4
  83. package/dist/components/trip-cards/assets/MoonIcon.d.ts +0 -1
  84. package/dist/components/trip-cards/assets/MoonIcon.js +0 -4
  85. package/dist/components/trip-cards/assets/index.d.ts +0 -6
  86. package/dist/components/trip-cards/assets/index.js +0 -7
  87. package/dist/components/trip-cards/helpers.d.ts +0 -4
  88. package/dist/components/trip-cards/helpers.js +0 -74
  89. package/dist/components/trip-cards/index.d.ts +0 -4
  90. package/dist/components/trip-cards/index.js +0 -70
  91. package/dist/components/trip-cards/mockData.d.ts +0 -3
  92. package/dist/components/trip-cards/mockData.js +0 -323
  93. package/dist/components/trip-cards/skeletonStyles.d.ts +0 -9
  94. package/dist/components/trip-cards/skeletonStyles.js +0 -37
  95. package/dist/components/trip-cards/styles.d.ts +0 -39
  96. package/dist/components/trip-cards/styles.js +0 -387
  97. package/dist/components/trip-cards/types.d.ts +0 -87
  98. package/dist/components/trip-cards/types.js +0 -2
  99. package/src/components/carousel-component/CarouselComponent.stories.tsx +0 -220
  100. package/src/components/carousel-component/CarouselItem.tsx +0 -20
  101. package/src/components/carousel-component/DefaultNavigationArrow.tsx +0 -37
  102. package/src/components/carousel-component/DefaultPageDot.tsx +0 -20
  103. package/src/components/carousel-component/__tests__/CarouselComponent.test.tsx +0 -259
  104. package/src/components/carousel-component/__tests__/CarouselItem.test.tsx +0 -140
  105. package/src/components/carousel-component/__tests__/DefaultNavigationArrow.test.tsx +0 -153
  106. package/src/components/carousel-component/__tests__/DefaultPageDot.test.tsx +0 -105
  107. package/src/components/carousel-component/hooks/__tests__/useCarousel.test.ts +0 -438
  108. package/src/components/carousel-component/hooks/useCarousel.ts +0 -187
  109. package/src/components/carousel-component/index.tsx +0 -88
  110. package/src/components/carousel-component/styles.ts +0 -140
  111. package/src/components/carousel-component/types.ts +0 -51
  112. package/src/components/trip-cards/SkeletonCard.tsx +0 -54
  113. package/src/components/trip-cards/TripCard.tsx +0 -135
  114. package/src/components/trip-cards/TripCards.stories.tsx +0 -67
  115. package/src/components/trip-cards/TripCardsLayout.tsx +0 -75
  116. package/src/components/trip-cards/__tests__/SkeletonCard.test.tsx +0 -169
  117. package/src/components/trip-cards/__tests__/TripCard.test.tsx +0 -120
  118. package/src/components/trip-cards/__tests__/TripCardsLayout.test.tsx +0 -532
  119. package/src/components/trip-cards/__tests__/assets.test.tsx +0 -206
  120. package/src/components/trip-cards/__tests__/helpers.test.ts +0 -165
  121. package/src/components/trip-cards/__tests__/index.test.tsx +0 -499
  122. package/src/components/trip-cards/__tests__/mockData.test.ts +0 -67
  123. package/src/components/trip-cards/__tests__/skeletonStyles.test.tsx +0 -256
  124. package/src/components/trip-cards/assets/BoatIcon.tsx +0 -17
  125. package/src/components/trip-cards/assets/CalendarIcon.tsx +0 -17
  126. package/src/components/trip-cards/assets/ChevronRightIcon.tsx +0 -20
  127. package/src/components/trip-cards/assets/LocationIcon.tsx +0 -17
  128. package/src/components/trip-cards/assets/MoonIcon.tsx +0 -17
  129. package/src/components/trip-cards/assets/index.ts +0 -7
  130. package/src/components/trip-cards/helpers.ts +0 -99
  131. package/src/components/trip-cards/index.tsx +0 -104
  132. package/src/components/trip-cards/mockData.ts +0 -351
  133. package/src/components/trip-cards/skeletonStyles.ts +0 -46
  134. package/src/components/trip-cards/styles.ts +0 -426
  135. package/src/components/trip-cards/types.ts +0 -91
  136. /package/dist/components/{carousel-component/CarouselComponent.stories.d.ts → opta/utils/__tests__/emitEvent.test.d.ts} +0 -0
@@ -12,6 +12,7 @@ import {
12
12
  import { Container, PlaceholderContainer } from '../../shared/shared-styles';
13
13
  import { WidgetContainer } from './styles';
14
14
  import Button from '../../shared/button/Button';
15
+ import { emitEvent } from '../../utils/emitEvent';
15
16
 
16
17
  export const OptaCricketScorecard: React.FC<{
17
18
  competition: string;
@@ -30,6 +31,7 @@ export const OptaCricketScorecard: React.FC<{
30
31
  heightLg = 258
31
32
  }) => {
32
33
  const ref = React.createRef<HTMLDivElement>();
34
+ const containerRef = React.createRef<HTMLDivElement>();
33
35
  const [isReady, setIsReady] = useState<boolean>(false);
34
36
  const [showDetails, setShowDetails] = useState<boolean>(false);
35
37
 
@@ -81,6 +83,16 @@ export const OptaCricketScorecard: React.FC<{
81
83
  });
82
84
  }, []);
83
85
 
86
+ useEffect(
87
+ () => {
88
+ const height = containerRef.current
89
+ ? containerRef.current.offsetHeight
90
+ : 0;
91
+ emitEvent('updateHeight', height);
92
+ },
93
+ [showDetails]
94
+ );
95
+
84
96
  return (
85
97
  <Container
86
98
  fullWidth={full_width}
@@ -88,6 +100,7 @@ export const OptaCricketScorecard: React.FC<{
88
100
  heightMd={heightMd}
89
101
  heightLg={heightLg}
90
102
  hasPadding
103
+ ref={containerRef}
91
104
  >
92
105
  <WidgetContainer ref={ref} showDetails={showDetails} />
93
106
 
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { render, act, fireEvent } from '@testing-library/react';
2
+ import { render, act, fireEvent, waitFor } from '@testing-library/react';
3
3
  import 'regenerator-runtime';
4
4
  import '@testing-library/jest-dom';
5
5
 
@@ -10,22 +10,27 @@ jest.mock('@times-components/image', () => ({
10
10
  const mockInitSettings = jest.fn();
11
11
  const mockInitStyleSheet = jest.fn();
12
12
  const mockInitComponent = jest.fn();
13
- const mockHasMatchEvents = jest.fn();
13
+ const mockInitScript = jest.fn();
14
+ const mockEmitEvent = jest.fn();
14
15
 
15
- const mockInitElement = () => {
16
+ const mockInitElement = jest.fn(() => {
16
17
  const element = document.createElement('div');
17
18
  element.appendChild(document.createTextNode('Widget'));
18
19
  return element;
19
- };
20
+ });
20
21
 
21
22
  jest.mock('../../../utils/config', () => ({
22
23
  initSettings: mockInitSettings,
23
24
  initStyleSheet: mockInitStyleSheet,
24
- initScript: () => new Promise(resolve => resolve({})),
25
+ initScript: mockInitScript,
25
26
  initElement: mockInitElement,
26
27
  initComponent: mockInitComponent
27
28
  }));
28
29
 
30
+ jest.mock('../../../utils/emitEvent', () => ({
31
+ emitEvent: mockEmitEvent
32
+ }));
33
+
29
34
  import { OptaCricketScorecard } from '../OptaCricketScorecard';
30
35
 
31
36
  const requiredProps = {
@@ -36,19 +41,26 @@ const requiredProps = {
36
41
  describe('OptaCricketScorecard', () => {
37
42
  beforeEach(() => {
38
43
  jest.clearAllMocks();
44
+ mockInitScript.mockResolvedValue({});
45
+ });
46
+
47
+ afterEach(() => {
48
+ jest.clearAllMocks();
49
+ document.body.innerHTML = '';
39
50
  });
40
51
 
41
52
  it('should render correctly', async () => {
42
- const { asFragment } = render(<OptaCricketScorecard {...requiredProps} />);
53
+ const { asFragment, getByRole } = render(
54
+ <OptaCricketScorecard {...requiredProps} />
55
+ );
43
56
 
44
- act(() => {
45
- mockInitComponent();
46
- mockHasMatchEvents();
57
+ await waitFor(() => {
58
+ expect(mockInitSettings).toHaveBeenCalledTimes(1);
47
59
  });
48
60
 
49
- expect(mockInitSettings).toHaveBeenCalledTimes(1);
50
- expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
61
+ expect(mockInitStyleSheet).toHaveBeenCalledWith('cricket');
51
62
  expect(mockInitComponent).toHaveBeenCalledTimes(1);
63
+ expect(getByRole('button')).toBeInTheDocument();
52
64
 
53
65
  expect(asFragment()).toMatchSnapshot();
54
66
  });
@@ -59,14 +71,112 @@ describe('OptaCricketScorecard', () => {
59
71
  expect(button).not.toBeDisabled();
60
72
  });
61
73
 
62
- it('should toggle details when button is clicked', () => {
74
+ it('should toggle details when button is clicked', async () => {
63
75
  const { getByRole } = render(<OptaCricketScorecard {...requiredProps} />);
64
76
  const button = getByRole('button');
65
77
 
66
78
  expect(button).toHaveTextContent('Show Details');
67
- fireEvent.click(button);
68
- expect(button).toHaveTextContent('Hide Details');
69
- fireEvent.click(button);
70
- expect(button).toHaveTextContent('Show Details');
79
+
80
+ act(() => {
81
+ fireEvent.click(button);
82
+ });
83
+
84
+ await waitFor(() => {
85
+ expect(button).toHaveTextContent('Hide Details');
86
+ });
87
+
88
+ act(() => {
89
+ fireEvent.click(button);
90
+ });
91
+
92
+ await waitFor(() => {
93
+ expect(button).toHaveTextContent('Show Details');
94
+ });
95
+ });
96
+
97
+ describe('emitEvent', () => {
98
+ it('should call emitEvent with updateHeight when details are toggled', async () => {
99
+ const { getByRole } = render(<OptaCricketScorecard {...requiredProps} />);
100
+ const button = getByRole('button');
101
+
102
+ // Clear initial calls
103
+ jest.clearAllMocks();
104
+
105
+ act(() => {
106
+ fireEvent.click(button);
107
+ });
108
+
109
+ await waitFor(() => {
110
+ expect(mockEmitEvent).toHaveBeenCalledWith(
111
+ 'updateHeight',
112
+ expect.any(Number)
113
+ );
114
+ });
115
+ });
116
+
117
+ it('should emit updateHeight event on each toggle', async () => {
118
+ const { getByRole } = render(<OptaCricketScorecard {...requiredProps} />);
119
+ const button = getByRole('button');
120
+
121
+ // Clear initial calls
122
+ jest.clearAllMocks();
123
+
124
+ // First toggle
125
+ act(() => {
126
+ fireEvent.click(button);
127
+ });
128
+
129
+ await waitFor(() => {
130
+ expect(mockEmitEvent).toHaveBeenCalledTimes(1);
131
+ });
132
+
133
+ // Second toggle
134
+ act(() => {
135
+ fireEvent.click(button);
136
+ });
137
+
138
+ await waitFor(() => {
139
+ expect(mockEmitEvent).toHaveBeenCalledTimes(2);
140
+ });
141
+
142
+ // Third toggle
143
+ act(() => {
144
+ fireEvent.click(button);
145
+ });
146
+
147
+ await waitFor(() => {
148
+ expect(mockEmitEvent).toHaveBeenCalledTimes(3);
149
+ });
150
+ });
151
+
152
+ it('should emit updateHeight with container offsetHeight', async () => {
153
+ const { getByRole, container } = render(
154
+ <OptaCricketScorecard {...requiredProps} />
155
+ );
156
+ const button = getByRole('button');
157
+
158
+ // Clear initial calls
159
+ jest.clearAllMocks();
160
+
161
+ // Mock offsetHeight
162
+ const containerElement = container.querySelector('[class*="Container"]');
163
+ if (containerElement) {
164
+ Object.defineProperty(containerElement, 'offsetHeight', {
165
+ value: 300,
166
+ configurable: true
167
+ });
168
+ }
169
+
170
+ act(() => {
171
+ fireEvent.click(button);
172
+ });
173
+
174
+ await waitFor(() => {
175
+ expect(mockEmitEvent).toHaveBeenCalledWith(
176
+ 'updateHeight',
177
+ expect.any(Number)
178
+ );
179
+ });
180
+ });
71
181
  });
72
182
  });
@@ -7,17 +7,16 @@ exports[`OptaCricketScorecard should render correctly 1`] = `
7
7
  >
8
8
  <div
9
9
  class="sc-bxivhb sc-ifAKCX dNXXXn"
10
- />
10
+ >
11
+ <div>
12
+ Widget
13
+ </div>
14
+ </div>
11
15
  <button
12
16
  class="sc-EHOje dWKhuC"
13
17
  >
14
18
  Show Details
15
19
  </button>
16
- <div
17
- class="sc-bwzfXH eSqyJ"
18
- >
19
- Placeholder
20
- </div>
21
20
  </div>
22
21
  </DocumentFragment>
23
22
  `;
@@ -13,6 +13,7 @@ import {
13
13
  import { Container, PlaceholderContainer } from '../../shared/shared-styles';
14
14
  import { WidgetContainer } from '../../shared/summary-styles';
15
15
  import Button from '../../shared/button/Button';
16
+ import { emitEvent } from '../../utils/emitEvent';
16
17
 
17
18
  export const OptaFootballSummary: React.FC<{
18
19
  season: string;
@@ -33,6 +34,7 @@ export const OptaFootballSummary: React.FC<{
33
34
  heightLg = 197
34
35
  }) => {
35
36
  const ref = React.createRef<HTMLDivElement>();
37
+ const containerRef = React.createRef<HTMLDivElement>();
36
38
  const [isReady, setIsReady] = useState<boolean>(false);
37
39
  const [showDetails, setShowDetails] = useState<boolean>(false);
38
40
 
@@ -71,6 +73,16 @@ export const OptaFootballSummary: React.FC<{
71
73
  });
72
74
  }, []);
73
75
 
76
+ useEffect(
77
+ () => {
78
+ const height = containerRef.current
79
+ ? containerRef.current.offsetHeight
80
+ : 0;
81
+ emitEvent('updateHeight', height);
82
+ },
83
+ [showDetails]
84
+ );
85
+
74
86
  return (
75
87
  <Container
76
88
  fullWidth={full_width}
@@ -78,6 +90,7 @@ export const OptaFootballSummary: React.FC<{
78
90
  heightMd={heightMd}
79
91
  heightLg={heightLg}
80
92
  hasPadding
93
+ ref={containerRef}
81
94
  >
82
95
  <WidgetContainer ref={ref} showDetails={showDetails} />
83
96
 
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import { render, act, fireEvent } from '@testing-library/react';
3
-
2
+ import { render, act, fireEvent, waitFor } from '@testing-library/react';
4
3
  import 'regenerator-runtime';
5
4
  import '@testing-library/jest-dom';
6
5
 
@@ -11,22 +10,27 @@ jest.mock('@times-components/image', () => ({
11
10
  const mockInitSettings = jest.fn();
12
11
  const mockInitStyleSheet = jest.fn();
13
12
  const mockInitComponent = jest.fn();
14
- const mockHasMatchEvents = jest.fn();
13
+ const mockInitScript = jest.fn();
14
+ const mockEmitEvent = jest.fn();
15
15
 
16
- const mockInitElement = () => {
16
+ const mockInitElement = jest.fn(() => {
17
17
  const element = document.createElement('div');
18
18
  element.appendChild(document.createTextNode('Widget'));
19
19
  return element;
20
- };
20
+ });
21
21
 
22
22
  jest.mock('../../../utils/config', () => ({
23
23
  initSettings: mockInitSettings,
24
24
  initStyleSheet: mockInitStyleSheet,
25
- initScript: () => new Promise(resolve => resolve({})),
25
+ initScript: mockInitScript,
26
26
  initElement: mockInitElement,
27
27
  initComponent: mockInitComponent
28
28
  }));
29
29
 
30
+ jest.mock('../../../utils/emitEvent', () => ({
31
+ emitEvent: mockEmitEvent
32
+ }));
33
+
30
34
  import { OptaFootballSummary } from '../OptaFootballSummary';
31
35
 
32
36
  const requiredProps = {
@@ -38,37 +42,142 @@ const requiredProps = {
38
42
  describe('OptaFootballSummary', () => {
39
43
  beforeEach(() => {
40
44
  jest.clearAllMocks();
45
+ mockInitScript.mockResolvedValue({});
46
+ });
47
+
48
+ afterEach(() => {
49
+ jest.clearAllMocks();
50
+ document.body.innerHTML = '';
41
51
  });
42
52
 
43
53
  it('should render correctly', async () => {
44
- const { asFragment } = render(<OptaFootballSummary {...requiredProps} />);
54
+ const { asFragment, getByRole } = render(
55
+ <OptaFootballSummary {...requiredProps} />
56
+ );
45
57
 
46
- act(() => {
47
- mockInitComponent();
48
- mockHasMatchEvents();
58
+ await waitFor(() => {
59
+ expect(mockInitSettings).toHaveBeenCalledTimes(1);
49
60
  });
50
61
 
51
- expect(mockInitSettings).toHaveBeenCalledTimes(1);
52
- expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
62
+ expect(mockInitStyleSheet).toHaveBeenCalledWith('football');
53
63
  expect(mockInitComponent).toHaveBeenCalledTimes(1);
64
+ expect(getByRole('button')).toBeInTheDocument();
54
65
 
55
66
  expect(asFragment()).toMatchSnapshot();
56
67
  });
57
68
 
58
- it('should disable the button initially', () => {
69
+ it('should enable the button initially', () => {
59
70
  const { getByRole } = render(<OptaFootballSummary {...requiredProps} />);
60
71
  const button = getByRole('button');
61
72
  expect(button).not.toBeDisabled();
62
73
  });
63
74
 
64
- it('should toggle details when button is clicked', () => {
75
+ it('should toggle details when button is clicked', async () => {
65
76
  const { getByRole } = render(<OptaFootballSummary {...requiredProps} />);
66
77
  const button = getByRole('button');
67
78
 
68
79
  expect(button).toHaveTextContent('Show Details');
69
- fireEvent.click(button);
70
- expect(button).toHaveTextContent('Hide Details');
71
- fireEvent.click(button);
72
- expect(button).toHaveTextContent('Show Details');
80
+
81
+ act(() => {
82
+ fireEvent.click(button);
83
+ });
84
+
85
+ await waitFor(() => {
86
+ expect(button).toHaveTextContent('Hide Details');
87
+ });
88
+
89
+ act(() => {
90
+ fireEvent.click(button);
91
+ });
92
+
93
+ await waitFor(() => {
94
+ expect(button).toHaveTextContent('Show Details');
95
+ });
96
+ });
97
+
98
+ describe('emitEvent', () => {
99
+ it('should call emitEvent with updateHeight when details are toggled', async () => {
100
+ const { getByRole } = render(<OptaFootballSummary {...requiredProps} />);
101
+ const button = getByRole('button');
102
+
103
+ // Clear initial calls
104
+ jest.clearAllMocks();
105
+
106
+ act(() => {
107
+ fireEvent.click(button);
108
+ });
109
+
110
+ await waitFor(() => {
111
+ expect(mockEmitEvent).toHaveBeenCalledWith(
112
+ 'updateHeight',
113
+ expect.any(Number)
114
+ );
115
+ });
116
+ });
117
+
118
+ it('should emit updateHeight event on each toggle', async () => {
119
+ const { getByRole } = render(<OptaFootballSummary {...requiredProps} />);
120
+ const button = getByRole('button');
121
+
122
+ // Clear initial calls
123
+ jest.clearAllMocks();
124
+
125
+ // First toggle
126
+ act(() => {
127
+ fireEvent.click(button);
128
+ });
129
+
130
+ await waitFor(() => {
131
+ expect(mockEmitEvent).toHaveBeenCalledTimes(1);
132
+ });
133
+
134
+ // Second toggle
135
+ act(() => {
136
+ fireEvent.click(button);
137
+ });
138
+
139
+ await waitFor(() => {
140
+ expect(mockEmitEvent).toHaveBeenCalledTimes(2);
141
+ });
142
+
143
+ // Third toggle
144
+ act(() => {
145
+ fireEvent.click(button);
146
+ });
147
+
148
+ await waitFor(() => {
149
+ expect(mockEmitEvent).toHaveBeenCalledTimes(3);
150
+ });
151
+ });
152
+
153
+ it('should emit updateHeight with container offsetHeight', async () => {
154
+ const { getByRole, container } = render(
155
+ <OptaFootballSummary {...requiredProps} />
156
+ );
157
+ const button = getByRole('button');
158
+
159
+ // Clear initial calls
160
+ jest.clearAllMocks();
161
+
162
+ // Mock offsetHeight
163
+ const containerElement = container.querySelector('[class*="Container"]');
164
+ if (containerElement) {
165
+ Object.defineProperty(containerElement, 'offsetHeight', {
166
+ value: 250,
167
+ configurable: true
168
+ });
169
+ }
170
+
171
+ act(() => {
172
+ fireEvent.click(button);
173
+ });
174
+
175
+ await waitFor(() => {
176
+ expect(mockEmitEvent).toHaveBeenCalledWith(
177
+ 'updateHeight',
178
+ expect.any(Number)
179
+ );
180
+ });
181
+ });
73
182
  });
74
183
  });
@@ -7,17 +7,16 @@ exports[`OptaFootballSummary should render correctly 1`] = `
7
7
  >
8
8
  <div
9
9
  class="sc-htpNat sc-bxivhb hNtyxM"
10
- />
10
+ >
11
+ <div>
12
+ Widget
13
+ </div>
14
+ </div>
11
15
  <button
12
16
  class="sc-ifAKCX fvBTJK"
13
17
  >
14
18
  Show Details
15
19
  </button>
16
- <div
17
- class="sc-bwzfXH eSqyJ"
18
- >
19
- Placeholder
20
- </div>
21
20
  </div>
22
21
  </DocumentFragment>
23
22
  `;
@@ -13,6 +13,7 @@ import {
13
13
  import { Container, PlaceholderContainer } from '../../shared/shared-styles';
14
14
  import { WidgetContainer } from '../../shared/summary-styles';
15
15
  import Button from '../../shared/button/Button';
16
+ import { emitEvent } from '../../utils/emitEvent';
16
17
 
17
18
  export const OptaRugbySummary: React.FC<{
18
19
  season: string;
@@ -33,6 +34,7 @@ export const OptaRugbySummary: React.FC<{
33
34
  heightLg = 197
34
35
  }) => {
35
36
  const ref = React.createRef<HTMLDivElement>();
37
+ const containerRef = React.createRef<HTMLDivElement>();
36
38
  const [isReady, setIsReady] = useState<boolean>(false);
37
39
  const [showDetails, setShowDetails] = useState<boolean>(false);
38
40
 
@@ -73,6 +75,16 @@ export const OptaRugbySummary: React.FC<{
73
75
  });
74
76
  }, []);
75
77
 
78
+ useEffect(
79
+ () => {
80
+ const height = containerRef.current
81
+ ? containerRef.current.offsetHeight
82
+ : 0;
83
+ emitEvent('updateHeight', height);
84
+ },
85
+ [showDetails]
86
+ );
87
+
76
88
  return (
77
89
  <Container
78
90
  fullWidth={full_width}
@@ -80,6 +92,7 @@ export const OptaRugbySummary: React.FC<{
80
92
  heightMd={heightMd}
81
93
  heightLg={heightLg}
82
94
  hasPadding
95
+ ref={containerRef}
83
96
  >
84
97
  <WidgetContainer ref={ref} showDetails={showDetails} />
85
98