@times-components/ts-slices 1.3.18 → 1.3.21

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 (68) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/components/article/Article/styles.js +2 -2
  3. package/dist/components/article/ArticleComment/styles.js +2 -2
  4. package/dist/components/article/shared-styles.js +2 -2
  5. package/dist/components/elements/Headline/__tests__/Headline.test.js +6 -3
  6. package/dist/components/elements/Headline/styles.js +2 -2
  7. package/dist/components/elements/Image/__tests__/Image.test.js +18 -12
  8. package/dist/components/elements/Image/styles.js +2 -2
  9. package/dist/components/slices/Lead1/styles.js +2 -2
  10. package/dist/components/slices/Lead1And1/styles.js +2 -2
  11. package/dist/components/slices/Lead1And2/styles.js +2 -2
  12. package/dist/components/slices/Lead1And3Reversed/styles.js +2 -2
  13. package/dist/components/slices/Lead2/styles.js +2 -2
  14. package/dist/components/slices/RelatedArticle1/styles.js +2 -2
  15. package/dist/components/slices/Secondary10/styles.js +2 -2
  16. package/dist/components/slices/Secondary2And2/styles.js +2 -2
  17. package/dist/components/slices/Secondary2And3/styles.js +2 -2
  18. package/dist/components/slices/Secondary2And3NoPic/styles.js +2 -2
  19. package/dist/components/slices/Secondary3/styles.js +2 -2
  20. package/dist/components/slices/Secondary4/styles.js +2 -2
  21. package/dist/components/slices/Secondary4Odd/styles.js +2 -2
  22. package/dist/components/slices/__tests__/Slice.test.d.ts +1 -0
  23. package/dist/components/slices/__tests__/Slice.test.js +24 -0
  24. package/dist/components/slices/shared-styles.js +2 -2
  25. package/dist/fixtures/__tests__/getSlice.test.d.ts +1 -0
  26. package/dist/fixtures/__tests__/getSlice.test.js +12 -0
  27. package/dist/fixtures/article-harness/__tests__/ArticleHarness.test.d.ts +1 -0
  28. package/dist/fixtures/article-harness/__tests__/ArticleHarness.test.js +11 -0
  29. package/dist/fixtures/article-harness/styles.js +2 -2
  30. package/dist/utils/FakeIntersectionObserver.d.ts +14 -0
  31. package/dist/utils/FakeIntersectionObserver.js +14 -0
  32. package/dist/utils/__tests__/convertChannelSlice.test.d.ts +2 -0
  33. package/dist/utils/__tests__/convertChannelSlice.test.js +45 -0
  34. package/dist/utils/__tests__/getSlice.test.d.ts +1 -0
  35. package/dist/utils/__tests__/getSlice.test.js +59 -0
  36. package/package.json +4 -4
  37. package/rnw.js +1 -1
  38. package/src/components/article/Article/styles.ts +1 -1
  39. package/src/components/article/ArticleComment/styles.ts +1 -1
  40. package/src/components/article/shared-styles.ts +1 -1
  41. package/src/components/elements/Headline/__tests__/Headline.test.tsx +9 -3
  42. package/src/components/elements/Headline/__tests__/__snapshots__/Headline.test.tsx.snap +1 -15
  43. package/src/components/elements/Headline/styles.ts +1 -1
  44. package/src/components/elements/Image/__tests__/Image.test.tsx +20 -17
  45. package/src/components/elements/Image/__tests__/__snapshots__/Image.test.tsx.snap +8 -9
  46. package/src/components/elements/Image/styles.ts +1 -1
  47. package/src/components/slices/Lead1/styles.ts +1 -1
  48. package/src/components/slices/Lead1And1/styles.ts +1 -1
  49. package/src/components/slices/Lead1And2/styles.ts +1 -1
  50. package/src/components/slices/Lead1And3Reversed/styles.ts +1 -1
  51. package/src/components/slices/Lead2/styles.ts +1 -1
  52. package/src/components/slices/RelatedArticle1/styles.ts +1 -1
  53. package/src/components/slices/Secondary10/styles.ts +1 -1
  54. package/src/components/slices/Secondary2And2/styles.ts +1 -1
  55. package/src/components/slices/Secondary2And3/styles.ts +1 -1
  56. package/src/components/slices/Secondary2And3NoPic/styles.ts +1 -1
  57. package/src/components/slices/Secondary3/styles.ts +1 -1
  58. package/src/components/slices/Secondary4/styles.ts +1 -1
  59. package/src/components/slices/Secondary4Odd/styles.ts +1 -1
  60. package/src/components/slices/__tests__/Slice.test.tsx +32 -0
  61. package/src/components/slices/shared-styles.ts +1 -1
  62. package/src/fixtures/__tests__/getSlice.test.tsx +13 -0
  63. package/src/fixtures/article-harness/__tests__/ArticleHarness.test.tsx +14 -0
  64. package/src/fixtures/article-harness/styles.ts +1 -1
  65. package/src/types/externs.d.ts +1 -1
  66. package/src/utils/FakeIntersectionObserver.tsx +20 -0
  67. package/src/utils/__tests__/convertChannelSlice.test.ts +49 -0
  68. package/src/utils/__tests__/getSlice.test.tsx +69 -0
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { breakpoints } from '@times-components/styleguide';
2
+ import { breakpoints } from '@times-components/ts-styleguide';
3
3
 
