gatsby-matrix-theme 53.28.16 → 53.28.18

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 (29) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/package.json +2 -2
  3. package/src/components/atoms/cards/game-cards/template-one/index.js +7 -1
  4. package/src/components/atoms/cards/game-cards/template-one/template-one.test.js +4 -2
  5. package/src/components/atoms/coupon/copied-state.module.scss +31 -0
  6. package/src/components/atoms/coupon/coupon.test.js +41 -1
  7. package/src/components/atoms/coupon/index.js +21 -2
  8. package/src/components/molecules/sportstake/lotto-module/index.js +7 -4
  9. package/src/components/molecules/sportstake/lotto-module/lotto-module.test.js +69 -0
  10. package/src/components/molecules/toplist/row/variant-one.js +5 -2
  11. package/src/components/molecules/toplist/row/variant-one.test.js +26 -7
  12. package/src/gatsby-core-theme/components/organisms/toplist/list/index.js +4 -1
  13. package/src/gatsby-core-theme/components/organisms/toplist/list/list.test.js +24 -0
  14. package/src/gatsby-core-theme/helpers/server-data.js +24 -5
  15. package/src/gatsby-core-theme/helpers/server-data.test.js +101 -0
  16. package/src/gatsby-core-theme/helpers/services.js +55 -54
  17. package/src/gatsby-core-theme/helpers/services.test.js +160 -0
  18. package/storybook/public/{251.31f7a99d.iframe.bundle.js → 251.dea1f5c3.iframe.bundle.js} +4 -4
  19. package/storybook/public/{251.31f7a99d.iframe.bundle.js.map → 251.dea1f5c3.iframe.bundle.js.map} +1 -1
  20. package/storybook/public/333.6032823e.iframe.bundle.js +1 -0
  21. package/storybook/public/943.f0ebee65.iframe.bundle.js +1 -0
  22. package/storybook/public/iframe.html +1 -1
  23. package/storybook/public/main.21695da0.iframe.bundle.js +1 -0
  24. package/storybook/public/project.json +1 -1
  25. package/storybook/public/{runtime~main.3b29e117.iframe.bundle.js → runtime~main.86c7df37.iframe.bundle.js} +1 -1
  26. package/storybook/public/333.41422704.iframe.bundle.js +0 -1
  27. package/storybook/public/943.3f7c32be.iframe.bundle.js +0 -1
  28. package/storybook/public/main.31e21238.iframe.bundle.js +0 -1
  29. /package/storybook/public/{251.31f7a99d.iframe.bundle.js.LICENSE.txt → 251.dea1f5c3.iframe.bundle.js.LICENSE.txt} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ ## [53.28.18](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/compare/v53.28.17...v53.28.18) (2026-10-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * handle lottery API timeouts and failures without crashing SSR pages ([75e9076](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/75e9076b12800e47635a66b441c0e4899998218c))
7
+ * keep coupon code in Meta click events and memoize toplist rows ([888147f](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/888147f22aaf02293b7326a340d1cacecd9685bd))
8
+ * pause lottery API calls after an invalid response body too ([90ee600](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/90ee60080b5e8e55cb71456d2c2b4f815168481b))
9
+
10
+
11
+ ### Config
12
+
13
+ * update theme to fix INP and 3rd part API timeout ([79b8666](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/79b8666320258e5e9b141bdcc5cbc75130bf87ef))
14
+ * update theme to fix INP and 3rd part API timeout ([08b3ccc](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/08b3ccc02eccb3042a70cc0b18daf3602908ad9f))
15
+
16
+
17
+ * Merge branch 'fix/api-resilience' into 'master' ([2b2ffef](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/2b2ffef5af1c7eb6d13ac9bf3cd42424af1b2975))
18
+ * Merge branch 'perf/inp-matrix' into 'master' ([5f7501b](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/5f7501bd2c45022539845fba3ea3268cfd245559))
19
+
20
+ ## [53.28.17](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/compare/v53.28.16...v53.28.17) (2026-10-14)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * update style of game cards when ribbon present ([b7da716](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/b7da7160010047e49a85f025ee5b4b97c9cccb51))
26
+
27
+
28
+ * Merge branch 'en-720-ribbons-update' into 'master' ([c38af12](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/c38af1238494f476731061a4e4fb420541f6d61f))
29
+
1
30
  ## [53.28.16](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/compare/v53.28.15...v53.28.16) (2026-10-13)
