@times-components/ts-components 1.87.0 → 1.88.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 (30) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/components/opta/football/fixtures-ticker/OptaFootballFixturesTicker.js +6 -12
  3. package/dist/components/opta/football/fixtures-ticker/__tests__/OptaFootballFixturesTicker.test.js +18 -12
  4. package/dist/components/opta/football/shared-styles.js +51 -1
  5. package/dist/components/opta/football/standings/OptaFootballStandings.js +8 -3
  6. package/dist/components/opta/football/standings/OptaFootballStandings.stories.js +4 -4
  7. package/dist/components/opta/football/standings/__tests__/OptaFootballStandings.test.js +3 -3
  8. package/dist/components/opta/football/standings/styles.js +1 -1
  9. package/dist/components/opta/utils/__tests__/replaceNationalTeamDetails.test.js +22 -9
  10. package/dist/components/opta/utils/replaceNationalTeamDetails.d.ts +2 -1
  11. package/dist/components/opta/utils/replaceNationalTeamDetails.js +15 -22
  12. package/dist/components/opta/utils/useUpdateNationalTeamDetails.d.ts +2 -0
  13. package/dist/components/opta/utils/useUpdateNationalTeamDetails.js +10 -0
  14. package/package.json +12 -12
  15. package/rnw.js +1 -1
  16. package/src/components/opta/football/fixtures/__tests__/__snapshots__/OptaFootballFixtures.test.tsx.snap +2 -2
  17. package/src/components/opta/football/fixtures-ticker/OptaFootballFixturesTicker.tsx +5 -15
  18. package/src/components/opta/football/fixtures-ticker/__tests__/OptaFootballFixturesTicker.test.tsx +19 -11
  19. package/src/components/opta/football/fixtures-ticker/__tests__/__snapshots__/OptaFootballFixturesTicker.test.tsx.snap +15 -5
  20. package/src/components/opta/football/match-stats/__tests__/__snapshots__/OptaFootballMatchStats.test.tsx.snap +2 -2
  21. package/src/components/opta/football/shared-styles.ts +56 -0
  22. package/src/components/opta/football/standings/OptaFootballStandings.stories.tsx +4 -4
  23. package/src/components/opta/football/standings/OptaFootballStandings.tsx +31 -22
  24. package/src/components/opta/football/standings/__tests__/OptaFootballStandings.test.tsx +3 -3
  25. package/src/components/opta/football/standings/__tests__/__snapshots__/OptaFootballStandings.test.tsx.snap +2 -2
  26. package/src/components/opta/football/standings/styles.ts +1 -1
  27. package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +2 -2
  28. package/src/components/opta/utils/__tests__/replaceNationalTeamDetails.test.tsx +24 -12
  29. package/src/components/opta/utils/replaceNationalTeamDetails.ts +14 -28
  30. package/src/components/opta/utils/useUpdateNationalTeamDetails.tsx +17 -0
@@ -6,7 +6,7 @@ exports[`OptaFootballFixtures should render correctly 1`] = `
6
6
  class="sc-bdVaJa giUBsz"
7
7
  >
8
8
  <div
9
- class="sc-htpNat sc-ifAKCX eajDtg"
9
+ class="sc-htpNat sc-ifAKCX eHZPwb"
10
10
  />
11
11
  <div
12
12
  class="sc-bwzfXH kVYHKf"
@@ -23,7 +23,7 @@ exports[`OptaFootballFixtures should render correctly 2`] = `
23
23
  class="sc-bdVaJa hGXeaj"
24
24
  >
25
25
  <div
26
- class="sc-htpNat sc-ifAKCX eajDtg"
26
+ class="sc-htpNat sc-ifAKCX eHZPwb"
27
27
  >
28
28
  <div>
29
29
  Widget
