Skip to content

Commit

Permalink
Merge branch 'latest' into replicate-av-embeds-cache-control
Browse files Browse the repository at this point in the history
  • Loading branch information
amoore108 authored Aug 19, 2024
2 parents 43f7d77 + b204256 commit 6556e9d
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 111 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/cache/fsevents-patch-6b67494872-10.zip
Binary file not shown.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"eslint-config-airbnb": "18.2.1",
"eslint-config-prettier": "9.1.0",
"eslint-import-resolver-alias": "1.1.2",
"eslint-plugin-cypress": "3.2.0",
"eslint-plugin-cypress": "3.5.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-json": "4.0.0",
"eslint-plugin-jsx-a11y": "6.8.0",
Expand All @@ -220,7 +220,6 @@
"eslint-plugin-react-hooks": "4.6.2",
"fetch-mock": "9.11.0",
"glob": "10.4.1",
"history": "4.10.1",
"husky": "9.0.11",
"inspectpack": "4.7.1",
"jest": "29.7.0",
Expand Down
147 changes: 45 additions & 102 deletions src/app/legacy/containers/PageHandlers/withVariant/index.test.jsx
Original file line number Diff line number Diff line change
@@ -1,127 +1,70 @@
import React from 'react';
import { Router, Route } from 'react-router-dom';
import { render } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import { MemoryRouter, Route } from 'react-router-dom';
import { frontPagePath } from '#app/routes/utils/regex';
import { render } from '../../../../components/react-testing-library-with-providers';
import WithVariant from '.';

jest.mock('react-router-dom', () => {
return {
...jest.requireActual('react-router-dom'),
Redirect: jest.fn(({ to }) => `Redirected to ${to}`),
};
});