4
4
  import { calculateSlotWidth } from '../../../utils/getArticleStyles';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { breakpoints } from '@times-components/styleguide';
2
+ import { breakpoints } from '@times-components/ts-styleguide';
3
3
 
4
4
  import { calculateSlotWidth } from '../../../utils/getArticleStyles';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { breakpoints } from '@times-components/styleguide';
2
+ import { breakpoints } from '@times-components/ts-styleguide';
3
3
 
4
4
  import { calculateSlotWidth } from '../../../utils/getArticleStyles';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { breakpoints } from '@times-components/styleguide';
2
+ import { breakpoints } from '@times-components/ts-styleguide';
3
3
 
4
4
  import { calculateSlotWidth } from '../../../utils/getArticleStyles';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { breakpoints } from '@times-components/styleguide';
2
+ import { breakpoints } from '@times-components/ts-styleguide';
3
3
 
4
4
  import { calculateSlotWidth } from '../../../utils/getArticleStyles';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { breakpoints } from '@times-components/styleguide';
2
+ import { breakpoints } from '@times-components/ts-styleguide';
3
3
 
4
4
  import { calculateSlotWidth } from '../../../utils/getArticleStyles';
5
5
 
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+
4
+ import { Slice } from '../Slice';
5
+
6
+ describe('<Slice/>', () => {
7
+ const mockData = {
8
+ name: 'LEAD_1',
9
+ children: [
10
+ {
11
+ article: {
12
+ headline: 'a headline',
13
+ images: {
14
+ alt: 'image alt text',
15
+ crops: [{ ratio: '3:2', url: 'https://dummyimage.com/300' }]
16
+ }
17
+ }
18
+ }
19
+ ]
20
+ };
21
+
22
+ it('should render as expected', () => {
23
+ const { getByText } = render(
24
+ <Slice
25
+ slice={mockData}
26
+ styles={{ removePadding: true, lineColor: 'yellow' }}
27
+ />
28
+ );
29
+
30
+ getByText('a headline');
31
+ });
32
+ });
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { breakpoints } from '@times-components/styleguide';
2
+ import { breakpoints } from '@times-components/ts-styleguide';
3
3
 
4
4
  import { SliceStyle } from '../../types/styles';
5
5
 
