This repository has been archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2991 from bbc/revert-2836
Revert 2836 - Add AV embed timeout handling to MP
- Loading branch information
Showing
11 changed files
with
51 additions
and
231 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
67 changes: 21 additions & 46 deletions
67
packages/components/psammead-media-player/src/Canonical/index.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,70 +1,45 @@ | ||
import React, { useState, useRef } from 'react'; | ||
import { string, number } from 'prop-types'; | ||
import styled, { css } from 'styled-components'; | ||
import Guidance from '../Guidance'; | ||
import useTimeout from './useTimeout'; | ||
|
||
const Canonical = ({ service, src, title, placeholderSrc, timeoutMs }) => { | ||
const [hasTimedOut, setHasTimedOut] = useState(null); | ||
const iframeRef = useRef(null); | ||
|
||
useTimeout(setHasTimedOut, iframeRef, timeoutMs); | ||
import React from 'react'; | ||
import { string } from 'prop-types'; | ||
import styled from 'styled-components'; | ||
|
||
const Canonical = ({ src, title, placeholderSrc }) => { | ||
const backgroundStyle = ` | ||
background-image: url(${placeholderSrc}); | ||
background-repeat: no-repeat; | ||
background-size: contain; | ||
`; | ||
|
||
const CanonicalWrapper = styled.div` | ||
const StyledIframe = styled.iframe` | ||
border: 0; | ||
left: 0; | ||
overflow: hidden; | ||
position: absolute; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
${placeholderSrc && | ||
css` | ||
background-image: url(${placeholderSrc}); | ||
background-repeat: no-repeat; | ||
background-size: contain; | ||
`} | ||
`; | ||
|
||
const StyledIframe = styled.iframe` | ||
border: 0; | ||
height: 100%; | ||
width: 100%; | ||
${placeholderSrc ? backgroundStyle : null} | ||
`; | ||
|
||
return ( | ||
<CanonicalWrapper> | ||
{hasTimedOut ? ( | ||
<Guidance | ||
service={service} | ||
guidanceMessage="There was a problem loading this content. Please check your internet connection and try again." | ||
noJsMessage="" | ||
/> | ||
) : ( | ||
<StyledIframe | ||
ref={iframeRef} | ||
src={src} | ||
title={title} | ||
allow="autoplay; fullscreen" | ||
scrolling="no" | ||
gesture="media" | ||
allowFullScreen | ||
/> | ||
)} | ||
</CanonicalWrapper> | ||
<StyledIframe | ||
src={src} | ||
title={title} | ||
allow="autoplay; fullscreen" | ||
scrolling="no" | ||
gesture="media" | ||
allowFullScreen | ||
/> | ||
); | ||
}; | ||
|
||
Canonical.propTypes = { | ||
service: string.isRequired, | ||
src: string.isRequired, | ||
title: string.isRequired, | ||
placeholderSrc: string, | ||
timeoutMs: number, | ||
}; | ||
|
||
Canonical.defaultProps = { | ||
placeholderSrc: null, | ||
timeoutMs: 5000, | ||
}; | ||
|
||
export default Canonical; |
47 changes: 1 addition & 46 deletions
47
packages/components/psammead-media-player/src/Canonical/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,55 +1,10 @@ | ||
import React from 'react'; | ||
import { render, act, cleanup, fireEvent } from '@testing-library/react'; | ||
import { shouldMatchSnapshot } from '@bbc/psammead-test-helpers'; | ||
import Canonical from '.'; | ||
|
||
afterEach(cleanup); | ||
|
||
describe('Media Player: Canonical', () => { | ||
shouldMatchSnapshot( | ||
'should render an iframe', | ||
<Canonical | ||
src="https://foo.bar/iframe" | ||
title="Media player" | ||
service="news" | ||
/>, | ||
<Canonical src="https://foo.bar/iframe" title="Media player" />, | ||
); | ||
|
||
it('should render a timeout message if the timeout expires', () => { | ||
jest.useFakeTimers(); | ||
const { getByText } = render( | ||
<Canonical | ||
src="https://foo.bar/iframe" | ||
title="Media player" | ||
service="news" | ||
timeoutMs={2000} | ||
/>, | ||
); | ||
|
||
act(() => { | ||
jest.runTimersToTime(3000); | ||
}); | ||
|
||
expect( | ||
getByText( | ||
'There was a problem loading this content. Please check your internet connection and try again.', | ||
), | ||
); | ||
}); | ||
|
||
it('should not render a timeout message if it loads successfully', () => { | ||
const { getByTitle, getByText } = render( | ||
<Canonical | ||
src="https://foo.bar/iframe" | ||
title="Media player" | ||
service="news" | ||
/>, | ||
); | ||
fireEvent.load(getByTitle('Media player')); | ||
expect(() => | ||
getByText( | ||
'There was a problem loading this content. Please check your internet connection and try again.', | ||
), | ||
).toThrow(); | ||
}); | ||
}); |
46 changes: 0 additions & 46 deletions
46
packages/components/psammead-media-player/src/Canonical/useTimeout.jsx
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
packages/components/psammead-media-player/src/Canonical/useTimeout.test.jsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.