gatsby-matrix-theme 53.28.17 → 53.28.19
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.
- package/CHANGELOG.md +26 -0
- package/package.json +2 -2
- package/src/components/atoms/coupon/copied-state.module.scss +31 -0
- package/src/components/atoms/coupon/coupon.test.js +41 -1
- package/src/components/atoms/coupon/index.js +21 -2
- package/src/components/molecules/sportstake/lotto-module/index.js +7 -4
- package/src/components/molecules/sportstake/lotto-module/lotto-module.test.js +69 -0
- package/src/components/molecules/toplist/row/variant-one.js +5 -2
- package/src/components/molecules/toplist/row/variant-one.test.js +26 -7
- package/src/gatsby-core-theme/components/organisms/toplist/list/index.js +4 -1
- package/src/gatsby-core-theme/components/organisms/toplist/list/list.test.js +24 -0
- package/src/gatsby-core-theme/helpers/server-data.js +24 -5
- package/src/gatsby-core-theme/helpers/server-data.test.js +101 -0
- package/src/gatsby-core-theme/helpers/services.js +55 -54
- package/src/gatsby-core-theme/helpers/services.test.js +160 -0
- package/storybook/public/{251.31f7a99d.iframe.bundle.js → 251.1bd25466.iframe.bundle.js} +4 -4
- package/storybook/public/{251.31f7a99d.iframe.bundle.js.map → 251.1bd25466.iframe.bundle.js.map} +1 -1
- package/storybook/public/333.6032823e.iframe.bundle.js +1 -0
- package/storybook/public/943.f0ebee65.iframe.bundle.js +1 -0
- package/storybook/public/iframe.html +1 -1
- package/storybook/public/main.21695da0.iframe.bundle.js +1 -0
- package/storybook/public/project.json +2 -1
- package/storybook/public/{runtime~main.3b29e117.iframe.bundle.js → runtime~main.86c7df37.iframe.bundle.js} +1 -1
- package/storybook/public/333.41422704.iframe.bundle.js +0 -1
- package/storybook/public/943.3f7c32be.iframe.bundle.js +0 -1
- package/storybook/public/main.27263f44.iframe.bundle.js +0 -1
- /package/storybook/public/{251.31f7a99d.iframe.bundle.js.LICENSE.txt → 251.1bd25466.iframe.bundle.js.LICENSE.txt} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## [53.28.19](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/compare/v53.28.18...v53.28.19) (2026-10-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update matrix version ([001171a](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/001171aeec9ed8b11773b6f205155b888348e8b9))
|
|
7
|
+
|
|
8
|
+
## [53.28.18](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/compare/v53.28.17...v53.28.18) (2026-10-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* handle lottery API timeouts and failures without crashing SSR pages ([75e9076](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/75e9076b12800e47635a66b441c0e4899998218c))
|
|
14
|
+
* keep coupon code in Meta click events and memoize toplist rows ([888147f](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/888147f22aaf02293b7326a340d1cacecd9685bd))
|
|
15
|
+
* pause lottery API calls after an invalid response body too ([90ee600](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/90ee60080b5e8e55cb71456d2c2b4f815168481b))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Config
|
|
19
|
+
|
|
20
|
+
* update theme to fix INP and 3rd part API timeout ([79b8666](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/79b8666320258e5e9b141bdcc5cbc75130bf87ef))
|
|
21
|
+
* update theme to fix INP and 3rd part API timeout ([08b3ccc](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/08b3ccc02eccb3042a70cc0b18daf3602908ad9f))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
* Merge branch 'fix/api-resilience' into 'master' ([2b2ffef](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/2b2ffef5af1c7eb6d13ac9bf3cd42424af1b2975))
|
|
25
|
+
* Merge branch 'perf/inp-matrix' into 'master' ([5f7501b](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/commit/5f7501bd2c45022539845fba3ea3268cfd245559))
|
|
26
|
+
|
|
1
27
|
## [53.28.17](https://gitlab.com/g2m-gentoo/team-floyd/themes/matrix-theme/compare/v53.28.16...v53.28.17) (2026-10-14)
|
|
2
28
|
|
|
3
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby-matrix-theme",
|
|
3
|
-
"version": "53.28.
|
|
3
|
+
"version": "53.28.19",
|
|
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.
|
|
29
|
+
"gatsby-core-theme": "44.36.1",
|
|
30
30
|
"gatsby-plugin-sharp": "^5.11.0",
|
|
31
31
|
"gatsby-plugin-sitemap": "^6.13.1",
|
|
32
32
|
"gatsby-transformer-sharp": "^5.11.0",
|
|
@@ -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
|
|
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
|
|
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]]
|
|
26
|
+
const lottoId = reorderedDates?.[tabId.split('_')[1]]?._id?.split('-')[idIndex];
|
|
27
|
+
if (!lottoId) return;
|
|
27
28
|
|
|
28
|
-
|
|
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
|
-
|
|
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).
|
|
19
|
+
expect(container).toBeInTheDocument();
|
|
14
20
|
|
|
15
21
|
// Name
|
|
16
|
-
expect(getByText('name1')).
|
|
22
|
+
expect(getByText('name1')).toBeInTheDocument();
|
|
17
23
|
|
|
18
24
|
// Bonus
|
|
19
|
-
expect(getByText('€100 welcome bonus')).
|
|
20
|
-
expect(getByText('+150 free spins')).
|
|
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')).
|
|
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')).
|
|
28
|
-
expect(getByText('Nice design')).
|
|
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 =
|
|
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 =
|
|
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:
|
|
340
|
-
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
|
+
});
|