Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No mocked Config context provider #8896

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions dotcom-rendering/scripts/jest/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,3 @@ global.TextDecoder = TextDecoder as unknown as typeof global.TextDecoder;

// Mocks the version number used by CDK, we don't want our tests to fail every time we update our cdk dependency.
jest.mock('@guardian/cdk/lib/constants/tracking-tag');

// Mocks the useConfig hook in ConfigContext, so that we don't have to use the provider all the time
jest.mock('../../src/components/ConfigContext.tsx', () => {
const mockConfig = { renderingTarget: 'Web' };
return {
...jest.requireActual('../../src/components/ConfigContext.tsx'),
useConfig: () => mockConfig,
};
});
85 changes: 45 additions & 40 deletions dotcom-rendering/src/components/ArticleMeta.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ArticleDesign, ArticleDisplay, Pillar } from '@guardian/libs';
import { render } from '@testing-library/react';
import { interactiveLegacyClasses } from '../layouts/lib/interactiveLegacyStyling';
import { ArticleMeta } from './ArticleMeta';
import { ConfigProvider } from './ConfigContext';

jest.mock('../lib/bridgetApi', () => jest.fn());

Expand All @@ -14,26 +15,28 @@ describe('ArticleMeta', () => {
};

const { container } = render(
<ArticleMeta
format={format}
pageId="1234"
webTitle="A title"
byline="Observer writers"
tags={[
{
id: 'lifeandstyle/series/observer-design',
type: 'Series',
title: 'Observer Design',
},
]}
primaryDateline="primary date line"
secondaryDateline="secondary date line"
isCommentable={false}
discussionApiUrl=""
shortUrlId=""
ajaxUrl=""
showShareCount={true}
/>,
<ConfigProvider value={{ renderingTarget: 'Web' }}>
<ArticleMeta
format={format}
pageId="1234"
webTitle="A title"
byline="Observer writers"
tags={[
{
id: 'lifeandstyle/series/observer-design',
type: 'Series',
title: 'Observer Design',
},
]}
primaryDateline="primary date line"
secondaryDateline="secondary date line"
isCommentable={false}
discussionApiUrl=""
shortUrlId=""
ajaxUrl=""
showShareCount={true}
/>
</ConfigProvider>,
);

expect(
Expand All @@ -54,26 +57,28 @@ describe('ArticleMeta', () => {
};

const { container } = render(
<ArticleMeta
format={format}
pageId="1234"
webTitle="A title"
byline="Observer writers"
tags={[
{
id: 'lifeandstyle/series/observer-design',
type: 'Series',
title: 'Observer Design',
},
]}
primaryDateline="primary date line"
secondaryDateline="secondary date line"
isCommentable={false}
discussionApiUrl=""
shortUrlId=""
ajaxUrl=""
showShareCount={true}
/>,
<ConfigProvider value={{ renderingTarget: 'Web' }}>
<ArticleMeta
format={format}
pageId="1234"
webTitle="A title"
byline="Observer writers"
tags={[
{
id: 'lifeandstyle/series/observer-design',
type: 'Series',
title: 'Observer Design',
},
]}
primaryDateline="primary date line"
secondaryDateline="secondary date line"
isCommentable={false}
discussionApiUrl=""
shortUrlId=""
ajaxUrl=""
showShareCount={true}
/>
</ConfigProvider>,
);

expect(
Expand Down
61 changes: 34 additions & 27 deletions dotcom-rendering/src/components/BylineLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
BylineLink,
SPECIAL_REGEX_CHARACTERS,
} from './BylineLink';
import { ConfigProvider } from './ConfigContext';

jest.mock('../lib/bridgetApi', jest.fn());

Expand Down Expand Up @@ -103,15 +104,17 @@ describe('BylineLink', () => {
];

const { container } = render(
<BylineLink
byline={byline}
tags={tags}
format={{
display: ArticleDisplay.Standard,
design: ArticleDesign.Standard,
theme: Pillar.News,
}}
/>,
<ConfigProvider value={{ renderingTarget: 'Web' }}>
<BylineLink
byline={byline}
tags={tags}
format={{
display: ArticleDisplay.Standard,
design: ArticleDesign.Standard,
theme: Pillar.News,
}}
/>
</ConfigProvider>,
);

const links = container.querySelectorAll('a');
Expand All @@ -136,15 +139,17 @@ describe('BylineLink', () => {
},
];
const { container } = render(
<BylineLink
byline={byline}
tags={tags}
format={{
display: ArticleDisplay.Standard,
design: ArticleDesign.Standard,
theme: Pillar.News,
}}
/>,
<ConfigProvider value={{ renderingTarget: 'Web' }}>
<BylineLink
byline={byline}
tags={tags}
format={{
display: ArticleDisplay.Standard,
design: ArticleDesign.Standard,
theme: Pillar.News,
}}
/>
</ConfigProvider>,
);

const links = container.querySelectorAll('a');
Expand All @@ -171,15 +176,17 @@ describe('BylineLink', () => {
];

const { container } = render(
<BylineLink
byline={byline}
tags={tags}
format={{
display: ArticleDisplay.Standard,
design: ArticleDesign.Standard,
theme: Pillar.News,
}}
/>,
<ConfigProvider value={{ renderingTarget: 'Web' }}>
<BylineLink
byline={byline}
tags={tags}
format={{
display: ArticleDisplay.Standard,
design: ArticleDesign.Standard,
theme: Pillar.News,
}}
/>
</ConfigProvider>,
);

const links = container.querySelectorAll('a');
Expand Down
7 changes: 2 additions & 5 deletions dotcom-rendering/src/components/ConfigContext.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { render } from '@testing-library/react';

// This file is globally mocked in "/dotcom-rendering/scripts/jest/setup.ts"
// so we need to explicitly override this in order to test its functionality
const { useConfig, ConfigProvider } = jest.requireActual('./ConfigContext.tsx');
import { ConfigProvider, useConfig } from './ConfigContext';

const testId = 'testId';
const TestComponent = () => {
Expand All @@ -22,7 +19,7 @@ describe('ConfigContext', () => {
});

describe('with ConfigProvider', () => {
it.each(['Web', 'Apps'])(
it.each(['Web', 'Apps'] as const)(
'provides correct context through useConfig hook with renderingTarget: "%s"',
(renderingTarget) => {
const config = { renderingTarget };
Expand Down
49 changes: 27 additions & 22 deletions dotcom-rendering/src/components/Contributor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ArticleDesign, ArticleDisplay, Pillar } from '@guardian/libs';
import { render } from '@testing-library/react';
import { interactiveLegacyClasses } from '../layouts/lib/interactiveLegacyStyling';
import { ConfigProvider } from './ConfigContext';
import { Contributor } from './Contributor';

jest.mock('../lib/bridgetApi', () => jest.fn());
Expand All @@ -14,17 +15,19 @@ describe('Contributor', () => {
};

const { container } = render(
<Contributor
format={format}
byline="Observer writers"
tags={[
{
id: 'lifeandstyle/series/observer-design',
type: 'Series',
title: 'Observer Design',
},
]}
/>,
<ConfigProvider value={{ renderingTarget: 'Web' }}>
<Contributor
format={format}
byline="Observer writers"
tags={[
{
id: 'lifeandstyle/series/observer-design',
type: 'Series',
title: 'Observer Design',
},
]}
/>
</ConfigProvider>,
);

expect(
Expand All @@ -40,17 +43,19 @@ describe('Contributor', () => {
};

const { container } = render(
<Contributor
format={format}
byline="Observer writers"
tags={[
{
id: 'lifeandstyle/series/observer-design',
type: 'Series',
title: 'Observer Design',
},
]}
/>,
<ConfigProvider value={{ renderingTarget: 'Web' }}>
<Contributor
format={format}
byline="Observer writers"
tags={[
{
id: 'lifeandstyle/series/observer-design',
type: 'Series',
title: 'Observer Design',
},
]}
/>
</ConfigProvider>,
);

expect(
Expand Down
Loading