Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3060 from bbc/MediaMessageRefactor
Browse files Browse the repository at this point in the history
Refactored Message component to support AV streams expired message
  • Loading branch information
rebeccamcginn authored Feb 5, 2020
2 parents 7ecc945 + 79baf81 commit c0a4e5b
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/components/psammead-media-player/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- prettier-ignore -->
| Version | Description |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| 2.7.1 | [PR#3060](https://github.com/bbc/psammead/pull/3060) Refactored Message component to display message for Expired AV Stream |
| 2.7.0 | [PR#3033](https://github.com/bbc/psammead/pull/3033) Refactor for No JS Canonical and AMP Media Player |
| 2.6.4 | [PR#3033](https://github.com/bbc/psammead/pull/3033) Talos - Bump Dependencies - @bbc/psammead-play-button |
| 2.6.3 | [PR#3030](https://github.com/bbc/psammead/pull/3030) Talos - Bump Dependencies - @bbc/psammead-assets |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/components/psammead-media-player/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbc/psammead-media-player",
"version": "2.7.0",
"version": "2.7.1",
"description": "Provides a media player with optional placeholder",
"main": "dist/index.js",
"module": "esm/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/components/psammead-media-player/src/Amp/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { string, number } from 'prop-types';
import Helmet from 'react-helmet';
import { AmpImg } from '@bbc/psammead-image';
import MediaMessage from '../MediaMessage';
import Message from '../Message';

const AmpHead = () => (
<Helmet>
Expand Down Expand Up @@ -46,9 +46,9 @@ const AmpMediaPlayer = ({
width={width}
/>
<noscript>
<MediaMessage
<Message
service={service}
noJsMessage={noJsMessage}
message={noJsMessage}
placeholderSrc={placeholderSrc}
placeholderSrcset={placeholderSrcset}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { string, bool } from 'prop-types';
import styled from 'styled-components';
import MediaMessage from '../MediaMessage';
import Message from '../Message';

const Canonical = ({
src,
Expand Down Expand Up @@ -40,9 +40,9 @@ const Canonical = ({
allowFullScreen
/>
<noscript>
<MediaMessage
<Message
service={service}
noJsMessage={noJsMessage}
message={noJsMessage}
placeholderSrc={placeholderSrc}
placeholderSrcset={placeholderSrcset}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const MessageWrapper = styled.div`
}
`;

const Message = styled.strong`
const StyledMessage = styled.strong`
display: block;
font-weight: normal;
bottom: 0;
Expand All @@ -49,12 +49,7 @@ const Message = styled.strong`
}
`;

const MediaMessage = ({
service,
noJsMessage,
placeholderSrc,
placeholderSrcset,
}) => (
const Message = ({ service, message, placeholderSrc, placeholderSrcset }) => (
<StyledWrapper>
{placeholderSrc && (
<Image
Expand All @@ -65,21 +60,21 @@ const MediaMessage = ({
/>
)}
<MessageWrapper service={service}>
<Message>{noJsMessage}</Message>
<StyledMessage>{message}</StyledMessage>
</MessageWrapper>
</StyledWrapper>
);

MediaMessage.propTypes = {
Message.propTypes = {
service: string.isRequired,
noJsMessage: string.isRequired,
message: string.isRequired,
placeholderSrcset: string,
placeholderSrc: string,
};

MediaMessage.defaultProps = {
Message.defaultProps = {
placeholderSrcset: '',
placeholderSrc: '',
};

export default MediaMessage;
export default Message;
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React from 'react';
import { render } from '@testing-library/react';
import MediaMessage from './index';
import Message from './index';
import '@testing-library/jest-dom/extend-expect';

it('should display the media message', () => {
const { getByText } = render(
<MediaMessage
<Message
service="news"
noJsMessage="Please enable Javascript or try a different browser"
message="Please enable Javascript or try a different browser"
placeholderSrc="http://foo.bar/placeholder.png"
placeholderSrcset="http://foo.bar/placeholder.png"
/>,
);
const mediaMessage = getByText(
const message = getByText(
'Please enable Javascript or try a different browser',
);
expect(mediaMessage).toBeInTheDocument();
expect(message).toBeInTheDocument();
});
15 changes: 15 additions & 0 deletions packages/components/psammead-media-player/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { string, bool, oneOf, shape } from 'prop-types';
import Placeholder from './Placeholder';
import Amp from './Amp';
import Canonical from './Canonical';
import Message from './Message';

const landscapeRatio = '56.25%'; // (9/16)*100 = 16:9
const portraitRatio = '177.78%'; // (16/9)*100 = 9:16
Expand Down Expand Up @@ -94,6 +95,8 @@ export const AmpMediaPlayer = ({
);
};

export const MediaMessage = Message;

CanonicalMediaPlayer.propTypes = {
placeholderSrc: string,
placeholderSrcset: string,
Expand Down Expand Up @@ -124,6 +127,18 @@ CanonicalMediaPlayer.defaultProps = {
noJsClassName: null,
};

MediaMessage.propTypes = {
service: string.isRequired,
message: string.isRequired,
placeholderSrc: string,
placeholderSrcset: string,
};

MediaMessage.defaultProps = {
placeholderSrc: null,
placeholderSrcset: null,
};

AmpMediaPlayer.propTypes = {
placeholderSrc: string.isRequired,
placeholderSrcset: string,
Expand Down

0 comments on commit c0a4e5b

Please sign in to comment.