@@ -0,0 +1,13 @@
1
+ import { getSlice } from '../getSlice';
2
+
3
+ describe('getSlice()', () => {
4
+ it('should return a slice', () => {
5
+ const result = getSlice('LEAD_1');
6
+ expect(result.children[0].article!.headline).toBe;
7
+ });
8
+
9
+ it('should not return a slice', () => {
10
+ const result = getSlice('LEAD_10038033');
11
+ expect(result).toEqual({ children: [], name: 'UNDEFINED' });
12
+ });
13
+ });
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react';
3
+ import { ArticleHarness } from '../ArticleHarness';
4
+
5
+ describe('ArticleHarness', () => {
6
+ it('should render as expected', () => {
7
+ const { getByText } = render(
8
+ <ArticleHarness>
9
+ <div>hello world</div>
10
+ </ArticleHarness>
11
+ );
12
+ expect(getByText('hello world'));
13
+ });
14
+ });
@@ -1,5 +1,5 @@
1
1
  import styled from 'styled-components';
2
- import { breakpoints } from '@times-components/styleguide';
2
+ import { breakpoints } from '@times-components/ts-styleguide';
3
3
 
4
4
  export const ArticlePage = styled.div`
5
5
  background-color: #f5efeb;
@@ -12,7 +12,7 @@ declare module '@times-components/icons' {
12
12
  }>;
13
13
  }
14
14
 
15
- declare module '@times-components/styleguide' {
15
+ declare module '@times-components/ts-styleguide' {
16
16
  type ColourMap = Record<string, string>;
17
17
  type Colours = Record<string, ColourMap>;
18
18
 
@@ -0,0 +1,20 @@
1
+ type MockCallbackType = (props: Array<{ isIntersecting: boolean }>) => {};
2
+
3
+ class FakeIntersectionObserver {
4
+ static callback: MockCallbackType;
5
+ static observe = jest.fn();
6
+ static disconnect = jest.fn();
7
+
8
+ static intersect(isIntersecting = true): void {
9
+ FakeIntersectionObserver.callback([{ isIntersecting }]);
10
+ }
11
+
12
+ observe = FakeIntersectionObserver.observe;
13
+ disconnect = FakeIntersectionObserver.disconnect;
14
+
15
+ constructor(callback: MockCallbackType) {
16
+ FakeIntersectionObserver.callback = callback;
17
+ }
18
+ }
19
+
20
+ export default FakeIntersectionObserver;
@@ -0,0 +1,49 @@
1
+ import 'react';
2
+ import '@testing-library/react';
3
+
4
+ import { convertChannelSlice } from '../convertChannelSlice';
5
+
6
+ describe('convertChannelSlice(', () => {
7
+ const mockData = {
8
+ name: 'slice',
9
+ children: [
10
+ {
11
+ article: {
12
+ headline: 'a headline',
13
+ images: {
14
+ alt: 'image alt text',
15
+ crops: [{ ratio: '3:2', url: 'https://dummyimage.com/300' }]
16
+ }
17
+ }
18
+ }
19
+ ]
20
+ };
21
+
22
+ it('should convert channel slice', () => {
23
+ expect(convertChannelSlice('channel name', mockData)).toEqual({
24
+ children: [
25
+ {
26
+ article: {
27
+ headline: 'a headline',
28
+ images: {
29
+ alt: 'image alt text',
30
+ crops: [
31
+ {
32
+ ratio: '3:2',
33
+ url: 'https://dummyimage.com/300'
34
+ }
35
+ ]
36
+ },
37
+ label: ''
38
+ }
39
+ }
40
+ ],
41
+ name: 'slice'
42
+ });
43
+ });
44
+ it('should return undefined when insufficient data is provided', () => {
45
+ expect(
46
+ convertChannelSlice('channel name', { name: 'slice', children: [{}] })
47
+ ).toEqual({ children: [{ article: undefined }], name: 'slice' });
48
+ });
49
+ });
@@ -0,0 +1,69 @@
1
+ import { getSliceComponent } from '../getSlice';
2
+ import Lead1 from '../../components/slices/Lead1/Lead1';
3
+ import Lead1And1 from '../../components/slices/Lead1And1/Lead1And1';
4
+ import Lead1And2 from '../../components/slices/Lead1And2/Lead1And2';
5
+ import Lead1And3Reversed from '../../components/slices/Lead1And3Reversed/Lead1And3Reversed';
6
+ import Lead2 from '../../components/slices/Lead2/Lead2';
7
+ import Secondary2And2 from '../../components/slices/Secondary2And2/Secondary2And2';
8
+ import Secondary2And3 from '../../components/slices/Secondary2And3/Secondary2And3';
9
+ import Secondary2And3NoPic from '../../components/slices/Secondary2And3NoPic/Secondary2And3NoPic';
10
+ import Secondary3 from '../../components/slices/Secondary3/Secondary3';
11
+ import Secondary4 from '../../components/slices/Secondary4/Secondary4';
12
+ import Secondary4Odd from '../../components/slices/Secondary4Odd/Secondary4Odd';
13
+ import Secondary10 from '../../components/slices/Secondary10/Secondary10';
14
+ import RelatedArticle1 from '../../components/slices/RelatedArticle1/RelatedArticle1';
15
+
16
+ describe('getSlice()', () => {
17
+ it('should render null when not able to find slice', () => {
18
+ expect(getSliceComponent('RELATED_ARTICLE_1000')).not.toBe;
19
+ });
20
+
21
+ it('should render RelatedArticle1 when it is called', () => {
22
+ expect(getSliceComponent('RELATED_ARTICLE_1')).toEqual(RelatedArticle1);
23
+ });
24
+ it('should render Secondary4Odd when it is called', () => {
25
+ expect(getSliceComponent('SECONDARY_4_ODD')).toEqual(Secondary4Odd);
26
+ });
27
+ it('should render Secondary10 when it is called', () => {
28
+ expect(getSliceComponent('SECONDARY_10')).toEqual(Secondary10);
29
+ });
30
+ it('should render Secondary4 when it is called', () => {
31
+ expect(getSliceComponent('SECONDARY_4')).toEqual(Secondary4);
32
+ });
33
+ it('should render Secondary3 when it is called', () => {
34
+ expect(getSliceComponent('SECONDARY_3')).toEqual(Secondary3);
35
+ });
36
+ it('should render Secondary2And3NoPic when it is called', () => {
37
+ expect(getSliceComponent('SECONDARY_2_AND_3_NO_PIC')).toEqual(
38
+ Secondary2And3NoPic
39
+ );
40
+ });
41
+ it('should render Secondary2And3 when it is called', () => {
42
+ expect(getSliceComponent('SECONDARY_2_AND_3')).toEqual(Secondary2And3);
43
+ });
44
+ it('should render Secondary2And2 when it is called', () => {
45
+ expect(getSliceComponent('SECONDARY_2_AND_2')).toEqual(Secondary2And2);
46
+ });
47
+
48
+ it('should render Lead2 when it is called', () => {
49
+ expect(getSliceComponent('LEAD_2')).toEqual(Lead2);
50
+ });
51
+
52
+ it('should render Lead1And3Reversed when it is called', () => {
53
+ expect(getSliceComponent('LEAD_1_AND_3_REVERSED')).toEqual(
54
+ Lead1And3Reversed
55
+ );
56
+ });
57
+
58
+ it('should render Lead1And2 when it is called', () => {
59
+ expect(getSliceComponent('LEAD_1_AND_2_COLUMNIST')).toEqual(Lead1And2);
60
+ });
61
+
62
+ it('should render Lead1 when it is called', () => {
63
+ expect(getSliceComponent('LEAD_1')).toEqual(Lead1);
64
+ });
65
+
66
+ it('should render Lead1And1 when it is called', () => {
67
+ expect(getSliceComponent('LEAD_1_AND_1_COMPONENT')).toEqual(Lead1And1);
68
+ });
69
+ });