-
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(TMRS-482): add new CategorisedArticles component
- Loading branch information
1 parent
2cc8cc7
commit 3398acb
Showing
17 changed files
with
168 additions
and
17 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
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
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
44 changes: 44 additions & 0 deletions
44
packages/ts-components/src/components/categorised-articles/CategorisedArticles.tsx
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,44 @@ | ||
import React from 'react'; | ||
import { | ||
Slice, | ||
SliceArticle, | ||
MouseEventType | ||
} from '@times-components/ts-slices'; | ||
|
||
import { useTrackingContext } from '../../helpers/tracking/TrackingContextProvider'; | ||
import { | ||
Article, | ||
getRecommendedArticlesSlice | ||
} from '../../utils/linkedArticles/formatters'; | ||
|
||
import { Header } from '../../utils/linkedArticles/styles'; | ||
|
||
interface CategorisedArticles { | ||
heading: string; | ||
articles: Article[]; | ||
} | ||
export const CategorisedArticles: React.FC<{ | ||
heading: string; | ||
articles: any; | ||
}> = ({ heading, articles }) => { | ||
const { fireAnalyticsEvent } = useTrackingContext(); | ||
|
||
const onClickHandler = (__: MouseEventType, article: SliceArticle) => { | ||
if (fireAnalyticsEvent) { | ||
fireAnalyticsEvent({ | ||
action: 'Clicked', | ||
attrs: { article_parent_name: article.headline } | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<div id="categorised-articles"> | ||
<Header>{`More from ${heading}`}</Header> | ||
<Slice | ||
slice={getRecommendedArticlesSlice(articles)} | ||
clickHandler={onClickHandler} | ||
/> | ||
</div> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
.../ts-components/src/components/categorised-articles/__tests__/CategorisedArticles.test.tsx
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,27 @@ | ||
import React from 'react'; | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { CategorisedArticles } from '../CategorisedArticles'; | ||
|
||
describe('render CategorisedArticles', () => { | ||
it('should render header and slice with articles when valid props provided', () => { | ||
const mockArticles = [{ headline: 'Test Article' }]; | ||
const mockFireEvent = jest.fn(); | ||
|
||
jest.mock('../../../helpers/tracking/TrackingContextProvider', () => ({ | ||
useTrackingContext: () => ({ | ||
fireAnalyticsEvent: mockFireEvent | ||
}) | ||
})); | ||
|
||
const { container, asFragment } = render( | ||
<CategorisedArticles heading="Sports" articles={mockArticles} /> | ||
); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
expect( | ||
container.querySelector('#categorised-articles') | ||
).toBeInTheDocument(); | ||
expect(screen.getByText('More from Sports')).toBeInTheDocument(); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
...components/categorised-articles/__tests__/__snapshots__/CategorisedArticles.test.tsx.snap
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,61 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`render CategorisedArticles should render header and slice with articles when valid props provided 1`] = ` | ||
<DocumentFragment> | ||
<div | ||
id="categorised-articles" | ||
> | ||
<div | ||
class="sc-bdVaJa vbIkV" | ||
> | ||
More from Sports | ||
</div> | ||
<div | ||
class="shared-styles__SliceContainer-ismxwo-0 styles__SliceContainer-b33h2c-0 bJHjPH" | ||
> | ||
<div | ||
class="shared-styles__SlotContainer-ismxwo-1 styles__SlotContainer-b33h2c-1 cKwigu" | ||
> | ||
<article | ||
class="shared-styles__ArticleContainer-sc-1kek94e-0 jgpbxb" | ||
> | ||
<div | ||
class="shared-styles__SideBySideColumn-sc-1kek94e-1 jOKfAL" | ||
> | ||
<div | ||
class="styles__ImageContainer-sc-8lglkt-0 hmOUZw" | ||
> | ||
<a> | ||
<div | ||
class="styles__ImageRatio-sc-8lglkt-1 kDSgGC" | ||
> | ||
<div | ||
class="styles__LazyContainer-qsbah5-0 iKBUbT" | ||
> | ||
<img | ||
alt="Test Article" | ||
/> | ||
</div> | ||
</div> | ||
</a> | ||
</div> | ||
</div> | ||
<div | ||
class="shared-styles__SideBySideColumn-sc-1kek94e-1 jOKfAL" | ||
> | ||
<div | ||
class="styles__HeadlineContainer-k0mgwi-0 ghKmOQ" | ||
> | ||
<a> | ||
<h3> | ||
Test Article | ||
</h3> | ||
</a> | ||
</div> | ||
</div> | ||
</article> | ||
</div> | ||
</div> | ||
</div> | ||
</DocumentFragment> | ||
`; |
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
6 changes: 3 additions & 3 deletions
6
...ed-articles/__tests__/formatters.test.tsx → ...s/src/utils/__tests__/formatters.test.tsx
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
File renamed without changes.
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