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

Amp Img #1101

Closed
wants to merge 32 commits into from
Closed

Amp Img #1101

wants to merge 32 commits into from

Conversation

sareh
Copy link
Contributor

@sareh sareh commented Dec 17, 2018

Resolves #929

Adding an AmpImg component that extends Img.

Integrating it into FigureContainer.

Testing notes
Visiting a canonical page renders images with <img>, with attributes alt, src, height and width.
http://localhost:7080/news/articles/c9rpqy7pmypo
screen shot 2018-12-18 at 09 44 31

Visiting an amp page renders images with <amp-img>, with attributes alt, src, height and width.
http://localhost:7080/news/articles/c9rpqy7pmypo.amp

screen shot 2018-12-18 at 09 42 45

Note, to run the validator and check everything is correct, in one window run:

npm run build && npm run start

In the second window run:

amphtml-validator http://localhost:7080/news/articles/c9rpqy7pmypo.amp || true

(Note: the npm run test:ampValidate seems to be failing on the wait command. Separate issue to fix this: #1109 )

  • I have assigned myself to this PR and the corresponding issues
  • Tests added for new features
  • Test engineer approval
  • I have followed the merging checklist and this is ready to merge.

Copy link
Contributor

@ChrisBAshton ChrisBAshton left a comment

Choose a reason for hiding this comment

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

Added some comments

const WrappingContainer = ({ alt, height, src, width }) => (
<AmpImg alt={alt} src={src} height={height} width={width} />
);
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Needs the rest of the README structure (guess I could have raised an issue for that!), e.g. https://github.com/BBC-News/psammead/tree/latest/packages/components/psammead-paragraph

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CoC and other links will need to change when we move it to Psammead. I've added a note to the description in this Issue: BBC-archive/psammead#203

src/app/components/Figure/Image/README.md Outdated Show resolved Hide resolved
src/app/components/Figure/Image/fixtureData.js Outdated Show resolved Hide resolved
src/app/components/Figure/Image/index.amp.jsx Outdated Show resolved Hide resolved
src/app/components/Figure/Image/index.amp.stories.jsx Outdated Show resolved Hide resolved
src/app/components/Figure/Image/index.amp.test.jsx Outdated Show resolved Hide resolved
src/app/components/Figure/Image/index.amp.test.jsx Outdated Show resolved Hide resolved
@sareh sareh self-assigned this Dec 17, 2018
@sareh
Copy link
Contributor Author

sareh commented Dec 18, 2018

Visiting a canonical page renders images with <img>, with attributes alt, src, height and width.
http://localhost:7080/news/articles/c9rpqy7pmypo

Visiting an amp page renders images with <amp-img>, with attributes alt, src, height and width.
http://localhost:7080/news/articles/c9rpqy7pmypo.amp

@sareh
Copy link
Contributor Author

sareh commented Dec 18, 2018

For readability of our test files, I have not refactored all of the tests.

width={portrait.width}
/>,
);
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

import { custom, landscape, portrait, square } from './fixtureData';

const snapshotTests = Component => {
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

width={landscape.width}
/>,
);
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

width={square.width}
/>,
);
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

import { shouldMatchSnapshot } from '../../../../helpers/tests/testHelpers';
import { custom, landscape, portrait, square } from './fixtureData';

const snapshotTests = Component => {
Copy link

Choose a reason for hiding this comment

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

Function snapshotTests has 46 lines of code (exceeds 25 allowed). Consider refactoring.

width={portrait.width}
/>,
);
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

import { custom, landscape, portrait, square } from './fixtureData';

const snapshotTests = Component => {
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

width={landscape.width}
/>,
);
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

width={square.width}
/>,
);
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

import { shouldMatchSnapshot } from '../../../../helpers/tests/testHelpers';
import { custom, landscape, portrait, square } from './fixtureData';

const snapshotTests = Component => {
Copy link

Choose a reason for hiding this comment

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

Function snapshotTests has 46 lines of code (exceeds 25 allowed). Consider refactoring.

@sareh
Copy link
Contributor Author

sareh commented Dec 20, 2018

The amp-img does not scale correctly. I've tried several different cases:

Option 1
layout: 'responsive' height & width defined. The docs say the height and width are only used for ratios, however, when used in Simorgh they get converted into px, and there is an overflow:
screen shot option 1

Option 2
https://www.ampproject.org/docs/reference/components/amp-img#the-difference-between-responsive-and-intrinsic-layout
Have used layout: "intrinsic" as well, just to see whether it'd make a difference. It does not.

It appears that regardless of the layout value passed, the fixed layout is assumed.
screen shot of fixed

Option 3
https://www.ampproject.org/docs/reference/components/amp-img#scaling-an-image-up-to-a-maximum-width
Scaling up to a maximum width with a wrapper around the <amp-img> - e.g. with a

const StyledWrapper = styled.div`
    max-width: 48rem;

This does constrain the image correctly, however the image width won't smoothly transition to be 6 out of 10 columns of our grid.

Option 4
Am now exploring the sizes option: https://www.ampproject.org/docs/design/responsive/art_direction#sizes

@ChrisBAshton ChrisBAshton mentioned this pull request Dec 21, 2018
1 task
{...additionalProps}
/>,
);
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

import { custom, landscape, portrait, square } from './fixtureData';

const snapshotTests = (Component, additionalProps) => {
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

{...additionalProps}
/>,
);
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

import React from 'react';
import CanonicalDecorator from '.';

describe('CanonicalDecorator', () => {
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

{...additionalProps}
/>,
);
shouldMatchSnapshot(
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

@codeclimate
Copy link

codeclimate bot commented Dec 24, 2018

Code Climate has analyzed commit 974b8ec and detected 9 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 8

The test coverage on the diff in this pull request is 97.3% (90% is the threshold).

This pull request will bring the total coverage in the repository to 96.6% (-0.1% change).

View more on Code Climate.

@sareh
Copy link
Contributor Author

sareh commented Dec 31, 2018

Due to #1104 being merged in, the Image component is only in Psammead now.
This PR is not relevant to the initial issue #929, but will be to this one #953, after this Psammead PR is merged in: BBC-archive/psammead#241

@sareh sareh deleted the amp-img branch January 7, 2019 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create AmpImg component
3 participants