describe('WithVariant', () => {
const Component = () => <h1>This is the BBC.</h1>;
const Component = ({ service }) => <p>This is BBC {service}</p>;
const ComponentWithVariantRedirect = WithVariant(Component);

const getMatchProps = (service, path = null) => ({
path: path || frontPagePath,
params: {
service,
},
});

describe('service with no default variant', () => {
it('should not redirect', () => {
const service = 'news';
const match = getMatchProps(service);
const history = createMemoryHistory({
initialEntries: [`/${service}`],
});

expect(history.location.pathname).toEqual(`/${service}`);

render(
<Router history={history}>
<Route path="/:service">
<ComponentWithVariantRedirect match={match} service={service} />
</Route>
</Router>,
);

expect(history.location.pathname).toEqual('/news');
});
});

describe('service (ukchina) with default variant', () => {
it('should redirect to ukchina/simp', () => {
const service = 'ukchina';
const match = getMatchProps(service);
const history = createMemoryHistory({
initialEntries: [`/${service}`],
});

expect(history.location.pathname).toEqual(`/${service}`);

render(
<Router history={history}>
<Route path="/:service">
<ComponentWithVariantRedirect match={match} service={service} />
</Route>
</Router>,
);

expect(history.location.pathname).toEqual('/ukchina/simp');
});
});

describe('service (zhongwen) with default variant', () => {
it('should redirect to zhongwen/simp', () => {
const service = 'zhongwen';
describe('services without variants', () => {
it.each`
service
${'news'}
${'uzbek'}
`('should render the /$service page', ({ service }) => {
const match = getMatchProps(service);
const history = createMemoryHistory({
initialEntries: [`/${service}`],
});

expect(history.location.pathname).toEqual(`/${service}`);

render(
<Router history={history}>
const { queryByText } = render(
<MemoryRouter initialEntries={[`/${service}`]}>
<Route path="/:service">
<ComponentWithVariantRedirect match={match} service={service} />
</Route>
</Router>,
</MemoryRouter>,
);

expect(history.location.pathname).toEqual('/zhongwen/simp');
expect(queryByText(`This is BBC ${service}`).toBeInTheDocument);
expect(queryByText(`Redirected to ${service}`)).not.toBeInTheDocument();
});
});

describe('service (serbian) with default variant', () => {
it('should redirect to serbian/lat', () => {
const service = 'serbian';
const match = getMatchProps(service);
const history = createMemoryHistory({
initialEntries: [`/${service}`],
});

expect(history.location.pathname).toEqual(`/${service}`);

render(
<Router history={history}>
<Route path="/:service">
<ComponentWithVariantRedirect match={match} service={service} />
</Route>
</Router>,
);

expect(history.location.pathname).toEqual('/serbian/lat');
});
});

describe('service (uzbek) with default variant', () => {
it('should not redirect', () => {
const service = 'uzbek';
const match = getMatchProps(service);
const history = createMemoryHistory({
initialEntries: [`/${service}`],
});

expect(history.location.pathname).toEqual(`/${service}`);

render(
<Router history={history}>
<Route path="/:service">
<ComponentWithVariantRedirect match={match} service={service} />
</Route>
</Router>,
);

expect(history.location.pathname).toEqual('/uzbek');
});
describe('services with default variants', () => {
it.each`
service | redirect
${'serbian'} | ${'/serbian/lat'}
${'ukchina'} | ${'/ukchina/simp'}
${'zhongwen'} | ${'/zhongwen/simp'}
`(
'should redirect from /$service to $redirect',
({ service, redirect }) => {
const match = getMatchProps(service);

const { queryByText } = render(
<MemoryRouter initialEntries={[`/${service}`]}>
<Route path="/:service">
<ComponentWithVariantRedirect match={match} service={service} />
</Route>
</MemoryRouter>,
);

expect(queryByText(`This is BBC ${service}`)).not.toBeInTheDocument();
expect(queryByText(`Redirected to ${redirect}`)).toBeInTheDocument();
},
);
});
});
13 changes: 6 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9431,14 +9431,14 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-cypress@npm:3.2.0":
version: 3.2.0
resolution: "eslint-plugin-cypress@npm:3.2.0"
"eslint-plugin-cypress@npm:3.5.0":
version: 3.5.0
resolution: "eslint-plugin-cypress@npm:3.5.0"
dependencies:
globals: "npm:^13.20.0"
peerDependencies:
eslint: ">=7"
checksum: 10/22e9450ddf989bfcfa2d71df2557afc0c0305ba9d5b418cebb8a82c188abbfc83c0619f2ff44c7132f83331e3a3ddd8563f9f834bd0e61e21eb0f213842dbb79
checksum: 10/c7797902d76331e4b243f8c97c8ecde451e6959af6ec54c07faf54e095ad64e64a588dc3bb466cb172f63219ea07fd6efb2bcb6ae63a64dd9c067edbd222327e
languageName: node
linkType: hard

Expand Down Expand Up @@ -10930,7 +10930,7 @@ __metadata:
languageName: node
linkType: hard

"history@npm:4.10.1, history@npm:^4.9.0":
"history@npm:^4.9.0":
version: 4.10.1
resolution: "history@npm:4.10.1"
dependencies:
Expand Down Expand Up @@ -16273,7 +16273,7 @@ __metadata:
eslint-config-airbnb: "npm:18.2.1"
eslint-config-prettier: "npm:9.1.0"
eslint-import-resolver-alias: "npm:1.1.2"
eslint-plugin-cypress: "npm:3.2.0"
eslint-plugin-cypress: "npm:3.5.0"
eslint-plugin-import: "npm:2.29.1"
eslint-plugin-json: "npm:4.0.0"
eslint-plugin-jsx-a11y: "npm:6.8.0"
Expand All @@ -16287,7 +16287,6 @@ __metadata:
glob: "npm:10.4.1"
helmet: "npm:7.1.0"
helmet-csp: "npm:3.4.0"
history: "npm:4.10.1"
husky: "npm:9.0.11"
inspectpack: "npm:4.7.1"
intersection-observer: "npm:0.12.2"
Expand Down

0 comments on commit 6556e9d

Please sign in to comment.