@newskit-render/core 1.54.0 → 1.66.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 (44) hide show
  1. package/CHANGELOG.md +291 -0
  2. package/__pacts__/spec/newskitApi.consumer.pact.ts +19 -32
  3. package/__tests__/pages/[articleSlug].test.tsx +6 -8
  4. package/__tests__/pages/__snapshots__/brightcove.test.tsx.snap +20 -0
  5. package/__tests__/pages/__snapshots__/home.test.tsx.snap +139 -139
  6. package/__tests__/pages/brightcove.test.tsx +34 -0
  7. package/__tests__/pages/home.test.tsx +22 -18
  8. package/__tests__/pages/mocks.ts +29 -0
  9. package/__tests__/pages/relatedArticles.test.tsx +76 -0
  10. package/components/article/RelatedArticles.tsx +48 -55
  11. package/components/article/__tests__/__snapshots__/index.test.tsx.snap +305 -308
  12. package/components/article/__tests__/index.test.tsx +46 -2
  13. package/components/article/index.tsx +28 -15
  14. package/components/footer/__snapshots__/index.test.tsx.snap +29 -29
  15. package/components/section/layouts/Rows.tsx +36 -17
  16. package/components/section/layouts/__tests__/Rows.test.tsx +12 -0
  17. package/components/section/layouts/__tests__/__snapshots__/Lead.test.tsx.snap +17 -17
  18. package/components/section/layouts/__tests__/__snapshots__/SectionTitle.test.tsx.snap +23 -23
  19. package/components/section/layouts/types.ts +3 -0
  20. package/config/index.ts +85 -0
  21. package/constants/index.ts +3 -1
  22. package/cypress/e2e/account/accessibility.spec.js +14 -17
  23. package/helpers/logger.ts +3 -1
  24. package/helpers/mocks/articleMock.ts +1 -1
  25. package/helpers/mocks/getUniversalArticleMock.ts +13 -0
  26. package/infrastructure/helm/values-dev.yaml +1 -1
  27. package/infrastructure/helm/values-pr.yaml +1 -1
  28. package/infrastructure/helm/values-prod.yaml +1 -1
  29. package/jest.config.js +1 -0
  30. package/package.json +11 -11
  31. package/pages/[section]/[articleId]/[articleSlug].tsx +9 -4
  32. package/pages/[section]/[articleId]/relatedArticles.tsx +85 -0
  33. package/pages/_app.tsx +5 -3
  34. package/pages/_document.tsx +17 -18
  35. package/pages/api/auth/[...nextauth].ts +2 -3
  36. package/pages/api/feed.ts +3 -5
  37. package/pages/api/news-sitemap.ts +4 -6
  38. package/pages/api/sitemap.ts +10 -7
  39. package/pages/index.tsx +1 -0
  40. package/pages/player/brightcove.tsx +19 -0
  41. package/pages/preview/[articleId]/version/[versionId]/index.tsx +9 -4
  42. package/queries/getRadioPosts.ts +1 -1
  43. package/queries/getUniversalArticle.ts +13 -0
  44. package/temp/header.tsx +7 -0
@@ -0,0 +1,34 @@
1
+ import { useRouter } from 'next/router'
2
+ import { renderWithTheme } from '../../helpers/test-utils'
3
+ import BrightcovePlayer from '../../pages/player/brightcove'
4
+
5
+ jest.mock('next/router', () => {
6
+ return {
7
+ useRouter: jest.fn(),
8
+ }
9
+ })
10
+
11
+ const useRouterMock = useRouter as jest.Mock
12
+
13
+ describe('Brightcove page tests', () => {
14
+ test('render page', () => {
15
+ useRouterMock.mockImplementationOnce(() => ({
16
+ query: {
17
+ account_id: 'account_id_test',
18
+ player_id: 'player_id_test',
19
+ post_id: 'post_id_test',
20
+ video_id: 'video_id_test',
21
+ },
22
+ }))
23
+
24
+ const { asFragment, getByTestId } = renderWithTheme(BrightcovePlayer)
25
+
26
+ const videoPlayer = getByTestId('bc-video-player')
27
+
28
+ expect(videoPlayer).toBeInTheDocument()
29
+ expect(videoPlayer.getAttribute('data-account')).toEqual('account_id_test')
30
+ expect(videoPlayer.getAttribute('data-video-id')).toEqual('video_id_test')
31
+
32
+ expect(asFragment()).toMatchSnapshot()
33
+ })
34
+ })
@@ -3,16 +3,6 @@ import SectionPage from '../../components/section'
3
3
  import { renderWithTheme } from '../../helpers/test-utils'
4
4
  import { getPageMock } from '../../helpers/mocks'
5
5
 
