-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/tiles utility functions (#1868)
* feat:Tiles utility functions added * feat:tests for utils * feat: all tiles using utils * chore: yarn updated * fix: yarn.lock revert * chore: fix deps
- Loading branch information
1 parent
6a8d1c7
commit 64fc486
Showing
46 changed files
with
322 additions
and
264 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import shared from "../utils.base"; | ||
|
||
shared(); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import shared from "../utils.base"; | ||
|
||
shared(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { mockEditionSlice } from "@times-components/fixture-generator"; | ||
import { | ||
getTileImageUri, | ||
getTileSummary, | ||
getTileStrapline | ||
} from "../src/tiles/shared"; | ||
|
||
const tile = mockEditionSlice(1).items[0]; | ||
|
||
export default () => { | ||
describe("getTileImageUri should", () => { | ||
test("getTileImageUri - return null if there is no lead asset", () => { | ||
const tileWithoutLeadAsset = { | ||
...tile, | ||
article: { | ||
...tile.article, | ||
leadAsset: null, | ||
listingAsset: null | ||
}, | ||
leadAsset: null | ||
}; | ||
expect(getTileImageUri(tileWithoutLeadAsset, "crop169")).toEqual(null); | ||
}); | ||
test("getTileImageUri - return poster image crop if lead asset is a video", () => { | ||
const leadAsset = { | ||
__typename: "Video", | ||
posterImage: { | ||
caption: null, | ||
credits: null, | ||
crop169: { | ||
ratio: "16:9", | ||
url: | ||
"https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2F674e242a-3f8b-11e9-aa0a-30b9d78dd63b.jpg?crop=3483%2C1959%2C9%2C366" | ||
}, | ||
id: "64806087-c6d0-4104-df61-1faf30525989", | ||
title: "Potholes" | ||
} | ||
}; | ||
const tileWithLeadAsset = { | ||
...tile, | ||
article: { | ||
...tile.article, | ||
leadAsset, | ||
listingAsset: leadAsset | ||
}, | ||
leadAsset | ||
}; | ||
expect(getTileImageUri(tileWithLeadAsset, "crop169")).toEqual( | ||
leadAsset.posterImage.crop169.url | ||
); | ||
}); | ||
test("getTileImageUri - return undefined if lead asset doesnt have the right crop", () => { | ||
const leadAsset = { | ||
caption: null, | ||
credits: null, | ||
crop169: null, | ||
id: "64806087-c6d0-4104-df61-1faf30525989", | ||
title: "Potholes" | ||
}; | ||
const tileWithLeadAsset = { | ||
...tile, | ||
article: { | ||
...tile.leadAsset, | ||
leadAsset, | ||
listingAsset: leadAsset | ||
}, | ||
leadAsset | ||
}; | ||
expect(getTileImageUri(tileWithLeadAsset, "crop45")).toEqual(undefined); | ||
}); | ||
test("getTileImageUri - return empty object if lead asset is a video but doesnt have a poster image of the right crop", () => { | ||
const leadAsset = { | ||
__typename: "Video", | ||
posterImage: { | ||
caption: null, | ||
credits: null, | ||
crop169: null, | ||
id: "64806087-c6d0-4104-df61-1faf30525989", | ||
title: "Potholes" | ||
} | ||
}; | ||
const tileWithLeadAsset = { | ||
...tile, | ||
article: { | ||
...tile.leadAsset, | ||
leadAsset, | ||
listingAsset: leadAsset | ||
}, | ||
leadAsset | ||
}; | ||
expect(getTileImageUri(tileWithLeadAsset, "crop45")).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe("getTileSummary should", () => { | ||
test("getTileSummary should return ast for summary with 125 characters", () => { | ||
const length = 125; | ||
const summary125 = [ | ||
{ | ||
attributes: {}, | ||
children: [ | ||
{ | ||
attributes: { | ||
value: | ||
"Theresa May has two objectives tomorrow when MPs get to vote on Brexit — the trouble is both are fraught with difficulty." | ||
}, | ||
children: [], | ||
name: "text" | ||
} | ||
], | ||
name: "paragraph" | ||
} | ||
]; | ||
const tileWithSummary125 = { | ||
...tile, | ||
article: { | ||
...tile.article, | ||
summary125 | ||
} | ||
}; | ||
expect(getTileSummary(tileWithSummary125, length)).toEqual(summary125); | ||
}); | ||
test("getTileSummary should return ast for summary with 300 characters", () => { | ||
const length = 300; | ||
const summary300 = [ | ||
{ | ||
attributes: {}, | ||
children: [ | ||
{ | ||
attributes: { | ||
value: | ||
"‘The prodigal son returns.” So read a banner tied to the wall of the Paul Strank Stand at Kingsmeadow, the home of AFC Wimbledon, on Saturday, alongside the sepia-toned image of a fresh-faced Wally Downes, sporting an 80s haircut and Wimbledon strip, with a mischievous glint in his eye." | ||
}, | ||
children: [], | ||
name: "text" | ||
} | ||
], | ||
name: "paragraph" | ||
} | ||
]; | ||
const tileWithSummary300 = { | ||
...tile, | ||
article: { | ||
...tile.article, | ||
summary300 | ||
} | ||
}; | ||
expect(getTileSummary(tileWithSummary300, length)).toEqual(summary300); | ||
}); | ||
}); | ||
|
||
describe("getTileStrapline should", () => { | ||
test("getTileStrapline should return strapline", () => { | ||
expect(getTileStrapline(tile)).toBe(tile.strapline); | ||
}); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import shared from "../utils.base"; | ||
|
||
shared(); |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const getTileImageUri = (tile, crop) => { | ||
const leadAsset = | ||
tile.leadAsset || tile.article.listingAsset || tile.article.leadAsset; | ||
if (!leadAsset) return null; | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
const isVideo = leadAsset.__typename === "Video"; | ||
const displayImage = isVideo | ||
? leadAsset.posterImage[crop] || {} | ||
: leadAsset[crop] || {}; | ||
|
||
return displayImage.url; | ||
}; | ||
|
||
const getTileSummary = (tile, length) => | ||
tile[`teaser${length}`] || tile.article[`summary${length}`]; | ||
|
||
const getTileStrapline = tile => tile.strapline || tile.article.strapline; | ||
|
||
export { getTileImageUri, getTileSummary, getTileStrapline }; |
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
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
Oops, something went wrong.