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 a368387 commit ad62398
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 17 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 };
28 changes: 21 additions & 7 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 @@ -81,12 +85,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 +163,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 +181,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 @@ -20,8 +20,8 @@ storiesOf('Typescript Component/Categorised Articles', module).add(
article_name: '<headline>',
widget_headline: '<headline>',
widget_section: '<section>',
widget_type: "today's section",
},
widget_type: "today's section"
}
}}
analyticsStream={analyticsStream}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {
Slice,
SliceArticle,
MouseEventType,
MouseEventType
} from '@times-components/ts-slices';

import { useTrackingContext } from '../../helpers/tracking/TrackingContextProvider';
Expand All @@ -16,15 +16,15 @@ interface CategorisedArticlesProps {
}
export const CategorisedArticles: React.FC<CategorisedArticlesProps> = ({
heading,
articles,
articles
}) => {
const { fireAnalyticsEvent } = useTrackingContext();

const onClickHandler = (__: MouseEventType, article: SliceArticle) => {
if (fireAnalyticsEvent) {
fireAnalyticsEvent({
action: 'Clicked',
attrs: { article_parent_name: article.headline },
attrs: { article_parent_name: article.headline }
});
}
};
Expand Down

0 comments on commit ad62398

Please sign in to comment.