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

MAP fauxHeadline and visuallyHiddenHeadline logic #4582

Merged
merged 42 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f12e8e0
WIP - add offScreenHeadline and Headline either side of aresMedia block
Nov 5, 2019
12b437f
ramda has clone but we call it deepClone? :thinking-face:
Nov 5, 2019
990f524
preprocessor logic for onScreenHadline and offScreenHeadline
Nov 6, 2019
b4b560d
extend insertTimestamp to place after onScreenHeadline
Nov 6, 2019
8c883f2
OffScreenHeadline container
Nov 6, 2019
44cddc3
OffScreenHeadline test, stories and snapshots
Nov 6, 2019
ab6c6ef
fix getId() logic
Nov 6, 2019
247ff7f
add OnScreenHeadline and OffScreenHeadline to CPSAssetMain
Nov 6, 2019
d4c3a94
snapshot update
Nov 6, 2019
5eb89a7
null text check in OffScreenHeadline
Nov 6, 2019
6fa8ba7
Add OnScreenHeadline container, with tests and stories
Nov 6, 2019
735d336
<strong> is not tab-able so remove tabIndex-1
Nov 6, 2019
d5a1534
simplify the firstBlockIsVideo logic
Nov 6, 2019
fb1ede2
snapshots
Nov 6, 2019
034f2b5
be consistent with onScreenHeadlineBlock
Nov 6, 2019
27f5182
maintain support for heading block when not MAP asset type
Nov 6, 2019
18cf149
add tests case for STY asset type
Nov 6, 2019
7ff139e
update STY snapshot
Nov 6, 2019
8468b94
rename OnScreenHeadline to FauxHeadline and OffScreenHeadline to Visu…
Nov 6, 2019
4aa81e3
add timestamp preprocessor tests for fauxHeadline logic
Nov 6, 2019
b27e9de
Merge branch 'latest' into MAP-hidden-headline-logic
Nov 6, 2019
778e413
use .shift() as per review comment
Nov 6, 2019
1563fb9
More succinct type check for headline and fauxHeadline
Nov 6, 2019
7304acb
Merge branch 'MAP-hidden-headline-logic' of github.com:bbc/simorgh in…
Nov 6, 2019
1e0cd2f
missed a rename to faux and visuallyHidden on headline component
Nov 6, 2019
de3244b
missed a rename to faux and visuallyHidden on headline component
Nov 6, 2019
583ed4a
Merge branch 'latest' of github.com:bbc/simorgh into MAP-hidden-headl…
Nov 7, 2019
6840cd0
linting
Nov 7, 2019
f50cbec
Merge branch 'latest' into MAP-hidden-headline-logic
Nov 7, 2019
6d89504
Merge branch 'latest' into MAP-hidden-headline-logic
Nov 7, 2019
34d9e55
Merge branch 'latest' of github.com:bbc/simorgh into MAP-hidden-headl…
Nov 7, 2019
dec7ef0
review comments and snapshot
Nov 7, 2019
9f2637b
Merge branch 'latest' into MAP-hidden-headline-logic
Nov 7, 2019
d971025
Merge branch 'latest' into MAP-hidden-headline-logic
FK78 Nov 8, 2019
974f9d0
Bump bundle check
ryanmccombe Nov 8, 2019
b3c0c79
Merge branch 'latest' into MAP-hidden-headline-logic
ryanmccombe Nov 8, 2019
87b8413
Merge branch 'latest' into MAP-hidden-headline-logic
amywalkerdev Nov 11, 2019
6f9349c
Merge branch 'latest' into MAP-hidden-headline-logic
ryanmccombe Nov 11, 2019
082af4e
Merge branch 'latest' into MAP-hidden-headline-logic
oluoluoxenfree Nov 11, 2019
a8ef983
Merge branch 'latest' into MAP-hidden-headline-logic
ryanmccombe Nov 11, 2019
4fac0f4
Merge branch 'latest' into MAP-hidden-headline-logic
ryanmccombe Nov 12, 2019
9ab0444
Merge branch 'latest' into MAP-hidden-headline-logic
ryanmccombe Nov 12, 2019
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
150 changes: 84 additions & 66 deletions src/app/containers/CpsAssetPageMain/__snapshots__/index.test.jsx.snap

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/app/containers/CpsAssetPageMain/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import MediaPlayer from '../CpsAssetMediaPlayer';
import Blocks from '../Blocks';
import ATIAnalytics from '../ATIAnalytics';
import cpsAssetPagePropTypes from '../../models/propTypes/cpsAssetPage';
import fauxHeadline from '../FauxHeadline';
ryanmccombe marked this conversation as resolved.
Show resolved Hide resolved
import visuallyHiddenHeadline from '../VisuallyHiddenHeadline';