6
- jest.mock('../../helpers/getYear', () => ({
7
- getYear: jest.fn().mockReturnValue('YYYY'),
8
- }))
9
-
10
- jest.mock('newrelic', () => {
11
- return {
12
- setTransactionName: jest.fn(),
13
- }
14
- })
15
-
16
6
  const user = {
17
7
  paymentFailure: {
18
8
  active: false,
@@ -21,6 +11,20 @@ const user = {
21
11
  subscriptions: [{ endDate: null }],
22
12
  }
23
13
 
14
+ jest.mock('newrelic', () => {
15
+ return {
16
+ setTransactionName: jest.fn(),
17
+ }
18
+ })
19
+
20
+ jest.mock('cross-fetch', () =>
21
+ jest.fn().mockImplementation(() =>
22
+ Promise.resolve({
23
+ json: () => Promise.resolve(user),
24
+ })
25
+ )
26
+ )
27
+
24
28
  jest.mock('@newskit-render/api', () => ({
25
29
  ClientTypes: { nkapi: 'nkapi' },
26
30
  createApolloClient: jest.fn().mockImplementation(() => {
@@ -40,20 +44,20 @@ jest.mock('@newskit-render/api', () => ({
40
44
  getAcsCookie: jest.fn().mockReturnValue({ Cookie: 'something' }),
41
45
  }))
42
46
 
43
- jest.mock('cross-fetch', () =>
44
- jest.fn().mockImplementation(() =>
45
- Promise.resolve({
46
- json: () => Promise.resolve(user),
47
- })
48
- )
49
- )
50
-
51
47
  jest.mock('@newskit-render/my-account', () => {
52
48
  return {
53
49
  PastDueBannerExternal: 'PastDueBannerExternal',
54
50
  }
55
51
  })
56
52
 
53
+ jest.mock('../../config', () => ({
54
+ getSanitzedConfig: jest.fn().mockImplementation(() => {}),
55
+ }))
56
+
57
+ jest.mock('../../helpers/getYear', () => ({
58
+ getYear: jest.fn().mockReturnValue('YYYY'),
59
+ }))
60
+
57
61
  describe('getServerSideProps', () => {
58
62
  test('Homepage', () => {
59
63
  const { asFragment } = renderWithTheme(SectionPage, {
@@ -0,0 +1,29 @@
1
+ import { Article } from '@newskit-render/standalone-components'
2
+
3
+ test.skip('Workaround', () => 1)
4
+
5
+ export const mockArticles: Article[] = [
6
+ {
7
+ href:
8
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/image-656eaa885d.jpg?strip=all&w=600&h=338&crop=1',
9
+ tag: 'FOOT ON THE GAZ',
10
+ text:
11
+ 'Bale considering short deal with new club before RETIRING after World Cup',
12
+ title: 'FOOT ON THE GAZ',
13
+ },
14
+ {
15
+ href:
16
+ 'https://www.thesun.co.uk/wp-content/uploads/2022/03/image-a21f115694-1.jpg?strip=all&w=600&h=338&crop=1',
17
+ tag: 'TOUGH TIMES',
18
+ text:
19
+ 'I only made £5k last year - I sold £801k villa for cash, says Claire Sweeney',
20
+ title: 'TOUGH TIMES',
21
+ },
22
+ {
23
+ href: null,
24
+ tag: 'TOUGH TIMES',
25
+ text:
26
+ 'I only made £5k last year - I sold £801k villa for cash, says Claire Sweeney',
27
+ title: 'TOUGH TIMES',
28
+ },
29
+ ]
@@ -0,0 +1,76 @@
1
+ import { recommendationsProvider } from '@newskit-render/standalone-components'
2
+ import {
3
+ RelatedArticles,
4
+ getServerSideProps,
5
+ } from '../../pages/[section]/[articleId]/relatedArticles'
6
+ import { mockArticles } from './mocks'
7
+
8
+ const props: RelatedArticles = {
9
+ recommendations: mockArticles,
10
+ }
11
+
12
+ const user = {
13
+ paymentFailure: {
14
+ active: false,
15
+ startDate: null,
16
+ },
17
+ subscriptions: [{ endDate: null }],
18
+ }
19
+
20
+ jest.mock('newrelic', () => {
21
+ return {
22
+ setTransactionName: jest.fn(),
23
+ }
24
+ })
25
+
26
+ jest.mock('cross-fetch', () =>
27
+ jest.fn().mockImplementation(() =>
28
+ Promise.resolve({
29
+ json: () => Promise.resolve(user),
30
+ })
31
+ )
32
+ )
33
+
34
+ jest.mock('@newskit-render/api', () => ({
35
+ ClientTypes: { nkapi: 'nkapi' },
36
+ getAcsCookie: jest.fn().mockReturnValue({ Cookie: 'something' }),
37
+ Publisher: {
38
+ SUN_UK: 'SUN_UK',
39
+ },
40
+ }))
41
+
42
+ jest.mock('@newskit-render/standalone-components', () => {
43
+ return {
44
+ recommendationsProvider: jest.fn(),
45
+ }
46
+ })
47
+
48
+ describe('Article', () => {
49
+ describe('getServerSideProps', () => {
50
+ beforeAll(() => {
51
+ process.env = Object.assign(process.env, {
52
+ SITE_HOST: 'hostname',
53
+ TWITTER_USERNAME: 'D_Trump',
54
+ GSC_ID: '4320982',
55
+ })
56
+ recommendationsProvider.mockResolvedValueOnce(mockArticles)
57
+ })
58
+
59
+ it('should return props', async () => {
60
+ const setHeaderMock = jest.fn()
61
+
62
+ const response = await getServerSideProps({
63
+ params: {
64
+ articleId: 'test-1',
65
+ },
66
+ req: { headers: { cookie: 'some-cookie' } },
67
+ res: { setHeader: setHeaderMock },
68
+ })
69
+ expect(response).toEqual({ props: { ...props, showAds: true, user } })
70
+ expect(setHeaderMock).toHaveBeenCalledWith(
71
+ 'Cache-Control',
72
+ 'public, s-maxage=10, stale-while-revalidate=59'
73
+ )
74
+ })
75
+ })
76
+ })
@@ -1,22 +1,16 @@
1
- import React from 'react'
1
+ import React, { ComponentType } from 'react'
2
2
  import {
3
3
  Block,
4
4
  TitleBar,
5
- Grid,
6
- TextBlock,
7
- Cell,
8
- Card,
9
5
  Stack,
10
6
  StackChild,
11
7
  AlignSelfValues,
12
8
  Divider,
13
- Headline,
14
9
  Visible,
15
10
  } from 'newskit'
16
- import { ArticleRecommendation } from '@newskit-render/standalone-components'
11
+ import { useRouter } from 'next/router'
17
12
  import ViewMoreButton from '../common/ViewMoreButton'
18
-
19
- const viewMoreButton = () => <ViewMoreButton href="/" />
13
+ import { BasicRow } from '../section/layouts'
20
14
 
21
15
  const RelatedArticles: React.FC<{
22
16
  relatedArticles: {
@@ -25,54 +19,53 @@ const RelatedArticles: React.FC<{
25
19
  text: string
26
20
  href: string
27
21
  }[]
28
- }> = ({ relatedArticles }) => (
29
- <Block data-testid="RelatedArticles">
30
- <Block spaceStack="space080">
31
- <TitleBar
32
- overrides={{
33
- spaceInset: {
34
- xs: 'spaceInsetSquish000',
35
- },
36
- heading: {
37
- typographyPreset: {
38
- xs: 'editorialHeadline050',
39
- md: 'editorialHeadline060',
40
- xl: 'editorialHeadline070',
41
- },
42
- stylePreset: 'inkContrast',
43
- },
44
- }}
45
- actionItem={viewMoreButton}
46
- >
47
- Related
48
- </TitleBar>
49
- </Block>
22
+ }> = ({ relatedArticles }) => {
23
+ const { asPath } = useRouter()
24
+ const relatedArticlesPath = `${asPath.substring(
25
+ 0,
26
+ asPath.lastIndexOf('/')
27
+ )}/relatedArticles`
50
28
 
51
- <Grid xsMargin="space000">
52
- {relatedArticles.map((article) => (
53
- <Cell
54
- key={article.title}
55
- xs={12}
56
- sm={6}
57
- lg={3}
58
- data-testid="RelatedArticlesVerticalCard"
29
+ return (
30
+ <Block data-testid="RelatedArticles">
31
+ <Block spaceStack="space080">
32
+ <TitleBar
33
+ overrides={{
34
+ spaceInset: {
35
+ xs: 'spaceInsetSquish000',
36
+ },
37
+ heading: {
38
+ typographyPreset: {
39
+ xs: 'editorialHeadline050',
40
+ md: 'editorialHeadline060',
41
+ xl: 'editorialHeadline070',
42
+ },
43
+ stylePreset: 'inkContrast',
44
+ },
45
+ }}
46
+ actionItem={() => <ViewMoreButton href={relatedArticlesPath} />}
59
47
  >
60
- <ArticleRecommendation article={article} size="large" />
61
- </Cell>
62
- ))}
63
- <Cell xs={12}>
64
- <Visible xs lg>
48
+ Related
49
+ </TitleBar>
50
+ </Block>
51
+
52
+ <BasicRow
53
+ data-testid="RelatedArticlesVerticalCard"
54
+ colums={{ xs: '1fr', sm: '1fr 1fr', lg: '1fr 1fr 1fr 1fr' }}
55
+ articles={relatedArticles}
56
+ />
57
+
58
+ <Visible xs lg>
59
+ <Divider />
60
+ <Stack>
61
+ <StackChild alignSelf={AlignSelfValues.Center}>
62
+ <ViewMoreButton href={relatedArticlesPath} />
63
+ </StackChild>
65
64
  <Divider />
66
- <Stack>
67
- <StackChild alignSelf={AlignSelfValues.Center}>
68
- <ViewMoreButton href="/" />
69
- </StackChild>
70
- <Divider />
71
- </Stack>
72
- </Visible>
73
- </Cell>
74
- </Grid>
75
- </Block>
76
- )
65
+ </Stack>
66
+ </Visible>
67
+ </Block>
68
+ )
69
+ }
77
70
 
78
71
  export default RelatedArticles