@times-components/ts-components 1.85.3-alpha.3 → 1.86.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.
@@ -6,6 +6,7 @@ import { OptaFootballFixturesTicker } from './OptaFootballFixturesTicker';
6
6
  const competitons = [
7
7
  '1',
8
8
  '2',
9
+ '3',
9
10
  '5',
10
11
  '6',
11
12
  '8',
@@ -12,6 +12,7 @@ import {
12
12
 
13
13
  import { PlaceholderContainer } from '../shared-styles';
14
14
  import { WidgetContainer } from './styles';
15
+ import { replaceFlags } from '../../utils/replaceFlags';
15
16
 
16
17
  export const OptaFootballFixturesTicker: React.FC<{
17
18
  season: string;
@@ -22,39 +23,56 @@ export const OptaFootballFixturesTicker: React.FC<{
22
23
  const ref = React.createRef<HTMLDivElement>();
23
24
 
24
25
  const [isReady, setIsReady] = useState<boolean>(false);
26
+ const [optaImages, setOptaImages] = useState<
27
+ HTMLCollectionOf<Element> | undefined
28
+ >();
29
+ const nationalCompetitions = ['3', '5', '6', '235', '941', '1125'];
30
+ const isNationalCompetition = nationalCompetitions.includes(competition);
25
31
 
26
- useEffect(() => {
27
- const sport = 'football';
32
+ useEffect(
33
+ () => {
34
+ const sport = 'football';
28
35
 
29
- initSettings();
30
- initStyleSheet(sport);
36
+ initSettings();
37
+ initStyleSheet(sport);
31
38
 
32
- initScript().then(() => {
33
- if (ref.current) {
34
- ref.current.innerHTML = initElement('opta-widget', {
35
- sport,
36
- widget: 'fixtures',
37
- season,
38
- competition,
39
- date_from,
40
- date_to,
41
- live: true,
42
- start_on_current: true,
43
- template: 'strip',
44
- team_naming: 'brief',
45
- match_status: 'all',
46
- order_by: 'date_ascending',
47
- show_grouping: true,
48
- show_crests: true,
49
- show_date: true,
50
- date_format: 'ddd Do MMM'
51
- }).outerHTML;
39
+ initScript().then(() => {
40
+ if (ref.current) {
41
+ ref.current.innerHTML = initElement('opta-widget', {
42
+ sport,
43
+ widget: 'fixtures',
44
+ season,
45
+ competition,
46
+ date_from,
47
+ date_to,
48
+ live: true,
49
+ start_on_current: true,
50
+ template: 'strip',
51
+ team_naming: 'brief',
52
+ match_status: 'all',
53
+ order_by: 'date_ascending',
54
+ show_grouping: true,
55
+ show_crests: !isNationalCompetition,
56
+ show_date: true,
57
+ date_format: 'ddd Do MMM'
58
+ }).outerHTML;
52
59
 
53
- initComponent();
54
- setIsReady(true);
55
- }
56
- });
57
- }, []);
60
+ initComponent();
61
+ setIsReady(true);
62
+
63
+ if (isNationalCompetition) {
64
+ const TeamNameContainers =
65
+ ref.current &&
66
+ ref.current.getElementsByClassName('Opta-TeamName');
67
+ TeamNameContainers && setOptaImages(TeamNameContainers);
68
+ }
69
+ }
70
+ });
71
+ },
72
+ [ref]
73
+ );
74
+
75
+ isNationalCompetition && replaceFlags(optaImages);
58
76
 
59
77
  return (
60
78
  <>
@@ -1,7 +1,5 @@
1
1
  import React from 'react';
2
2
  import { render, waitForElementToBeRemoved } from '@testing-library/react';
3
-
4
- import 'regenerator-runtime';
5
3
  import '@testing-library/jest-dom';
6
4
 
7
5
  jest.mock('@times-components/image', () => ({
@@ -11,6 +9,7 @@ jest.mock('@times-components/image', () => ({
11
9
  const mockInitSettings = jest.fn();
12
10
  const mockInitStyleSheet = jest.fn();
13
11
  const mockInitComponent = jest.fn();
12
+ const mockReplaceFlags = jest.fn();
14
13
 
15
14
  const mockInitElement = () => {
16
15
  const element = document.createElement('div');
@@ -25,17 +24,20 @@ jest.mock('../../../utils/config', () => ({
25
24
  initElement: mockInitElement,
26
25
  initComponent: mockInitComponent
27
26
  }));
27
+ jest.mock('../../../utils/replaceFlags', () => ({
28
+ replaceFlags: mockReplaceFlags
29
+ }));
28
30
 
29
31
  import { OptaFootballFixturesTicker } from '../OptaFootballFixturesTicker';
30
32
 
31
33
  const requiredProps = {
32
34
  season: '2020',
33
- competition: '3',
35
+ competition: '8',
34
36
  date_from: '2021-06-20',
35
37
  date_to: '2021-07-11'
36
38
  };
37
39
 
38
- describe('OptaFootballFixturesTicker', () => {
40
+ describe('OptaFootballFixturesTicker with flags', () => {
39
41
  it('should render correctly', async () => {
40
42
  const { asFragment, getByText } = render(
41
43
  <OptaFootballFixturesTicker {...requiredProps} />
@@ -44,9 +46,34 @@ describe('OptaFootballFixturesTicker', () => {
44
46
 
45
47
  await waitForElementToBeRemoved(getByText('Placeholder'));
46
48
 
47
- expect(mockInitSettings).toHaveBeenCalledTimes(1);
48
- expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
49
- expect(mockInitComponent).toHaveBeenCalledTimes(1);
49
+ expect(mockInitSettings).toHaveBeenCalledTimes(2);
50
+ expect(mockInitStyleSheet).toHaveBeenCalledTimes(2);
51
+ expect(mockInitComponent).toHaveBeenCalledTimes(2);
52
+
53
+ expect(asFragment()).toMatchSnapshot();
54
+ });
55
+ });
56
+
57
+ describe('OptaFootballFixturesTicker without flags', () => {
58
+ afterAll(() => {
59
+ jest.clearAllTimers();
60
+ });
61
+
62
+ 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]);
67
+
68
+ const { asFragment } = render(
69
+ <OptaFootballFixturesTicker season="2023" competition="3" />
70
+ );
71
+ expect(asFragment()).toMatchSnapshot();
72
+
73
+ expect(mockInitSettings).toHaveBeenCalled();
74
+ expect(mockInitStyleSheet).toHaveBeenCalled();
75
+ expect(mockInitComponent).toHaveBeenCalled();
76
+ expect(mockReplaceFlags).toHaveBeenCalled();
50
77
 
51
78
  expect(asFragment()).toMatchSnapshot();
52
79
  });
@@ -1,9 +1,9 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`OptaFootballFixturesTicker should render correctly 1`] = `
3
+ exports[`OptaFootballFixturesTicker with flags should render correctly 1`] = `
4
4
  <DocumentFragment>
5
5
  <div
6
- class="sc-htpNat sc-ifAKCX elhfwo"
6
+ class="sc-htpNat sc-ifAKCX cpKKZE"
7
7
  />
8
8
  <div
9
9
  class="sc-bwzfXH eLGWmp"
@@ -14,10 +14,10 @@ exports[`OptaFootballFixturesTicker should render correctly 1`] = `
14
14
  </DocumentFragment>
15
15
  `;
16
16
 
17
- exports[`OptaFootballFixturesTicker should render correctly 2`] = `
17
+ exports[`OptaFootballFixturesTicker with flags should render correctly 2`] = `
18
18
  <DocumentFragment>
19
19
  <div
20
- class="sc-htpNat sc-ifAKCX elhfwo"
20
+ class="sc-htpNat sc-ifAKCX cpKKZE"
21
21
  >
22
22
  <div>
23
23
  Widget
@@ -25,3 +25,19 @@ exports[`OptaFootballFixturesTicker should render correctly 2`] = `
25
25
  </div>
26
26
  </DocumentFragment>
27
27
  `;
28
+
29
+ exports[`OptaFootballFixturesTicker without flags should render correctly 1`] = `
30
+ <DocumentFragment>
31
+ <div
32
+ class="sc-htpNat sc-ifAKCX cpKKZE"
33
+ />
34
+ </DocumentFragment>
35
+ `;
36
+
37
+ exports[`OptaFootballFixturesTicker without flags should render correctly 2`] = `
38
+ <DocumentFragment>
39
+ <div
40
+ class="sc-htpNat sc-ifAKCX cpKKZE"
41
+ />
42
+ </DocumentFragment>
43
+ `;
@@ -40,6 +40,10 @@ export const WidgetContainerOverride = styled(WidgetContainerBase)`
40
40
  `;
41
41
 
42
42
  export const WidgetContainer = styled(WidgetContainerBase)`
43
+ .Opta {
44
+ font-family: Roboto !important;
45
+ }
46
+
43
47
  @media (max-width: ${breakpoints.small}px) {
44
48
  .Opta-Window {
45
49
  left: 0 !important;
@@ -95,20 +99,31 @@ export const WidgetContainer = styled(WidgetContainerBase)`
95
99
  }
96
100
  .Opta-Team {
97
101
  height: 24px !important;
102
+
103
+ .team-flag {
104
+ width: 20px;
105
+ margin-bottom: -2px;
106
+ margin-right: 8px;
107
+ }
98
108
  }
99
109
  .Opta-timings {
100
110
  height: 24px !important;
101
111
  order: -1;
112
+ color: #aaaaaa !important;
102
113
  }
103
114
 
104
115
  .Opta-TeamName,
105
116
  .Opta-Team-Score {
106
- color: black !important;
107
- font-weight: bold !important;
117
+ color: #01000d !important;
118
+ font-weight: 700 !important;
108
119
  }
109
120
  &.Opta-prematch .Opta-Team-Score::after {
110
121
  content: '-';
111
122
  }
123
+
124
+ .Opta-Image-Team-Small {
125
+ height: 20px;
126
+ }
112
127
  }
113
128
 
114
129
  .Opta {
@@ -0,0 +1,39 @@
1
+ import '@testing-library/jest-dom';
2
+ import * as optaFn from '../replaceFlags';
3
+
4
+ const mockReplaceFlags = () => {
5
+ const mockDomContainer = document.createElement('div');
6
+ const mockDomElement = document.createElement('div');
7
+ const mockDomElement2 = document.createElement('div');
8
+
9
+ mockDomElement.innerHTML = 'Portugal';
10
+ mockDomElement.classList.add('Opta-TeamName');
11
+
12
+ mockDomElement2.innerHTML = 'Spain';
13
+ mockDomElement2.classList.add('Opta-TeamName');
14
+
15
+ mockDomContainer.append(mockDomElement);
16
+ mockDomContainer.append(mockDomElement2);
17
+
18
+ return mockDomContainer;
19
+ };
20
+
21
+ describe('replaceFlags', () => {
22
+ jest.spyOn(optaFn, 'replaceFlags');
23
+
24
+ it('should replace images when valid elements are passed', async () => {
25
+ jest.useFakeTimers();
26
+ const container = mockReplaceFlags();
27
+ const elements = container.getElementsByClassName('Opta-TeamName');
28
+ const replaceFlags = await optaFn.replaceFlags(elements);
29
+
30
+ expect(optaFn.replaceFlags).toHaveBeenCalledWith(elements);
31
+ jest.advanceTimersByTime(3000);
32
+ expect(replaceFlags).toBe(undefined);
33
+ const transformedElements = Array.from(elements);
34
+ expect(transformedElements[0].querySelector('img')).toBeInstanceOf;
35
+ expect(transformedElements[0]).toHaveTextContent('Portugal');
36
+ expect(transformedElements[1].querySelector('img')).toBeInstanceOf;
37
+ expect(transformedElements[1]).toHaveTextContent('Spain');
38
+ });
39
+ });
@@ -0,0 +1,30 @@
1
+ export const replaceFlags = (
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 (!optaFlagContainer.querySelector('img')) {
16
+ const countryImg = document.createElement('img');
17
+ countryImg.setAttribute(
18
+ 'src',
19
+ `https://nuk-tnl-editorial-prod-staticassets.s3.eu-west-1.amazonaws.com/opta/euro-flags/${country}.svg`
20
+ );
21
+ countryImg.setAttribute('onerror', 'this.remove()');
22
+ countryImg.classList.add('team-flag');
23
+
24
+ optaFlagContainer.prepend(countryImg);
25
+ }
26
+ }
27
+ clearInterval(replaceImages);
28
+ }
29
+ }, 500);
30
+ };
package/tsconfig.json CHANGED
@@ -38,7 +38,7 @@
38
38
 
39
39
  "skipLibCheck": true,
40
40
 
41
- "lib": ["es6", "dom", "es2017"],
41
+ "lib": ["es6", "dom", "es2017", "dom.iterable"],
42
42
  "types": ["jest"],
43
43
  "typeRoots": ["node_modules/@types", "src/types", "../../node_modules/@types"]
44
44
  },