const CpsAssetPageMain = ({ pageData }) => {
const title = path(['promo', 'headlines', 'headline'], pageData);
Expand All @@ -22,6 +24,8 @@ const CpsAssetPageMain = ({ pageData }) => {
const blocks = pathOr([], ['content', 'model', 'blocks'], pageData);

const componentsToRender = {
fauxHeadline,
visuallyHiddenHeadline,
headline: headings,
subheadline: headings,
text,
Expand Down
149 changes: 149 additions & 0 deletions src/app/containers/FauxHeadline/__snapshots__/index.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`FauxHeadline with headline data should render correctly 1`] = `
.c1 {
font-size: 1.75rem;
line-height: 2rem;
font-family: ReithSerif,Helvetica,Arial,sans-serif;
font-weight: 500;
font-style: normal;
color: #3F3F42;
margin: 0;
padding: 2rem 0;
}

@media (min-width:20rem) and (max-width:37.4375rem) {
.c1 {
font-size: 2rem;
line-height: 2.25rem;
}
}

@media (min-width:37.5rem) {
.c1 {
font-size: 2.75rem;
line-height: 3rem;
}
}

@media (min-width:37.5rem) {
.c1 {
padding: 2.5rem 0;
}
}

@media (max-width:63rem) {
.c0 {
grid-column: 1 / span 6;
}
}

@media (min-width:63rem) and (max-width:80rem) {
.c0 {
grid-column: 3 / span 6;
}
}

@media (min-width:80rem) {
.c0 {
grid-column: 6 / span 12;
}
}

@media (max-width:25rem) {
.c0 {
padding: 0 0.5rem;
}
}

@media (min-width:25rem) and (max-width:62.9375rem) {
.c0 {
padding: 0 1rem;
}
}

<div
class="c0"
>
<strong
aria-hidden="true"
class="c1"
>
This is a headline!
</strong>
</div>
`;

exports[`FauxHeadline with plain text headline should render <strong> containing correct text 1`] = `
.c1 {
font-size: 1.75rem;
line-height: 2rem;
font-family: ReithSerif,Helvetica,Arial,sans-serif;
font-weight: 500;
font-style: normal;
color: #3F3F42;
margin: 0;
padding: 2rem 0;
}

@media (min-width:20rem) and (max-width:37.4375rem) {
.c1 {
font-size: 2rem;
line-height: 2.25rem;
}
}

@media (min-width:37.5rem) {
.c1 {
font-size: 2.75rem;
line-height: 3rem;
}
}

@media (min-width:37.5rem) {
.c1 {
padding: 2.5rem 0;
}
}

@media (max-width:63rem) {
.c0 {
grid-column: 1 / span 6;
}
}

@media (min-width:63rem) and (max-width:80rem) {
.c0 {
grid-column: 3 / span 6;
}
}

@media (min-width:80rem) {
.c0 {
grid-column: 6 / span 12;
}
}

@media (max-width:25rem) {
.c0 {
padding: 0 0.5rem;
}
}

@media (min-width:25rem) and (max-width:62.9375rem) {
.c0 {
padding: 0 1rem;
}
}

<div
class="c0"
>
<strong
aria-hidden="true"
class="c1"
>
Plain headline
</strong>
</div>
`;
42 changes: 42 additions & 0 deletions src/app/containers/FauxHeadline/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useContext } from 'react';
import { Headline } from '@bbc/psammead-headings';
import { textDefaultPropTypes } from '#models/propTypes';
import { ServiceContext } from '#contexts/ServiceContext';
import { headlineModelPropTypes } from '#models/propTypes/headline';
import Fragment from '../Fragment';
import Blocks from '../Blocks';
import { GridItemConstrainedLarge } from '#lib/styledGrid';

// missing CSS 'display: block;' in psammead branch `explicitly-set-h1-styles-display-and-font-weight`
ryanmccombe marked this conversation as resolved.
Show resolved Hide resolved
const FauxHeadline = props => <Headline as="strong" {...props} />;

const FauxHeadlineContainer = ({ blocks }) => {
const { script, service } = useContext(ServiceContext);

const arrayOfFragments = blocks[0].model.blocks[0].model.blocks;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use path here please


if (!arrayOfFragments || !Array.isArray(arrayOfFragments)) {
return null;
}
const componentsToRender = { fragment: Fragment };

const renderText = () => (
<Blocks blocks={arrayOfFragments} componentsToRender={componentsToRender} />
);

return (
<GridItemConstrainedLarge>
<FauxHeadline script={script} service={service} aria-hidden="true">
ryanmccombe marked this conversation as resolved.
Show resolved Hide resolved
{renderText()}
</FauxHeadline>
</GridItemConstrainedLarge>
);
};

FauxHeadlineContainer.propTypes = {
...headlineModelPropTypes,
};

FauxHeadlineContainer.defaultProps = textDefaultPropTypes;

export default FauxHeadlineContainer;
16 changes: 16 additions & 0 deletions src/app/containers/FauxHeadline/index.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { storiesOf } from '@storybook/react';
import React from 'react';
import { latin } from '@bbc/gel-foundations/scripts';
import FauxHeadlineContainer from '.';
import { ServiceContext } from '#contexts/ServiceContext';
import blocksSingleFragment from '../Headings/testHelpers';

const headline = blocksSingleFragment('This is a headline.', []);

storiesOf('Containers|FauxHeadline', module)
.addParameters({ chromatic: { disable: true } })
.add('default FauxHeadline', () => (
<ServiceContext.Provider value={{ script: latin, service: 'news' }}>
<FauxHeadlineContainer type="fauxHeadline" blocks={headline} />
</ServiceContext.Provider>
));
47 changes: 47 additions & 0 deletions src/app/containers/FauxHeadline/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import {
shouldMatchSnapshot,
isNull,
suppressPropWarnings,
} from '@bbc/psammead-test-helpers';
import { latin } from '@bbc/gel-foundations/scripts';
import FauxHeadlineContainer from '.';
import { ServiceContext } from '#contexts/ServiceContext';
import { textBlock } from '#models/blocks';
import blocksSingleFragment from '../Headings/testHelpers';

const FauxHeadlineContainerWithContext = data => (
<ServiceContext.Provider value={{ script: latin, service: 'news' }}>
<FauxHeadlineContainer {...data} />
</ServiceContext.Provider>
);

describe('FauxHeadline', () => {
describe('with no data', () => {
suppressPropWarnings(['blocks', 'supplied']);
isNull('should not render anything', FauxHeadlineContainerWithContext());
});

describe('with headline data', () => {
const data = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const data = textBlock('This is a headline!');

...textBlock('This is a headline!'),
};
shouldMatchSnapshot(
'should render correctly',
FauxHeadlineContainerWithContext(data),
);
});

describe('with plain text', () => {
describe('headline', () => {
const data = {
blocks: blocksSingleFragment('Plain headline', []),
};

shouldMatchSnapshot(
'should render <strong> containing correct text',
FauxHeadlineContainerWithContext(data),
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`VisuallyHiddenHeadline with headline data should render correctly 1`] = `
.c0 {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
-webkit-clip: rect(1px,1px,1px,1px);
clip: rect(1px,1px,1px,1px);
height: 1px;
overflow: hidden;
position: absolute;
width: 1px;
margin: 0;
}

<h1
class="c0"
id="content"
tabindex="-1"
>
This is a headline!
</h1>
`;

exports[`VisuallyHiddenHeadline with plain text headline should render h1 containing correct text 1`] = `
.c0 {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
-webkit-clip: rect(1px,1px,1px,1px);
clip: rect(1px,1px,1px,1px);
height: 1px;
overflow: hidden;
position: absolute;
width: 1px;
margin: 0;
}

<h1
class="c0"
id="content"
tabindex="-1"
>
Plain headline
</h1>
`;
33 changes: 33 additions & 0 deletions src/app/containers/VisuallyHiddenHeadline/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import path from 'ramda/src/path';
import VisuallyHiddenText from '@bbc/psammead-visually-hidden-text';
import { textDefaultPropTypes } from '#models/propTypes';
import { headlineModelPropTypes } from '#models/propTypes/headline';

const VisuallyHiddenHeadline = props => (
<VisuallyHiddenText as="h1" {...props} />
);

const VisuallyHiddenHeadlineContainer = ({ blocks }) => {
const { text } = path(['0', 'model', 'blocks', '0', 'model'], blocks);

if (!text) {
return null;
}

const id = 'content'; // Used for the skiplink

return (
<VisuallyHiddenHeadline id={id} tabIndex="-1">
{text}
</VisuallyHiddenHeadline>
);
};

VisuallyHiddenHeadlineContainer.propTypes = {
...headlineModelPropTypes,
};

VisuallyHiddenHeadlineContainer.defaultProps = textDefaultPropTypes;

export default VisuallyHiddenHeadlineContainer;
15 changes: 15 additions & 0 deletions src/app/containers/VisuallyHiddenHeadline/index.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { storiesOf } from '@storybook/react';
import React from 'react';
import VisuallyHiddenHeadlineContainer from '.';
import blocksSingleFragment from '../Headings/testHelpers';

const headline = blocksSingleFragment('This is a headline.', []);

storiesOf('Containers|VisuallyHiddenHeadline', module)
.addParameters({ chromatic: { disable: true } })
.add('default VisuallyHiddenHeadline', () => (
<VisuallyHiddenHeadlineContainer
type="visuallyHiddenHeadline"
blocks={headline}
/>
));
Loading