2
31
 
3
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-matrix-theme",
3
- "version": "53.28.16",
3
+ "version": "53.28.18",
4
4
  "main": "index.js",
5
5
  "description": "Matrix Theme NPM Package",
6
6
  "author": "",
@@ -26,7 +26,7 @@
26
26
  "@gigmedia/enigma-utils": "^1.20.0",
27
27
  "@react-icons/all-files": "^4.1.0",
28
28
  "gatsby": "^5.11.0",
29
- "gatsby-core-theme": "44.35.13",
29
+ "gatsby-core-theme": "44.36.0",
30
30
  "gatsby-plugin-sharp": "^5.11.0",
31
31
  "gatsby-plugin-sitemap": "^6.13.1",
32
32
  "gatsby-transformer-sharp": "^5.11.0",
@@ -37,12 +37,14 @@ const TemplateOne = ({
37
37
  const operator = item.extra_fields?.operator;
38
38
  const provider = relation?.game_provider;
39
39
  const gameImage = relation?.logo?.filename || banner;
40
+ const ribbons = item?.relation?.ribbons || item?.ribbons || [];
41
+ const hasRibbons = showRibbon && Array.isArray(ribbons) && ribbons?.length > 0;
40
42
 
41
43
  return (
42
44
  <div
43
45
  className={`${styles?.baseCard || ''} ${featured ? styles.featured || '' : ''} ${
44
46
  moduleStyle ? styles[moduleStyle] || '' : ''
45
- }`}
47
+ } ${hasRibbons ? `${styles.withRibbon || ''}` : ''}`}
46
48
  >
47
49
  {showImageAsLink ? (
48
50
  <Link
@@ -153,7 +155,11 @@ const TemplateOne = ({
153
155
 
154
156
  TemplateOne.propTypes = {
155
157
  item: PropTypes.shape({
158
+ ribbons: PropTypes.arrayOf(PropTypes.string),
156
159
  relation: PropTypes.shape({
160
+ ribbons: PropTypes.arrayOf(PropTypes.shape({
161
+ name: PropTypes.string,
162
+ })),
157
163
  rating: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
158
164
  average_rating: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
159
165
  first_rating: PropTypes.number,
@@ -46,9 +46,10 @@ describe('Game Cards', () => {
46
46
  ribbons: ['New', 'Exclusive'],
47
47
  };
48
48
 
49
- const { queryByText } = render(<TemplateOne item={card} />);
49
+ const { container, queryByText } = render(<TemplateOne item={card} />);
50
50
  expect(queryByText('New')).not.toBeInTheDocument();
51
51
  expect(queryByText('Exclusive')).not.toBeInTheDocument();
52
+ expect(container.querySelector('.withRibbon')).not.toBeInTheDocument();
52
53
  });
53
54
 
54
55
  test('shows only the first ribbon when showRibbon is true', () => {
@@ -58,9 +59,10 @@ describe('Game Cards', () => {
58
59
  ribbons: ['New', 'Exclusive'],
59
60
  };
60
61
 
61
- const { getByText, queryByText } = render(<TemplateOne item={card} showRibbon />);
62
+ const { container, getByText, queryByText } = render(<TemplateOne item={card} showRibbon />);
62
63
  expect(getByText('New')).toBeInTheDocument();
63
64
  expect(queryByText('Exclusive')).not.toBeInTheDocument();
65
+ expect(container.querySelector('.withRibbon')).toBeInTheDocument();
64
66
  });
65
67
 
66
68
  test('shows every ribbon when multipleRibbons is true', () => {
@@ -0,0 +1,31 @@
1
+ // NOTE kept out of coupon.module.scss, which sites shadow: without these rules the copied state would show the code instead of the label
2
+ .copiedLabel {
3
+ display: inline-grid;
4
+ place-items: center;
5
+
6
+ &::after {
7
+ content: attr(data-copied-label);
8
+ grid-area: 1 / 1;
9
+ }
10
+ }
11
+
12
+ // NOTE opacity, not visibility/display: hidden text would drop out of innerText
13
+ .copiedCode {
14
+ @include flex-align(center, center);
15
+
16
+ grid-area: 1 / 1;
17
+ gap: 0.4rem;
18
+ opacity: 0;
19
+ }
20
+
21
+ .liveRegion {
22
+ position: absolute;
23
+ width: 1px;
24
+ height: 1px;
25
+ margin: -1px;
26
+ padding: 0;
27
+ border: 0;
28
+ overflow: hidden;
29
+ clip-path: inset(50%);
30
+ white-space: nowrap;
31
+ }
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { render, fireEvent } from '@testing-library/react';
2
+ import { render, fireEvent, act } from '@testing-library/react';
3
3
  import Coupon from '.';
4
4
 
5
5
  describe('Coupon Component', () => {
@@ -36,4 +36,44 @@ describe('Coupon Component', () => {
36
36
 
37
37
  expect(container.querySelector('button')).toHaveAttribute('disabled', '');
38
38
  });
39
+
40
+ it('exposes the code as the button value', () => {
41
+ const { container } = render(<Coupon code="TESTCODE" />);
42
+
43
+ expect(container.querySelector('button')).toHaveAttribute('value', 'TESTCODE');
44
+ });
45
+
46
+ it('exposes the code as the anchor name when it acts like a CTA', () => {
47
+ const { container } = render(
48
+ <Coupon
49
+ code="TESTCODE"
50
+ actLikeCta
51
+ operator={{ name: 'Operator', short_name: 'operator', status: 'active', type: 'casino' }}
52
+ />
53
+ );
54
+
55
+ expect(container.querySelector('a')).toHaveAttribute('name', 'TESTCODE');
56
+ });
57
+
58
+ it('keeps the code as hidden text in the button when copied and announces the label outside it', async () => {
59
+ const writeText = jest.fn().mockResolvedValue(undefined);
60
+ Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true });
61
+
62
+ const { container } = render(<Coupon code="TESTCODE" templateOne showprefix />);
63
+ const button = container.querySelector('button');
64
+
65
+ await act(async () => {
66
+ fireEvent.click(button);
67
+ });
68
+
69
+ const label = button.querySelector('[data-copied-label]');
70
+ expect(label).toHaveAttribute('data-copied-label', 'CODE COPIED');
71
+ expect(label.querySelector('[aria-hidden="true"]')).toHaveTextContent('Code:TESTCODE');
72
+ expect(button).toHaveTextContent('TESTCODE');
73
+ expect(button).not.toHaveTextContent('CODE COPIED');
74
+
75
+ const liveRegion = container.querySelector('[aria-live="polite"]');
76
+ expect(button).not.toContainElement(liveRegion);
77
+ expect(liveRegion).toHaveTextContent('CODE COPIED');
78
+ });
39
79
  });
@@ -8,6 +8,7 @@ import useTranslate from '~hooks/useTranslate/useTranslate';
8
8
  import CopyIcon from '../../../images/icons/copy-icon';
9
9
  import CheckCircleIcon from '../../../images/icons/check-circle';
10
10
  import styles from './coupon.module.scss';
11
+ import copiedStyles from './copied-state.module.scss';
11
12
 
12
13
  const Coupon = ({
13
14
  code = '',
@@ -70,17 +71,29 @@ const Coupon = ({
70
71
  ${code === null ? styles.noCode : ''}
71
72
  ${inactive ? styles.disabled : ''}`;
72
73
 
73
- const couponContent = !copySuccess ? (
74
+ const codeText = (
74
75
  <>
75
76
  {templateOne && showprefix && (
76
77
  <span className={styles.prefix}>{prefixLabel}</span>
77
78
  )}
78
79
  {code || noCouponLabel}
80
+ </>
81
+ );
82
+
83
+ // Meta's automatic events read innerText after the click has re-rendered, so the copied state
84
+ // keeps the code as invisible text and draws the label with ::after, which innerText skips.
85
+ const couponContent = !copySuccess ? (
86
+ <>
87
+ {codeText}
79
88
  {showIcon && code !== null && !inactive && !isBet365 && icon}
80
89
  </>
81
90
  ) : (
82
91
  <>
83
- <span>{codeCopiedLabel}</span>
92
+ <span className={copiedStyles.copiedLabel} data-copied-label={codeCopiedLabel}>
93
+ <span className={copiedStyles.copiedCode} aria-hidden="true">
94
+ {codeText}
95
+ </span>
96
+ </span>
84
97
  {showIcon && checkIcon}
85
98
  </>
86
99
  );
@@ -100,6 +113,7 @@ const Coupon = ({
100
113
  href={prettyLink}
101
114
  target="_blank"
102
115
  rel={rel}
116
+ name={code}
103
117
  onClick={handleCopyClick}
104
118
  className={couponClass}
105
119
  {...getCtaDataAttributes(operator, {
@@ -115,6 +129,7 @@ const Coupon = ({
115
129
  <button
116
130
  onClick={handleCopyClick}
117
131
  type="button"
132
+ value={code}
118
133
  className={couponClass}
119
134
  disabled={inactive || isBet365}
120
135
  {...(ctaEnabled
@@ -129,6 +144,10 @@ const Coupon = ({
129
144
  {couponContent}
130
145
  </button>
131
146
  )}
147
+ {/* Outside the button: Meta reads the button's innerText, which would include this label */}
148
+ <div className={copiedStyles.liveRegion} aria-live="polite">
149
+ {copySuccess ? codeCopiedLabel : ''}
150
+ </div>
132
151
  </div>
133
152
  );
134
153
  };
@@ -23,11 +23,14 @@ const LottoModule = ({ serverData, page, module, modulePosition }) => {
23
23
  const apiBaseNames = getApiBasedNames(moduleName);
24
24
  const idIndex = moduleName === 'daily_lotto' ? 2 : 1;
25
25
  // eslint-disable-next-line no-underscore-dangle
26
- const lottoId = reorderedDates[tabId.split('_')[1]]._id.split('-')[idIndex];
26
+ const lottoId = reorderedDates?.[tabId.split('_')[1]]?._id?.split('-')[idIndex];
27
+ if (!lottoId) return;
27
28
 
28
- setTabData(await Promise.all(
29
- apiBaseNames.map((name) => getResultsById(`${name}-${lottoId}`))
30
- ));
29
+ const draws = (
30
+ await Promise.all(apiBaseNames.map((name) => getResultsById(`${name}-${lottoId}`)))
31
+ ).filter(Boolean);
32
+
33
+ if (draws.length > 0) setTabData(draws);
31
34
  }
32
35
 
33
36
  return (
@@ -0,0 +1,69 @@
1
+ /* eslint-disable react/prop-types */
2
+ import React from 'react';
3
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
4
+ import LottoModule from '.';
5
+ import { getResultsById } from '../../../../gatsby-core-theme/helpers/services';
6
+
7
+ jest.mock('../../../../gatsby-core-theme/helpers/services', () => ({
8
+ getResultsById: jest.fn(),
9
+ }));
10
+ jest.mock('../../../../gatsby-core-theme/helpers/lotto', () => ({
11
+ getApiBasedNames: () => ['lotto', 'lotto-plus-1', 'lotto-plus-2'],
12
+ }));
13
+ jest.mock('gatsby-core-theme/src/hooks/tabs', () => ({ children, onTabChange }) => (
14
+ <div>
15
+ {children.map((child, index) => (
16
+ <button
17
+ type="button"
18
+ key={child.props.label + child.props.results}
19
+ onClick={() => onTabChange(`${child.props.label}_${index}`)}
20
+ >
21
+ {child.props.results}
22
+ </button>
23
+ ))}
24
+ {children[0]?.props.children}
25
+ </div>
26
+ ));
27
+ jest.mock('./winning-numbers', () => ({ data }) => <p>{`draw ${data.drawNumber}`}</p>);
28
+ jest.mock('./rollover', () => () => null);
29
+ jest.mock('./lotto-table', () => () => null);
30
+
31
+ const serverData = {
32
+ latestDrawResults: [{ lottery: 'lotto', drawNumber: 2400 }],
33
+ reorderedDates: [
34
+ { _id: 'lotto-2400', drawDate: '2026-10-11' },
35
+ { _id: 'lotto-2399', drawDate: '2026-10-08' },
36
+ ],
37
+ };
38
+
39
+ const renderModule = () =>
40
+ render(<LottoModule serverData={serverData} module={{ name: 'lotto' }} page={{}} />);
41
+
42
+ describe('LottoModule', () => {
43
+ beforeEach(() => {
44
+ getResultsById.mockReset();
45
+ });
46
+
47
+ test('shows the draws loaded for the selected tab', async () => {
48
+ getResultsById.mockImplementation((id) =>
49
+ Promise.resolve(id === 'lotto-2399' ? { lottery: 'lotto', drawNumber: 2399 } : null)
50
+ );
51
+ renderModule();
52
+
53
+ fireEvent.click(screen.getByText('Oct 8'));
54
+
55
+ expect(await screen.findByText('draw 2399')).toBeInTheDocument();
56
+ expect(getResultsById).toHaveBeenCalledWith('lotto-2399');
57
+ expect(getResultsById).toHaveBeenCalledWith('lotto-plus-1-2399');
58
+ });
59
+
60
+ test('keeps the current draws when the lottery API fails', async () => {
61
+ getResultsById.mockResolvedValue(null);
62
+ renderModule();
63
+
64
+ fireEvent.click(screen.getByText('Oct 8'));
65
+
66
+ await waitFor(() => expect(getResultsById).toHaveBeenCalledTimes(3));
67
+ expect(screen.getByText('draw 2400')).toBeInTheDocument();
68
+ });
69
+ });
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable react/prop-types */
2
2
  /* eslint-disable import/no-extraneous-dependencies */
3
- import React, { useContext } from 'react';
3
+ import React, { useContext, memo } from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import SellingPoints from 'gatsby-core-theme/src/components/atoms/selling-points';
6
6
  import OperatorCta from 'gatsby-core-theme/src/components/atoms/button/operator-cta';
@@ -13,7 +13,7 @@ import VerifiedAuthor from '../../../../images/icons/verified-author';
13
13
  import { TrackingKeys } from '~constants/tracking-api'
14
14
  import styles from './variant-one.module.scss';
15
15
 
16
- export default function Row({
16
+ function Row({
17
17
  item,
18
18
  tracker = 'main',
19
19
  oneliner = 'main',
@@ -154,3 +154,6 @@ Row.propTypes = {
154
154
  height: PropTypes.number,
155
155
  multipleRibbons: PropTypes.bool,
156
156
  };
157
+
158
+ // The toplist renders every row and "Load more" only changes className, so unchanged rows skip re-rendering.
159
+ export default memo(Row);
@@ -3,33 +3,52 @@ import { render, cleanup } from '@testing-library/react';
3
3
  import '@testing-library/jest-dom/extend-expect';
4
4
 
5
5
  import { getToplistItem } from '../../../../../tests/factories/modules/toplist.factory';
6
+ import CasinoDetails from '../../operator-details';
6
7
  import Row from './variant-one';
7
8
 
9
+ jest.mock('../../operator-details', () => {
10
+ const actual = jest.requireActual('../../operator-details');
11
+ return { __esModule: true, default: jest.fn(actual.default) };
12
+ });
13
+
8
14
  describe('toplist row component', () => {
9
15
  test('render row list format', async () => {
10
16
  const { container, getByText } = render(
11
17
  <Row item={getToplistItem()} tracker="main" itemRefs={{ current: {} }} />
12
18
  );
13
- expect(container).toBeTruthy();
19
+ expect(container).toBeInTheDocument();
14
20
 
15
21
  // Name
16
- expect(getByText('name1')).toBeTruthy();
22
+ expect(getByText('name1')).toBeInTheDocument();
17
23
 
18
24
  // Bonus
19
- expect(getByText('€100 welcome bonus')).toBeTruthy();
20
- expect(getByText('+150 free spins')).toBeTruthy();
25
+ expect(getByText('€100 welcome bonus')).toBeInTheDocument();
26
+ expect(getByText('+150 free spins')).toBeInTheDocument();
21
27
 
22
28
  // Rating & Logo
23
- expect(container.querySelector('img')).toBeTruthy();
29
+ expect(container.querySelector('img')).toBeInTheDocument();
24
30
 
25
31
  // Selling Points
26
32
  expect(container.querySelectorAll('.sellingPoint li')).toHaveLength(2);
27
- expect(getByText('200% Bonus')).toBeTruthy();
28
- expect(getByText('Nice design')).toBeTruthy();
33
+ expect(getByText('200% Bonus')).toBeInTheDocument();
34
+ expect(getByText('Nice design')).toBeInTheDocument();
29
35
 
30
36
  // CTA
31
37
  expect(getByText('Visit').closest('a').getAttribute('href')).toEqual('/slotum');
32
38
  });
39
+
40
+ test('re-renders only when its props change', () => {
41
+ const item = getToplistItem();
42
+ const itemRefs = { current: {} };
43
+ const { rerender } = render(<Row item={item} tracker="main" itemRefs={itemRefs} />);
44
+ CasinoDetails.mockClear();
45
+
46
+ rerender(<Row item={item} tracker="main" itemRefs={itemRefs} />);
47
+ expect(CasinoDetails).not.toHaveBeenCalled();
48
+
49
+ rerender(<Row item={item} tracker="main" itemRefs={itemRefs} className="show" />);
50
+ expect(CasinoDetails).toHaveBeenCalledTimes(1);
51
+ });
33
52
  });
34
53
  afterEach(() => {
35
54
  cleanup();
@@ -13,6 +13,9 @@ import styleTemplateOne from './template-one.module.scss';
13
13
  import styleTemplateTwo from './template-two.module.scss';
14
14
  import styleTemplateThree from './template-three.module.scss';
15
15
 
16
+ // One element for every render: a new default element per render would re-render every memoized Row.
17
+ const defaultVerifyIcon = <VerifiedAuthor />;
18
+
16
19
  export default function List({
17
20
  pagePath,
18
21
  toplist,
@@ -26,7 +29,7 @@ export default function List({
26
29
  template,
27
30
  loadMoreIcon = null,
28
31
  modulePosition,
29
- verifyIcon = <VerifiedAuthor />,
32
+ verifyIcon = defaultVerifyIcon,
30
33
  pageStyle,
31
34
  multipleRibbons = false,
32
35
  }) {
@@ -4,6 +4,12 @@ import '@testing-library/jest-dom/extend-expect';
4
4
  import { singleToplistData } from 'gatsby-core-theme/tests/factories/modules/toplist.factory';
5
5
  import List from './index';
6
6
  import Row from '../../../../../components/molecules/toplist/row/variant-one';
7
+ import CasinoDetails from '../../../../../components/molecules/operator-details';
8
+
9
+ jest.mock('../../../../../components/molecules/operator-details', () => {
10
+ const actual = jest.requireActual('../../../../../components/molecules/operator-details');
11
+ return { __esModule: true, default: jest.fn(actual.default) };
12
+ });
7
13
 
8
14
  const module = singleToplistData;
9
15
 
@@ -41,6 +47,24 @@ describe('List test component', () => {
41
47
 
42
48
  expect(container.getElementsByClassName('show').length).toBe(0);
43
49
  });
50
+
51
+ test('load more re-renders only the newly shown rows', () => {
52
+ const { container } = render(
53
+ <List
54
+ hasLoadMoreButton="1"
55
+ initItemsCount="2"
56
+ loadItemsCount="2"
57
+ toplist={module.items[0]}
58
+ removeInactiveItems={false}
59
+ />
60
+ );
61
+ CasinoDetails.mockClear();
62
+
63
+ fireEvent.click(container.querySelector('.loadMore button'));
64
+
65
+ expect(container.getElementsByClassName('show').length).toBe(4);
66
+ expect(CasinoDetails).toHaveBeenCalledTimes(2);
67
+ });
44
68
  });
45
69
  afterEach(() => {
46
70
  cleanup();
@@ -111,6 +111,23 @@ export async function getAPIData(page, url, header, preview) {
111
111
  }
112
112
  }
113
113
 
114
+ try {
115
+ // eslint-disable-next-line no-use-before-define
116
+ return await getLotteryData(page);
117
+ } catch (error) {
118
+ console.error(chalk.red('error') + chalk.whiteBright(` Lottery data failed for ${page?.path}`), error);
119
+ return {
120
+ props: {
121
+ fixtures: { data: {} },
122
+ results: { data: {} },
123
+ lotto: { data: [] },
124
+ lottouk49: { data: [], tabs: [] },
125
+ },
126
+ };
127
+ }
128
+ }
129
+
130
+ async function getLotteryData(page) {
114
131
  const sportstakeTemplateBlocks = [
115
132
  'matchplay8results',
116
133
  'matchplay14results',
@@ -296,9 +313,11 @@ export async function getAPIData(page, url, header, preview) {
296
313
  return dateB.getTime() - dateA.getTime();
297
314
  });
298
315
 
299
- const latestDrawResults = await Promise.all(
300
- apiBaseNames.map((name) => getLatestResults(name))
301
- );
316
+ const latestDrawResults = (
317
+ await Promise.all(apiBaseNames.map((name) => getLatestResults(name)))
318
+ ).filter(Boolean);
319
+
320
+ if (reorderedDates.length === 0 || latestDrawResults.length === 0) return;
302
321
 
303
322
  return { name: moduleName, result: { latestDrawResults, reorderedDates } };
304
323
  })
@@ -336,8 +355,8 @@ export async function getAPIData(page, url, header, preview) {
336
355
  })
337
356
  );
338
357
  lottoUK49 = {
339
- tabs: [...responseArray[0].tabs, ...responseArray[1].tabs],
340
- data: [...responseArray[0].data, ...responseArray[1].data],
358
+ tabs: responseArray.flatMap((response) => response.tabs || []),
359
+ data: responseArray.flatMap((response) => response.data || []),
341
360
  };
342
361
  } else {
343
362
  lottoUK49 = { data: [], tabs: [] };
@@ -0,0 +1,101 @@
1
+ import { getAPIData } from './server-data';
2
+ import {
3
+ getResultsById,
4
+ getLatestResults,
5
+ getAvailableDrawDays,
6
+ getLottoUKdata,
7
+ getCalendarData,
8
+ } from './services';
9
+
10
+ jest.mock('./services', () => ({
11
+ getResultsById: jest.fn(),
12
+ getLatestResults: jest.fn(),
13
+ getAvailableDrawDays: jest.fn(),
14
+ getLottoUKdata: jest.fn(),
15
+ getCalendarData: jest.fn(),
16
+ }));
17
+ jest.mock('./lotto', () => ({
18
+ getApiBasedNames: (name) => (name === 'lotto' ? ['lotto', 'lotto-plus-1', 'lotto-plus-2'] : []),
19
+ }));
20
+ jest.mock('./sportstake', () => ({
21
+ getApiQueryParams: (name) => ({ lotteryName: name.replace(/(results|fixtures)$/, '') }),
22
+ }));
23
+ jest.mock('gatsby-core-theme/src/resolver/index', () => ({ run: jest.fn() }));
24
+ jest.mock('gatsby-core-theme/src/services/fetch.mjs', () => ({ fetchSiteSettings: jest.fn() }));
25
+ jest.mock('~helpers/search-source', () => jest.fn());
26
+ const templateBlock = (name) => ({ value_type: 'template_block', name });
27
+
28
+ const lottoPage = {
29
+ path: 'lotto-results',
30
+ categories: [{ short_name: 'lotto' }, { short_name: 'results' }, { short_name: 'lotto_uk_49' }],
31
+ sections: {
32
+ main: { modules: [templateBlock('lotto'), templateBlock('matchplay8results')] },
33
+ },
34
+ };
35
+
36
+ const mockApiDown = () => {
37
+ getResultsById.mockResolvedValue(null);
38
+ getLatestResults.mockResolvedValue(null);
39
+ getAvailableDrawDays.mockResolvedValue([]);
40
+ getLottoUKdata.mockResolvedValue([]);
41
+ getCalendarData.mockResolvedValue([]);
42
+ };
43
+
44
+ describe('getAPIData', () => {
45
+ beforeEach(() => {
46
+ jest.resetAllMocks();
47
+ jest.spyOn(console, 'error').mockImplementation(() => {});
48
+ });
49
+
50
+ afterEach(() => {
51
+ jest.restoreAllMocks();
52
+ });
53
+
54
+ test('returns empty lottery data when the lottery API is down', async () => {
55
+ mockApiDown();
56
+
57
+ const { props } = await getAPIData(lottoPage, '/lotto-results', {});
58
+
59
+ expect(props.lotto).toEqual({ data: [] });
60
+ expect(props.results.data.matchplay8results).toEqual([]);
61
+ expect(props.lottouk49).toEqual({ data: [], tabs: [] });
62
+ });
63
+
64
+ test('leaves out a lotto module that has no draw dates', async () => {
65
+ mockApiDown();
66
+ getLatestResults.mockResolvedValue({ lottery: 'lotto' });
67
+
68
+ const { props } = await getAPIData(lottoPage, '/lotto-results', {});
69
+
70
+ expect(props.lotto).toEqual({ data: [] });
71
+ });
72
+
73
+ test('keeps a lotto module and drops the draws that failed to load', async () => {
74
+ mockApiDown();
75
+ const draw = { _id: 'lotto-2400', drawDate: '2026-10-11' };
76
+ getAvailableDrawDays.mockResolvedValueOnce([draw]);
77
+ getLatestResults.mockImplementation((name) =>
78
+ Promise.resolve(name === 'lotto' ? { lottery: 'lotto' } : null)
79
+ );
80
+
81
+ const { props } = await getAPIData(lottoPage, '/lotto-results', {});
82
+
83
+ expect(props.lotto.data).toEqual([
84
+ { name: 'lotto', result: { latestDrawResults: [{ lottery: 'lotto' }], reorderedDates: [draw] } },
85
+ ]);
86
+ });
87
+
88
+ test('returns empty lottery props instead of throwing on an unexpected error', async () => {
89
+ mockApiDown();
90
+ getCalendarData.mockRejectedValue(new Error('boom'));
91
+
92
+ await expect(getAPIData(lottoPage, '/lotto-results', {})).resolves.toEqual({
93
+ props: {
94
+ fixtures: { data: {} },
95
+ results: { data: {} },
96
+ lotto: { data: [] },
97
+ lottouk49: { data: [], tabs: [] },
98
+ },
99
+ });
100
+ });
101
+ });