1+ import { render , screen } from '@testing-library/react' ;
2+ import '@testing-library/jest-dom/extend-expect' ;
3+ import Blogs from '../src/pages/components/Blogs' ;
4+
5+ const posts = [
6+ {
7+ title : 'Our Legendary Article here' ,
8+ href : '#' ,
9+ category : { name : 'Greatness' , href : '#' } ,
10+ description :
11+ 'Reactime v17, we have come a long way from beta. Now introducing full Context API support and CustomHooks support: thereby allowing developers to better visualize the states and ... ' ,
12+ date : 'Dec 14, 2022' ,
13+ datetime : '2022-12-14' ,
14+ imageUrl :
15+ 'https://images.unsplash.com/photo-1496128858413-b36217c2ce36?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1679&q=80' ,
16+ readingTime : '6 min' ,
17+ author : {
18+ name : 'James Nghiem' ,
19+ href : '#' ,
20+ imageUrl :
21+ 'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80' ,
22+ } ,
23+ } ,
24+ {
25+ title : 'Time-Traveling Through React State' ,
26+ href : 'https://rxlina.medium.com/time-traveling-through-react-state-with-reactime-9-0-371dbdc99319' ,
27+ category : { name : 'React' , href : 'https://medium.com/tag/react' } ,
28+ description :
29+ 'Reactime is a Chrome extension and time-travel debugger for React that allows developers to record, track, and visualize state changes. Reactime leverages React’s core reconciliation... ' ,
30+ date : 'Oct 7, 2021' ,
31+ datetime : '2020-10-07' ,
32+ imageUrl :
33+ 'https://images.unsplash.com/photo-1547586696-ea22b4d4235d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1679&q=80' ,
34+ readingTime : '4 min' ,
35+ author : {
36+ name : 'Lina Shin' ,
37+ href : 'https://rxlina.medium.com/' ,
38+ imageUrl :
39+ 'https://media-exp1.licdn.com/dms/image/C5603AQHQGFvRHt25WQ/profile-displayphoto-shrink_200_200/0/1623865299399?e=1676505600&v=beta&t=yDqgIaJOhO3oOWLROIH9rHPBHdVzDSV3VlB2axWqXr4' ,
40+ } ,
41+ } ,
42+ {
43+ title : 'What time is it? Reactime!' ,
44+ href : 'https://medium.com/@robbytiptontol/inter-route-time-travel-with-reactime-d84cd55ec73b' ,
45+ category : { name : 'React Devtools' , href : 'https://medium.com/tag/react-devtools' } ,
46+ description : 'Reactime is a debugging tool that lets developers take snapshots of an application\’s state data as well as time-travel through these snapshots. The snapshots display React...' ,
47+ date : 'Jun 16, 2022' ,
48+ datetime : '2022-06-16' ,
49+ imageUrl :
50+ 'https://images.unsplash.com/photo-1492724441997-5dc865305da7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1679&q=80' ,
51+ readingTime : '9 min' ,
52+ author : {
53+ name : 'Robby Tipton' ,
54+ href : 'https://medium.com/@robbytiptontol' ,
55+ imageUrl :
56+ 'https://miro.medium.com/fit/c/96/96/1*pi-RH2LRvsZA9vLZTvY2mg.jpeg' ,
57+ } ,
58+ } ,
59+ ]
60+
61+ describe ( 'Blog component test ' , ( ) => {
62+ beforeEach ( ( ) => {
63+ render ( < Blogs /> )
64+ } )
65+
66+ it ( 'the title appears on the page' , ( ) => {
67+ expect ( screen . getByText ( / F r o m t h e B l o g / i) ) . toBeInTheDocument ( )
68+ expect ( screen . getByText ( / S e e t h e b l o g s f r o m t h e m o s t r e c e n t u p d a t e s a n d t o t h e p a s t y e a r s ! / i) ) . toBeInTheDocument ( )
69+ } ) ;
70+
71+ it ( 'displays the correct information for each blog post' , ( ) => {
72+ const blogs = screen . getAllByTestId ( 'blog' )
73+ blogs . forEach ( ( blog , index ) => {
74+ console . debug ( blog )
75+ expect ( blog ) . toHaveProperty ( 'title' , blog . title ) ;
76+ // expect(blog).toHaveProperty('description', blog.description);
77+ // expect(blog).toHaveProperty('description', blog.);
78+ // expect(blog).toHaveProperty('category.name', blog.title);
79+ // expect(blog).toHaveProperty('author.name', blog.title);
80+ // expect(blog).toHaveProperty('date', blog.date);
81+ // expect(blog).toHaveProperty('readingTime', blog.title);
82+ } )
83+
84+ } ) ;
85+
86+ } ) ;
0 commit comments