Skip to content

Commit

Permalink
Fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
wassgha committed Aug 1, 2017
1 parent ca3ff51 commit 588aeb1
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 48 deletions.
7 changes: 2 additions & 5 deletions src/mediasession-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,13 @@ export function parseSchemaImage(ampdoc) {
// 1. "image": "http://..",
return schemaJson['image'];
} else if (schemaJson['image']['@list']
&& schemaJson['image']['@list'][0]
&& typeof schemaJson['image']['@list'][0] === 'string') {
// 2. "image": {.., "@list": ["http://.."], ..}
return schemaJson['image']['@list'][0];
} else if (schemaJson['image']['url']
&& typeof schemaJson['image']['url'] === 'string') {
} else if (typeof schemaJson['image']['url'] === 'string') {
// 3. "image": {.., "url": "http://..", ..}
return schemaJson['image']['url'];
} else if (schemaJson['image'][0]
&& typeof schemaJson['image'][0] === 'string') {
} else if (typeof schemaJson['image'][0] === 'string') {
// 4. "image": ["http://.. "]
return schemaJson['image'][0];
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/video-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class VideoInterface {
/**
* Returns video's meta data (artwork, title, artist, album, etc.) for use
* with the Media Session API
* artwork (string): URL to the poster image (preferably a 512x512 PNG)
* artwork (Array): URL to the poster image (preferably a 512x512 PNG)
* title (string): Name of the video
* artist (string): Name of the video's author/artist
* album (string): Name of the video's album if it exists
Expand Down
95 changes: 53 additions & 42 deletions test/functional/test-mediasession-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,63 @@ import {
parseFavicon,
} from '../../src/mediasession-helper';

const template = `
<head>
<link rel="icon" href="http://example.com/favicon.ico">
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"mainEntityOfPage": "something",
"headline": "Something Happened",
"datePublished": "Fri Jul 28 12:45:00 EDT 2017",
"dateModified": "Fri Jul 28 12:45:00 EDT 2017",
"description": "Appearantly, yesterday something happened",
"author": {
"@type": "Person",
"name": "Awesome Author"
},
"publisher": {
"@type": "Organization",
"name": "Aperture Science",
"logo": {
"@type": "ImageObject",
"url": "logo-url",
"width": 133,
"height": 60
}
},
"image": {
"@type": "ImageObject",
"url": "http://example.com/image.png",
"height": 392,
"width": 696
}
}
</script>
<meta property="og:image" content="http://example.com/og-image.png">
</head>
<body>
<h1>Yesterday Something Happened</h1>
<p>Lorem ipsum dolor set amet..</p>
</body>
const schemaTemplate = `
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"mainEntityOfPage": "something",
"headline": "Something Happened",
"datePublished": "Fri Jul 28 12:45:00 EDT 2017",
"dateModified": "Fri Jul 28 12:45:00 EDT 2017",
"description": "Appearantly, yesterday something happened",
"author": {
"@type": "Person",
"name": "Awesome Author"
},
"publisher": {
"@type": "Organization",
"name": "Aperture Science",
"logo": {
"@type": "ImageObject",
"url": "logo-url",
"width": 133,
"height": 60
}
},
"image": {
"@type": "ImageObject",
"url": "http://example.com/image.png",
"height": 392,
"width": 696
}
}
`;


describes.sandboxed('MediaSessionAPI Helper Functions', {}, () => {
let ampdoc;
let favicon;
let schema;
let ogImage;
let head;

beforeEach(() => {
document.documentElement.innerHTML = template;
head = document.querySelector('head');
// Favicon
favicon = document.createElement('link');
favicon.setAttribute('rel', 'icon');
favicon.setAttribute('href', 'http://example.com/favicon.ico');
head.appendChild(favicon);
// Schema
schema = document.createElement('script');
schema.setAttribute('type', 'application/ld+json');
schema.innerHTML = schemaTemplate;
head.appendChild(schema);
// og-image
ogImage = document.createElement('meta');
ogImage.setAttribute('property', 'og:image');
ogImage.setAttribute('content', 'http://example.com/og-image.png');
head.appendChild(ogImage);
ampdoc = {
win: {
'document': document,
Expand All @@ -90,7 +99,9 @@ describes.sandboxed('MediaSessionAPI Helper Functions', {}, () => {
});

afterEach(() => {
document.documentElement.innerHTML = '';
head.removeChild(favicon);
head.removeChild(schema);
head.removeChild(ogImage);
});

it('should parse the schema and find the image', () => {
Expand Down

0 comments on commit 588aeb1

Please sign in to comment.