@@ -12,7 +12,8 @@ import {
12
12
 
13
13
  import { PlaceholderContainer } from '../shared-styles';
14
14
  import { WidgetContainer } from './styles';
15
- import { replaceNationalTeamDetails } from '../../utils/replaceNationalTeamDetails';
15
+ import { isNationalCompetition } from '../../utils/replaceNationalTeamDetails';
16
+ import { useUpdateNationalTeamDetails } from '../../utils/useUpdateNationalTeamDetails';
16
17
 
17
18
  export const OptaFootballFixturesTicker: React.FC<{
18
19
  season: string;
@@ -35,11 +36,7 @@ export const OptaFootballFixturesTicker: React.FC<{
35
36
  const ref = React.createRef<HTMLDivElement>();
36
37
 
37
38
  const [isReady, setIsReady] = useState<boolean>(false);
38
- const [optaImages, setOptaImages] = useState<
39
- HTMLCollectionOf<Element> | undefined
40
- >();
41
- const nationalCompetitions = ['3', '5', '6', '235', '941', '1125'];
42
- const isNationalCompetition = nationalCompetitions.includes(competition);
39
+ const isNationalComp = isNationalCompetition(competition);
43
40
 
44
41
  useEffect(
45
42
  () => {
@@ -67,7 +64,7 @@ export const OptaFootballFixturesTicker: React.FC<{
67
64
  match_status: 'all',
68
65
  order_by: 'date_ascending',
69
66
  show_grouping: true,
70
- show_crests: !isNationalCompetition,
67
+ show_crests: !isNationalComp,
71
68
  show_date: true,
72
69
  show_live: true,
73
70
  date_format: 'ddd Do MMM'
@@ -75,20 +72,13 @@ export const OptaFootballFixturesTicker: React.FC<{
75
72
 
76
73
  initComponent();
77
74
  setIsReady(true);
78
-
79
- if (isNationalCompetition) {
80
- const TeamNameContainers =
81
- ref.current &&
82
- ref.current.getElementsByClassName('Opta-TeamName');
83
- TeamNameContainers && setOptaImages(TeamNameContainers);
84
- }
85
75
  }
86
76
  });
87
77
  },
88
78
  [ref]
89
79
  );
90
80
 
91
- isNationalCompetition && replaceNationalTeamDetails(optaImages);
81
+ isNationalComp && useUpdateNationalTeamDetails(ref, 'Opta-TeamName');
92
82
 
93
83
  return (
94
84
  <>
@@ -9,7 +9,8 @@ jest.mock('@times-components/image', () => ({
9
9
  const mockInitSettings = jest.fn();
10
10
  const mockInitStyleSheet = jest.fn();
11
11
  const mockInitComponent = jest.fn();
12
- const mockReplaceFlags = jest.fn();
12
+ const mockIsNationalComp = jest.fn();
13
+ const mockUseUpdateNationalTeamDetails = jest.fn();
13
14
 
14
15
  const mockInitElement = () => {
15
16
  const element = document.createElement('div');
@@ -25,10 +26,14 @@ jest.mock('../../../utils/config', () => ({
25
26
  initComponent: mockInitComponent
26
27
  }));
27
28
  jest.mock('../../../utils/replaceNationalTeamDetails', () => ({
28
- replaceNationalTeamDetails: mockReplaceFlags
29
+ isNationalCompetition: mockIsNationalComp
30
+ }));
31
+ jest.mock('../../../utils/useUpdateNationalTeamDetails', () => ({
32
+ useUpdateNationalTeamDetails: mockUseUpdateNationalTeamDetails
29
33
  }));
30
34
 
31
35
  import { OptaFootballFixturesTicker } from '../OptaFootballFixturesTicker';
36
+ import { isNationalCompetition } from '../../../utils/replaceNationalTeamDetails';
32
37
 
33
38
  const requiredProps = {
34
39
  season: '2020',
@@ -37,6 +42,10 @@ const requiredProps = {
37
42
  date_to: '2021-07-11'
38
43
  };
39
44
 
45
+ afterEach(() => {
46
+ jest.clearAllMocks();
47
+ });
48
+
40
49
  describe('OptaFootballFixturesTicker with flags', () => {
41
50
  it('should render correctly', async () => {
42
51
  const { asFragment, getByText } = render(
@@ -46,9 +55,9 @@ describe('OptaFootballFixturesTicker with flags', () => {
46
55
 
47
56
  await waitForElementToBeRemoved(getByText('Placeholder'));
48
57
 
49
- expect(mockInitSettings).toHaveBeenCalledTimes(2);
50
- expect(mockInitStyleSheet).toHaveBeenCalledTimes(2);
51
- expect(mockInitComponent).toHaveBeenCalledTimes(2);
58
+ expect(mockInitSettings).toHaveBeenCalled();
59
+ expect(mockInitStyleSheet).toHaveBeenCalled();
60
+ expect(mockInitComponent).toHaveBeenCalled();
52
61
 
53
62
  expect(asFragment()).toMatchSnapshot();
54
63
  });
@@ -60,20 +69,19 @@ describe('OptaFootballFixturesTicker without flags', () => {
60
69
  });
61
70
 
62
71
  it('should render correctly', async () => {
63
- React.useState = jest.fn().mockReturnValue([true, () => React.useState]);
64
- React.useState = jest
65
- .fn()
66
- .mockReturnValue([document.createElement('div'), () => React.useState]);
72
+ (isNationalCompetition as jest.Mock).mockReturnValue(true);
67
73
 
68
- const { asFragment } = render(
74
+ const { asFragment, getByText } = render(
69
75
  <OptaFootballFixturesTicker season="2023" competition="3" />
70
76
  );
71
77
  expect(asFragment()).toMatchSnapshot();
72
78
 
79
+ await waitForElementToBeRemoved(getByText('Placeholder'));
80
+
73
81
  expect(mockInitSettings).toHaveBeenCalled();
74
82
  expect(mockInitStyleSheet).toHaveBeenCalled();
75
83
  expect(mockInitComponent).toHaveBeenCalled();
76
- expect(mockReplaceFlags).toHaveBeenCalled();
84
+ expect(mockUseUpdateNationalTeamDetails).toHaveBeenCalled();
77
85
 
78
86
  expect(asFragment()).toMatchSnapshot();
79
87
  });
@@ -3,7 +3,7 @@
3
3
  exports[`OptaFootballFixturesTicker with flags should render correctly 1`] = `
4
4
  <DocumentFragment>
5
5
  <div
6
- class="sc-htpNat sc-ifAKCX cpKKZE"
6
+ class="sc-htpNat sc-ifAKCX hfzpiP"
7
7
  />
8
8
  <div
9
9
  class="sc-bwzfXH eLGWmp"
@@ -17,7 +17,7 @@ exports[`OptaFootballFixturesTicker with flags should render correctly 1`] = `
17
17
  exports[`OptaFootballFixturesTicker with flags should render correctly 2`] = `
18
18
  <DocumentFragment>
19
19
  <div
20
- class="sc-htpNat sc-ifAKCX cpKKZE"
20
+ class="sc-htpNat sc-ifAKCX hfzpiP"
21
21
  >
22
22
  <div>
23
23
  Widget
@@ -29,15 +29,25 @@ exports[`OptaFootballFixturesTicker with flags should render correctly 2`] = `
29
29
  exports[`OptaFootballFixturesTicker without flags should render correctly 1`] = `
30
30
  <DocumentFragment>
31
31
  <div
32
- class="sc-htpNat sc-ifAKCX cpKKZE"
32
+ class="sc-htpNat sc-ifAKCX hfzpiP"
33
33
  />
34
+ <div
35
+ class="sc-bwzfXH eLGWmp"
36
+ height="100"
37
+ >
38
+ Placeholder
39
+ </div>
34
40
  </DocumentFragment>
35
41
  `;
36
42
 
37
43
  exports[`OptaFootballFixturesTicker without flags should render correctly 2`] = `
38
44
  <DocumentFragment>
39
45
  <div
40
- class="sc-htpNat sc-ifAKCX cpKKZE"
41
- />
46
+ class="sc-htpNat sc-ifAKCX hfzpiP"
47
+ >
48
+ <div>
49
+ Widget
50
+ </div>
51
+ </div>
42
52
  </DocumentFragment>
43
53
  `;
@@ -6,7 +6,7 @@ exports[`OptaFootballMatchStats should render correctly 1`] = `
6
6
  class="sc-bdVaJa giUBsz"
7
7
  >
8
8
  <div
9
- class="sc-htpNat sc-bxivhb jbuKhZ"
9
+ class="sc-htpNat sc-bxivhb eIGYVQ"
10
10
  />
11
11
  <div
12
12
  class="sc-bwzfXH kVYHKf"
@@ -23,7 +23,7 @@ exports[`OptaFootballMatchStats should render correctly 2`] = `
23
23
  class="sc-bdVaJa hGXeaj"
24
24
  >
25
25
  <div
26
- class="sc-htpNat sc-bxivhb jbuKhZ"
26
+ class="sc-htpNat sc-bxivhb eIGYVQ"
27
27
  >
28
28
  <div>
29
29
  Widget
@@ -1,6 +1,58 @@
1
1
  import styled from 'styled-components';
2
2
  import { breakpoints, colours, fonts } from '@times-components/ts-styleguide';
3
3
 
4
+ const countries: Record<string, string> = {
5
+ '119': 'Italy',
6
+ '357': 'Germany',
7
+ '115': 'Scotland',
8
+ '538': 'Hungary',
9
+ '497': 'Switzerland',
10
+ '118': 'Spain',
11
+ '535': 'Croatia',
12
+ '534': 'Albania',
13
+ '511': 'Poland',
14
+ '366': 'Netherlands',
15
+ '365': 'Slovenia',
16
+ '369': 'Denmark',
17
+ '364': 'Serbia',
18
+ '114': 'England',
19
+ '358': 'Romania',
20
+ '510': 'Ukraine',
21
+ '360': 'Belgium',
22
+ '507': 'Slovakia',
23
+ '515': 'Austria',
24
+ '368': 'France',
25
+ '362': 'Turkey',
26
+ '520': 'Georgia',
27
+ '359': 'Portugal',
28
+ '367': 'CzechRep'
29
+ };
30
+
31
+ const flagStyles = Object.keys(countries).map(
32
+ (countryCode: string) => `
33
+ .Opta-Team-${countryCode} .Opta-Team, .Opta-Team-${countryCode}.Opta-Team {
34
+ background-image: url(https://nuk-tnl-editorial-prod-staticassets.s3.eu-west-1.amazonaws.com/opta/euro-flags/${
35
+ countries[countryCode]
36
+ }.svg);
37
+ background-size: 20px;
38
+ background-repeat: no-repeat;
39
+
40
+ @media (max-width: ${breakpoints.small}px) {
41
+ background-image: none;
42
+ padding-left: 0 !important;
43
+ }
44
+ }
45
+ .Opta-Team-${countryCode} .Opta-Team {
46
+ background-position: 0 13px;
47
+ padding-left: 28px;
48
+ }
49
+ .Opta-Team-${countryCode}.Opta-Team {
50
+ background-position: 10px 8px;
51
+ padding-left: 38px !important;
52
+ }
53
+ `
54
+ );
55
+
4
56
  export const Container = styled.div<{ border: boolean; fullWidth?: boolean }>`
5
57
  margin: 0 auto 20px auto;
6
58
  background-color: ${colours.functional.backgroundPrimary};
@@ -27,6 +79,10 @@ export const PlaceholderContainer = styled.div<{ height?: number }>`
27
79
  `;
28
80
 
29
81
  export const WidgetContainerBase = styled.div`
82
+ &.team-flags {
83
+ ${flagStyles};
84
+ }
85
+
30
86
  .Opta {
31
87
  .Opta_W {
32
88
  margin: 0;
@@ -13,18 +13,18 @@ const showcase = {
13
13
  type: 'decorator'
14
14
  },
15
15
  {
16
- component: () => <OptaFootballStandings season="2020" competition="8" />,
16
+ component: () => <OptaFootballStandings season="2023" competition="8" />,
17
17
  name: 'Standings',
18
18
  type: 'story'
19
19
  },
20
20
  {
21
- component: () => <OptaFootballStandings season="2020" competition="3" />,
21
+ component: () => <OptaFootballStandings season="2023" competition="3" />,
22
22
  name: 'Standings (inline)',
23
23
  type: 'story'
24
24
  },
25
25
  {
26
26
  component: () => (
27
- <OptaFootballStandings season="2020" competition="3" navigation />
27
+ <OptaFootballStandings season="2023" competition="3" navigation />
28
28
  ),
29
29
  name: 'Standings (dropdown)',
30
30
  type: 'story'
@@ -32,7 +32,7 @@ const showcase = {
32
32
  {
33
33
  component: () => (
34
34
  <OptaFootballStandings
35
- season="2020"
35
+ season="2023"
36
36
  competition="3"
37
37
  default_nav="4"
38
38
  navigation
@@ -12,6 +12,8 @@ import {
12
12
 
13
13
  import { Container, PlaceholderContainer } from '../shared-styles';
14
14
  import { WidgetContainer } from './styles';
15
+ import { isNationalCompetition } from '../../utils/replaceNationalTeamDetails';
16
+ import { useUpdateNationalTeamDetails } from '../../utils/useUpdateNationalTeamDetails';
15
17
 
16
18
  export const OptaFootballStandings: React.FC<{
17
19
  season: string;
@@ -24,32 +26,39 @@ export const OptaFootballStandings: React.FC<{
24
26
  const ref = React.createRef<HTMLDivElement>();
25
27
 
26
28
  const [isReady, setIsReady] = useState<boolean>(false);
29
+ const isNationalComp = isNationalCompetition(competition);
27
30
 
28
- useEffect(() => {
29
- const sport = 'football';
31
+ useEffect(
32
+ () => {
33
+ const sport = 'football';
30
34
 
31
- initSettings();
32
- initStyleSheet(sport);
35
+ initSettings();
36
+ initStyleSheet(sport);
33
37
 
34
- initScript().then(() => {
35
- if (ref.current) {
36
- ref.current.innerHTML = initElement('opta-widget', {
37
- sport,
38
- widget: 'standings',
39
- season,
40
- competition,
41
- live: true,
42
- navigation: navigation ? 'dropdown' : undefined,
43
- default_nav,
44
- show_crests: true,
45
- breakpoints: 520
46
- }).outerHTML;
38
+ initScript().then(() => {
39
+ if (ref.current) {
40
+ ref.current.innerHTML = initElement('opta-widget', {
41
+ sport,
42
+ widget: 'standings',
43
+ season,
44
+ competition,
45
+ live: true,
46
+ navigation: navigation ? 'dropdown' : undefined,
47
+ default_nav,
48
+ show_crests: !isNationalComp,
49
+ team_naming: 'brief',
50
+ breakpoints: 520
51
+ }).outerHTML;
47
52
 
48
- initComponent();
49
- setIsReady(true);
50
- }
51
- });
52
- }, []);
53
+ initComponent();
54
+ setIsReady(true);
55
+ }
56
+ });
57
+ },
58
+ [ref]
59
+ );
60
+
61
+ isNationalComp && useUpdateNationalTeamDetails(ref, 'Opta-Team');
53
62
 
54
63
  return (
55
64
  <Container border={isReady} fullWidth={full_width}>
@@ -42,9 +42,9 @@ describe('OptaFootballStandings', () => {
42
42
 
43
43
  await waitForElementToBeRemoved(getByText('Placeholder'));
44
44
 
45
- expect(mockInitSettings).toHaveBeenCalledTimes(1);
46
- expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
47
- expect(mockInitComponent).toHaveBeenCalledTimes(1);
45
+ expect(mockInitSettings).toHaveBeenCalledTimes(2);
46
+ expect(mockInitStyleSheet).toHaveBeenCalledTimes(2);
47
+ expect(mockInitComponent).toHaveBeenCalledTimes(2);
48
48
 
49
49
  expect(asFragment()).toMatchSnapshot();
50
50
  });
@@ -6,7 +6,7 @@ exports[`OptaFootballStandings should render correctly 1`] = `
6
6
  class="sc-bdVaJa giUBsz"
7
7
  >
8
8
  <div
9
- class="sc-htpNat sc-bxivhb kQLOGL"
9
+ class="sc-htpNat sc-bxivhb elfuvD team-flags"
10
10
  />
11
11
  <div
12
12
  class="sc-bwzfXH kVYHKf"
@@ -23,7 +23,7 @@ exports[`OptaFootballStandings should render correctly 2`] = `
23
23
  class="sc-bdVaJa hGXeaj"
24
24
  >
25
25
  <div
26
- class="sc-htpNat sc-bxivhb kQLOGL"
26
+ class="sc-htpNat sc-bxivhb elfuvD team-flags"
27
27
  >
28
28
  <div>
29
29
  Widget
@@ -185,7 +185,7 @@ export const WidgetContainer = styled(WidgetContainerBase)`
185
185
 
186
186
  th {
187
187
  width: 42px;
188
- padding: 6px 0 0 0;
188
+ padding: 0;
189
189
  color: ${colours.section.sport};
190
190
  font-family: ${fonts.supporting};
191
191
  font-size: 14px;
@@ -6,7 +6,7 @@ exports[`OptaFootballSummary should render correctly 1`] = `
6
6
  class="sc-bdVaJa giUBsz"
7
7
  >
8
8
  <div
9
- class="sc-htpNat sc-bxivhb kplfa"
9
+ class="sc-htpNat sc-bxivhb bhudKL"
10
10
  />
11
11
  <div
12
12
  class="sc-bwzfXH kVYHKf"
@@ -23,7 +23,7 @@ exports[`OptaFootballSummary should render correctly 2`] = `
23
23
  class="sc-bdVaJa hGXeaj"
24
24
  >
25
25
  <div
26
- class="sc-htpNat sc-bxivhb kplfa"
26
+ class="sc-htpNat sc-bxivhb bhudKL"
27
27
  >
28
28
  <div>
29
29
  Widget
@@ -23,20 +23,34 @@ const mockReplaceNationalTeamDetails = () => {
23
23
  return mockDomContainer;
24
24
  };
25
25
 
26
- describe('replaceNationalTeamDetails', () => {
27
- jest.spyOn(optaFn, 'replaceNationalTeamDetails');
26
+ describe('isNationalCompetition', () => {
27
+ jest.spyOn(optaFn, 'isNationalCompetition');
28
+
29
+ it('should return TRUE if is in array of national competitions', async () => {
30
+ const isNationalCompetition = optaFn.isNationalCompetition('3');
31
+ expect(optaFn.isNationalCompetition).toHaveBeenCalledWith('3');
32
+ expect(isNationalCompetition).toBe(true);
33
+ });
34
+
35
+ it('should return FALSE if is in array of national competitions', async () => {
36
+ const isNationalCompetition = optaFn.isNationalCompetition('8');
37
+ expect(optaFn.isNationalCompetition).toHaveBeenCalledWith('8');
38
+ expect(isNationalCompetition).toBe(false);
39
+ });
40
+ });
41
+
42
+ describe('replaceWithTBD', () => {
43
+ jest.spyOn(optaFn, 'replaceWithTBD');
28
44
 
29
45
  it('should replace images when valid elements are passed', async () => {
30
46
  jest.useFakeTimers();
31
47
  const container = mockReplaceNationalTeamDetails();
32
48
  const elements = container.getElementsByClassName('Opta-TeamName');
33
- const replaceNationalTeamDetails = await optaFn.replaceNationalTeamDetails(
34
- elements
35
- );
49
+ const replaceWithTBD = await optaFn.replaceWithTBD(elements);
36
50
 
37
- expect(optaFn.replaceNationalTeamDetails).toHaveBeenCalledWith(elements);
51
+ expect(optaFn.replaceWithTBD).toHaveBeenCalledWith(elements);
38
52
  jest.advanceTimersByTime(3000);
39
- expect(replaceNationalTeamDetails).toBe(undefined);
53
+ expect(replaceWithTBD).toBe(undefined);
40
54
  const transformedElements = Array.from(elements);
41
55
  expect(transformedElements[0].querySelector('img')).toBeInstanceOf;
42
56
  expect((transformedElements[0] as HTMLElement).innerText).toBe('Portugal');
@@ -48,13 +62,11 @@ describe('replaceNationalTeamDetails', () => {
48
62
  jest.useFakeTimers();
49
63
  const container = mockReplaceNationalTeamDetails();
50
64
  const elements = container.getElementsByClassName('Opta-TeamName');
51
- const replaceNationalTeamDetails = await optaFn.replaceNationalTeamDetails(
52
- elements
53
- );
65
+ const replaceWithTBD = await optaFn.replaceWithTBD(elements);
54
66
 
55
- expect(optaFn.replaceNationalTeamDetails).toHaveBeenCalledWith(elements);
67
+ expect(optaFn.replaceWithTBD).toHaveBeenCalledWith(elements);
56
68
  jest.advanceTimersByTime(3000);
57
- expect(replaceNationalTeamDetails).toBe(undefined);
69
+ expect(replaceWithTBD).toBe(undefined);
58
70
  const transformedElements = Array.from(elements);
59
71
  expect(transformedElements[2].querySelector('img')).not.toBeInstanceOf;
60
72
  expect((transformedElements[2] as HTMLElement).innerText).toBe('TBD');
@@ -1,34 +1,20 @@
1
- export const replaceNationalTeamDetails = (
2
- element: HTMLCollectionOf<Element> | undefined
3
- ) => {
4
- let count = 0;
5
- const replaceImages = setInterval(() => {
6
- if (count >= 5) {
7
- clearInterval(replaceImages);
8
- }
9
- count++;
10
-
11
- if (element && element.length > 0) {
12
- for (let optaFlagContainer of element) {
13
- const country = (optaFlagContainer as HTMLElement).innerText;
14
-
15
- if (country && country.includes('Third Place')) {
16
- (optaFlagContainer as HTMLElement).innerText = 'TBD';
17
- }
1
+ export const isNationalCompetition = (competition: string) => {
2
+ const nationalCompetitions = [
3
+ '3', // UEFA European Championship Finals
4
+ '235', // UEFA European Championship Qualifiers
5
+ '941' // UEFA Nations League
6
+ ];
7
+ return nationalCompetitions.includes(competition);
8
+ };
18
9
 
19
- if (!optaFlagContainer.querySelector('img')) {
20
- const countryImg = document.createElement('img');
21
- countryImg.setAttribute(
22
- 'src',
23
- `https://nuk-tnl-editorial-prod-staticassets.s3.eu-west-1.amazonaws.com/opta/euro-flags/${country}.svg`
24
- );
25
- countryImg.setAttribute('onerror', 'this.remove()');
26
- countryImg.classList.add('team-flag');
10
+ export const replaceWithTBD = (element: HTMLCollectionOf<Element>) => {
11
+ setTimeout(() => {
12
+ for (let optaFlagContainer of element) {
13
+ const country = (optaFlagContainer as HTMLElement).innerText;
27
14
 
28
- optaFlagContainer.prepend(countryImg);
29
- }
15
+ if (country && country.includes('Third Place')) {
16
+ (optaFlagContainer as HTMLElement).innerText = 'TBD';
30
17
  }
31
- clearInterval(replaceImages);
32
18
  }
33
19
  }, 500);
34
20
  };
@@ -0,0 +1,17 @@
1
+ import { RefObject, useEffect } from 'react';
2
+ import { replaceWithTBD } from './replaceNationalTeamDetails';
3
+
4
+ export const useUpdateNationalTeamDetails = (
5
+ ref: RefObject<HTMLDivElement>,
6
+ container: string
7
+ ) => {
8
+ useEffect(
9
+ () => {
10
+ ref.current && ref.current.classList.add('team-flags');
11
+
12
+ const TeamNameContainers = document.getElementsByClassName(container);
13
+ TeamNameContainers && replaceWithTBD(TeamNameContainers);
14
+ },
15
+ [ref]
16
+ );
17
+ };