@newskit-render/core 1.50.1 → 1.63.2
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 +324 -0
- package/__pacts__/spec/newskitApi.consumer.pact.ts +19 -32
- package/__tests__/pages/[articleSlug].test.tsx +12 -8
- package/__tests__/pages/__snapshots__/brightcove.test.tsx.snap +20 -0
- package/__tests__/pages/__snapshots__/home.test.tsx.snap +241 -1846
- package/__tests__/pages/brightcove.test.tsx +34 -0
- package/__tests__/pages/home.test.tsx +22 -12
- package/__tests__/pages/mocks.ts +29 -0
- package/__tests__/pages/relatedArticles.test.tsx +76 -0
- package/components/article/RelatedArticles.tsx +48 -55
- package/components/article/__tests__/__snapshots__/index.test.tsx.snap +414 -3366
- package/components/article/__tests__/index.test.tsx +46 -2
- package/components/article/index.tsx +28 -15
- package/components/footer/__snapshots__/index.test.tsx.snap +37 -271
- package/components/header/index.tsx +7 -0
- package/components/section/layouts/Rows.tsx +36 -17
- package/components/section/layouts/__tests__/Rows.test.tsx +12 -0
- package/components/section/layouts/__tests__/__snapshots__/Lead.test.tsx.snap +36 -530
- package/components/section/layouts/__tests__/__snapshots__/SectionTitle.test.tsx.snap +42 -766
- package/components/section/layouts/types.ts +3 -0
- package/config/index.ts +85 -0
- package/constants/index.ts +3 -1
- package/cypress/e2e/account/accessibility.spec.js +14 -17
- package/cypress/e2e/account/account-subscription.spec.js +9 -8
- package/cypress/e2e/account/payment-failer.spec.js +3 -3
- package/cypress/support/commands.js +2 -2
- package/helpers/__tests__/getUser.test.ts +7 -8
- package/helpers/logger.ts +3 -1
- package/helpers/mocks/articleMock.ts +1 -1
- package/helpers/mocks/getUniversalArticleMock.ts +13 -0
- package/helpers/setupTests.ts +4 -0
- package/jest.config.js +22 -19
- package/package.json +11 -11
- package/pages/[section]/[articleId]/[articleSlug].tsx +9 -4
- package/pages/[section]/[articleId]/relatedArticles.tsx +85 -0
- package/pages/_app.tsx +4 -3
- package/pages/_document.tsx +17 -18
- package/pages/api/auth/[...nextauth].ts +2 -3
- package/pages/api/feed.ts +7 -3
- package/pages/api/news-sitemap.ts +4 -6
- package/pages/api/sitemap.ts +10 -7
- package/pages/help-hub/[id]/index.tsx +11 -0
- package/pages/help-hub/index.tsx +11 -0
- package/pages/index.tsx +1 -0
- package/pages/player/brightcove.tsx +19 -0
- package/pages/preview/[articleId]/version/[versionId]/index.tsx +9 -4
- package/public/icon.png +0 -0
- package/queries/getRadioPosts.ts +1 -1
- package/queries/getUniversalArticle.ts +13 -0
- 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,10 +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
6
|
const user = {
|
|
11
7
|
paymentFailure: {
|
|
12
8
|
active: false,
|
|
@@ -15,6 +11,20 @@ const user = {
|
|
|
15
11
|
subscriptions: [{ endDate: null }],
|
|
16
12
|
}
|
|
17
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
|
+
|
|
18
28
|
jest.mock('@newskit-render/api', () => ({
|
|
19
29
|
ClientTypes: { nkapi: 'nkapi' },
|
|
20
30
|
createApolloClient: jest.fn().mockImplementation(() => {
|
|
@@ -34,20 +44,20 @@ jest.mock('@newskit-render/api', () => ({
|
|
|
34
44
|
getAcsCookie: jest.fn().mockReturnValue({ Cookie: 'something' }),
|
|
35
45
|
}))
|
|
36
46
|
|
|
37
|
-
jest.mock('cross-fetch', () =>
|
|
38
|
-
jest.fn().mockImplementation(() =>
|
|
39
|
-
Promise.resolve({
|
|
40
|
-
json: () => Promise.resolve(user),
|
|
41
|
-
})
|
|
42
|
-
)
|
|
43
|
-
)
|
|
44
|
-
|
|
45
47
|
jest.mock('@newskit-render/my-account', () => {
|
|
46
48
|
return {
|
|
47
49
|
PastDueBannerExternal: 'PastDueBannerExternal',
|
|
48
50
|
}
|
|
49
51
|
})
|
|
50
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
|
+
|
|
51
61
|
describe('getServerSideProps', () => {
|
|
52
62
|
test('Homepage', () => {
|
|
53
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 {
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
61
|
-
</
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|