-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'latest' into replicate-av-embeds-cache-control
- Loading branch information
Showing
9 changed files
with
52 additions
and
111 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+38.8 MB
...inux-x64-gnu-npm-14.2.5-cc62fe9948-10.zip → ...darwin-arm64-npm-14.2.5-30baab3764-10.zip
Binary file not shown.
Binary file removed
BIN
-32.5 KB
.yarn/cache/eslint-plugin-cypress-npm-3.2.0-fe6d901dde-22e9450ddf.zip
Binary file not shown.
Binary file added
BIN
+42.6 KB
.yarn/cache/eslint-plugin-cypress-npm-3.5.0-f6a2cc23ee-c7797902d7.zip
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 45 additions & 102 deletions
147
src/app/legacy/containers/PageHandlers/withVariant/index.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters