Skip to content

Commit

Permalink
feat(TMRS-482): linting and test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
times-tools committed Nov 28, 2024
1 parent b5cf55d commit a783228
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 31 deletions.
12 changes: 10 additions & 2 deletions packages/article-extras/__tests__/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { iterator } from "@times-components/test-utils";

import { UserState } from "./mocks";
import ArticleExtras from "../src/article-extras";
import { relatedArticleSlice, topics } from "../fixtures/article-extras";
import {
relatedArticleSlice,
categorisedArticles,
topics
} from "../fixtures/article-extras";

const commentingConfig = {
account: "sp_pCQgrRiN"
Expand Down Expand Up @@ -45,6 +49,7 @@ export default () => {
commentsEnabled
registerNode={() => {}}
relatedArticleSlice={relatedArticleSlice}
categorisedArticles={categorisedArticles}
relatedArticlesVisible
commentingConfig={commentingConfig}
topics={topics}
Expand All @@ -56,7 +61,7 @@ export default () => {
},
{
name:
"no topics and comments when user not logged in, only related articles and sponsored div",
"no topics and comments when user not logged in, only related articles, category articles, and sponsored div",
test: () => {
UserState.mockStates = [];
const testInstance = TestRenderer.create(
Expand All @@ -66,6 +71,7 @@ export default () => {
commentsEnabled
registerNode={() => {}}
relatedArticleSlice={relatedArticleSlice}
categorisedArticles={categorisedArticles}
relatedArticlesVisible
commentingConfig={commentingConfig}
topics={topics}
Expand All @@ -85,6 +91,7 @@ export default () => {
commentsEnabled
registerNode={() => {}}
relatedArticleSlice={relatedArticleSlice}
categorisedArticles={categorisedArticles}
relatedArticlesVisible
commentingConfig={commentingConfig}
topics={topics}
Expand All @@ -104,6 +111,7 @@ export default () => {
commentsEnabled
registerNode={() => {}}
relatedArticleSlice={relatedArticleSlice}
categorisedArticles={categorisedArticles}
relatedArticlesVisible
commentingConfig={commentingConfig}
topics={topics}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Array [
id="related-articles"
>
<RelatedArticles
hideBorder={false}
isVisible={true}
/>
<div>
Expand Down Expand Up @@ -56,14 +57,107 @@ Array [
]
`;

exports[`2. no topics and comments when user not logged in, only related articles and sponsored div 1`] = `
exports[`2. no topics and comments when user not logged in, only related articles, category articles, and sponsored div 1`] = `
Array [
<div
id="related-articles"
>
<RelatedArticles
hideBorder={true}
isVisible={true}
/>
<div
id="categorised-articles"
>
<div>
More from category
</div>
<div>
<div>
<article>
<div>
<div>
<a
href="/article/tms-pratchetts-law-of-the-jungle-xgqrcw779"
>
<div>
<div>
<img
alt="TMS: Pratchett’s law of the jungle - Disable Saving 2"
/>
</div>
</div>
</a>
</div>
</div>
<div>
<p>
Health
</p>
<div>
<a
href="/article/tms-pratchetts-law-of-the-jungle-xgqrcw779"
>
<h3>
TMS: Pratchett’s law of the jungle - Disable Saving 2
</h3>
</a>
</div>
<p>
March 23 2015, 8.39pm
</p>
</div>
</article>
</div>
</div>
</div>
<div
id="categorised-articles"
>
<div>
More from parent
</div>
<div>
<div>
<article>
<div>
<div>
<a
href="/article/tms-pratchetts-law-of-the-jungle-xgqrcw779"
>
<div>
<div>
<img
alt="TMS: Pratchett’s law of the jungle - Disable Saving"
/>
</div>
</div>
</a>
</div>
</div>
<div>
<p>
Health
</p>
<div>
<a
href="/article/tms-pratchetts-law-of-the-jungle-xgqrcw779"
>
<h3>
TMS: Pratchett’s law of the jungle - Disable Saving
</h3>
</a>
</div>
<p>
March 23 2015, 7.39pm
</p>
</div>
</article>
</div>
</div>
</div>
</div>,
<div>
<span>
Expand Down Expand Up @@ -105,6 +199,7 @@ Array [
id="related-articles"
>
<RelatedArticles
hideBorder={false}
isVisible={true}
/>
<div>
Expand Down Expand Up @@ -161,6 +256,7 @@ Array [
id="related-articles"
>
<RelatedArticles
hideBorder={false}
isVisible={true}
/>
<div>
Expand Down
86 changes: 85 additions & 1 deletion packages/article-extras/fixtures/article-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,90 @@ const relatedArticleSlice = {
],
sliceName: "StandardSlice"
};

const categorisedArticles = {
categoryArticles: {
label: "category",
articles: [
{
bylines: [
{
byline: [
{
attributes: {},
children: [
{
attributes: {
value: "Patrick Kidd"
},
children: [],
name: "text"
}
],
name: "inline"
}
]
}
],
headline: "TMS: Pratchett’s law of the jungle - Disable Saving 2",
label: "Health",
media: {
crops: [
{
url:
"https://www.thetimes.co.uk/imageserver/image/methode%2Ftimes%2Fprod%2Fweb%2Fbin%2F0547a7be-fb77-11e7-a987-7fcf5e9983dc.jpg?crop=1600%2C1125%2C0%2C104",
ratio: "3:2"
}
]
},
publicationName: "TIMES",
publishedDateTime: "2015-03-23T20:39:39.000Z",
categoryPath: "/article/tms-pratchetts-law-of-the-jungle-xgqrcw779"
}
]
},
parentCategoryArticles: {
label: "parent",
articles: [
{
bylines: [
{
byline: [
{
attributes: {},
children: [
{
attributes: {
value: "Patrick Kidd"
},
children: [],
name: "text"
}
],
name: "inline"
}
]
}
],
headline: "TMS: Pratchett’s law of the jungle - Disable Saving",
label: "Health",
media: {
crops: [
{
url:
"https://www.thetimes.co.uk/imageserver/image/methode%2Ftimes%2Fprod%2Fweb%2Fbin%2F0547a7be-fb77-11e7-a987-7fcf5e9983dc.jpg?crop=1600%2C1125%2C0%2C104",
ratio: "3:2"
}
]
},
publicationName: "TIMES",
publishedDateTime: "2015-03-23T19:39:39.000Z",
categoryPath: "/article/tms-pratchetts-law-of-the-jungle-xgqrcw779"
}
]
}
};

const topics = [
{
__typename: "Topic",
Expand Down Expand Up @@ -637,4 +721,4 @@ const topics = [
}
];

export { relatedArticleSlice, topics };
export { relatedArticleSlice, categorisedArticles, topics };
34 changes: 25 additions & 9 deletions packages/article-extras/src/article-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import ArticleComments from "@times-components/article-comments";
import RelatedArticles from "@times-components/related-articles";
import { MessageContext } from "@times-components/message-bar";
import SaveAndShareBar from "@times-components/save-and-share-bar";
import { RecommendedFetch, Breadcrumb, CategorisedArticles } from "@times-components/ts-components";
import {
RecommendedFetch,
Breadcrumb,
CategorisedArticles
} from "@times-components/ts-components";

import ArticleTopics from "./article-topics";
import {
Expand Down Expand Up @@ -57,8 +61,10 @@ const ArticleExtras = ({

return null;
};

const { categoryArticles, parentCategoryArticles } = categorisedArticles;
const categoryArticles =
(categorisedArticles && categorisedArticles.categoryArticles) || null;
const parentCategoryArticles =
(categorisedArticles && categorisedArticles.parentCategoryArticles) || null;

/* Nativo insert Sponsored Articles after the div#sponsored-article element. They are not able to insert directly into that element hence the container div */
const sponsoredArticlesAndRelatedArticles = (
Expand All @@ -81,12 +87,20 @@ const ArticleExtras = ({
articleSection={section}
/>
)}
{!isRecommendedActive && categoryArticles && (
<CategorisedArticles heading={categoryArticles.label} articles={categoryArticles.articles} />
)}
{!isRecommendedActive && parentCategoryArticles && (
<CategorisedArticles heading={parentCategoryArticles.label} articles={parentCategoryArticles.articles} />
)}
{!isRecommendedActive &&
categoryArticles && (
<CategorisedArticles
heading={categoryArticles.label}
articles={categoryArticles.articles}
/>
)}
{!isRecommendedActive &&
parentCategoryArticles && (
<CategorisedArticles
heading={parentCategoryArticles.label}
articles={parentCategoryArticles.articles}
/>
)}
</div>
<PromotedContentContainer>
<PromotedContentTitle>PROMOTED CONTENT</PromotedContentTitle>
Expand Down Expand Up @@ -151,6 +165,7 @@ ArticleExtras.propTypes = {
commentsEnabled: PropTypes.bool.isRequired,
registerNode: PropTypes.func.isRequired,
relatedArticleSlice: PropTypes.shape({}),
categorisedArticles: PropTypes.shape({}),
relatedArticlesVisible: PropTypes.bool.isRequired,
commentingConfig: PropTypes.shape({
account: PropTypes.string.isRequired
Expand All @@ -168,6 +183,7 @@ ArticleExtras.propTypes = {

ArticleExtras.defaultProps = {
relatedArticleSlice: null,
categorisedArticles: null,
topics: null,
isSharingSavingEnabled: true,
isCommentEnabled: true,
Expand Down
3 changes: 2 additions & 1 deletion packages/article-skeleton/src/article-skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ const ArticleSkeleton = ({
window.removeEventListener("scroll", handleScroll);
};
}, []);
const { hostName, canonicalUrl, breadcrumbs, categorisedArticles } = articleDataFromRender || {};
const { hostName, canonicalUrl, breadcrumbs, categorisedArticles } =
articleDataFromRender || {};
const articleUrl =
hostName && canonicalUrl ? `${hostName}${canonicalUrl}` : url;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ exports[`2. a single child element 1`] = `
<div
className="c0"
>
<responsive__SliceContainer>
<responsive__SliceContainer
hideBorder={false}
>
<div
className="c1"
>
Expand Down Expand Up @@ -475,7 +477,9 @@ exports[`3. two child elements 1`] = `
<div
className="c0"
>
<responsive__SliceContainer>
<responsive__SliceContainer
hideBorder={false}
>
<div
className="c1"
>
Expand Down Expand Up @@ -755,7 +759,9 @@ exports[`4. three child elements 1`] = `
<div
className="c0"
>
<responsive__SliceContainer>
<responsive__SliceContainer
hideBorder={false}
>
<div
className="c1"
>
Expand Down
Loading

0 comments on commit a783228

Please sign in to comment.