Skip to content

Commit c04b618

Browse files
author
Tiffany Le-Nguyen
committed
chore: change site to stub api request on dev
1 parent 0136ae8 commit c04b618

File tree

5 files changed

+309
-10
lines changed

5 files changed

+309
-10
lines changed

cypress/integration/default.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* eslint-disable eslint-comments/disable-enable-pair, max-nested-callbacks */
2+
describe('Default site', () => {
3+
beforeEach(() => {
4+
cy.visit('/')
5+
})
6+
7+
it('loads home page', () => {
8+
cy.findByText('Next Demo!')
9+
cy.findByTestId("list-server-side").within(() => {
10+
cy.findAllByRole("link").should('have.length', 5)
11+
})
12+
13+
cy.findByTestId("list-dynamic-pages").within(() => {
14+
cy.findAllByRole("link").should('have.length', 3)
15+
})
16+
17+
cy.findByTestId("list-catch-all").within(() => {
18+
cy.findAllByRole("link").should('have.length', 3)
19+
})
20+
21+
cy.findByTestId("list-static").within(() => {
22+
cy.findAllByRole("link").should('have.length', 2)
23+
})
24+
})
25+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-disable eslint-comments/disable-enable-pair, max-nested-callbacks */
2+
describe('Dynamic Routing', () => {
3+
it('loads page', () => {
4+
cy.visit('/shows/250')
5+
cy.findByRole('heading').should('contain', '250')
6+
cy.findByText('Kirby Buckets')
7+
})
8+
})

cypress/integration/test.spec.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

demo/pages/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ const Index = ({ shows }) => (
118118
)
119119

120120
Index.getInitialProps = async function () {
121+
const dev = process.env.CONTEXT !== 'production';
122+
121123
// Set a random page between 1 and 100
122124
const randomPage = Math.floor(Math.random() * 100) + 1
125+
const server = dev ? 'http://localhost:3000/shows1.json' : `https://api.tvmaze.com/shows?page=${randomPage}`;
123126

124127
// Get the data
125-
const res = await fetch(`https://api.tvmaze.com/shows?page=${randomPage}`)
128+
const res = await fetch(server);
126129
const data = await res.json()
127130

128131
return { shows: data.slice(0, 5) }

demo/public/shows1.json

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
[{
2+
"id": 250,
3+
"url": "https://www.tvmaze.com/shows/250/kirby-buckets",
4+
"name": "Kirby Buckets",
5+
"type": "Scripted",
6+
"language": "English",
7+
"genres": ["Comedy"],
8+
"status": "Ended",
9+
"runtime": 30,
10+
"averageRuntime": 30,
11+
"premiered": "2014-10-20",
12+
"ended": "2017-02-02",
13+
"officialSite": "http://disneyxd.disney.com/kirby-buckets",
14+
"schedule": {
15+
"time": "07:00",
16+
"days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
17+
},
18+
"rating": {
19+
"average": null
20+
},
21+
"weight": 69,
22+
"network": {
23+
"id": 25,
24+
"name": "Disney XD",
25+
"country": {
26+
"name": "United States",
27+
"code": "US",
28+
"timezone": "America/New_York"
29+
}
30+
},
31+
"webChannel": {
32+
"id": 83,
33+
"name": "DisneyNOW",
34+
"country": {
35+
"name": "United States",
36+
"code": "US",
37+
"timezone": "America/New_York"
38+
}
39+
},
40+
"dvdCountry": null,
41+
"externals": {
42+
"tvrage": 37394,
43+
"thetvdb": 278449,
44+
"imdb": "tt3544772"
45+
},
46+
"image": {
47+
"medium": "https://static.tvmaze.com/uploads/images/medium_portrait/1/4600.jpg",
48+
"original": "https://static.tvmaze.com/uploads/images/original_untouched/1/4600.jpg"
49+
},
50+
"summary": "<p>The single-camera series that mixes live-action and animation stars Jacob Bertrand as the title character. <b>Kirby Buckets</b> introduces viewers to the vivid imagination of charismatic 13-year-old Kirby Buckets, who dreams of becoming a famous animator like his idol, Mac MacCallister. With his two best friends, Fish and Eli, by his side, Kirby navigates his eccentric town of Forest Hills where the trio usually find themselves trying to get out of a predicament before Kirby's sister, Dawn, and her best friend, Belinda, catch them. Along the way, Kirby is joined by his animated characters, each with their own vibrant personality that only he and viewers can see.</p>",
51+
"updated": 1617744408,
52+
"_links": {
53+
"self": {
54+
"href": "https://api.tvmaze.com/shows/250"
55+
},
56+
"previousepisode": {
57+
"href": "https://api.tvmaze.com/episodes/1051658"
58+
}
59+
}
60+
}, {
61+
"id": 251,
62+
"url": "https://www.tvmaze.com/shows/251/downton-abbey",
63+
"name": "Downton Abbey",
64+
"type": "Scripted",
65+
"language": "English",
66+
"genres": ["Drama", "Family", "Romance"],
67+
"status": "Ended",
68+
"runtime": 60,
69+
"averageRuntime": 71,
70+
"premiered": "2010-09-26",
71+
"ended": "2015-12-25",
72+
"officialSite": "http://www.itv.com/downtonabbey",
73+
"schedule": {
74+
"time": "21:00",
75+
"days": ["Sunday"]
76+
},
77+
"rating": {
78+
"average": 9.1
79+
},
80+
"weight": 96,
81+
"network": {
82+
"id": 35,
83+
"name": "ITV",
84+
"country": {
85+
"name": "United Kingdom",
86+
"code": "GB",
87+
"timezone": "Europe/London"
88+
}
89+
},
90+
"webChannel": null,
91+
"dvdCountry": null,
92+
"externals": {
93+
"tvrage": 26615,
94+
"thetvdb": 193131,
95+
"imdb": "tt1606375"
96+
},
97+
"image": {
98+
"medium": "https://static.tvmaze.com/uploads/images/medium_portrait/1/4601.jpg",
99+
"original": "https://static.tvmaze.com/uploads/images/original_untouched/1/4601.jpg"
100+
},
101+
"summary": "<p>The Downton Abbey estate stands a splendid example of confidence and mettle, its family enduring for generations and its staff a well-oiled machine of propriety. But change is afoot at Downton--change far surpassing the new electric lights and telephone. A crisis of inheritance threatens to displace the resident Crawley family, in spite of the best efforts of the noble and compassionate Earl, Robert Crawley; his American heiress wife, Cora his comically implacable, opinionated mother, Violet and his beautiful, eldest daughter, Mary, intent on charting her own course. Reluctantly, the family is forced to welcome its heir apparent, the self-made and proudly modern Matthew Crawley himself none too happy about the new arrangements. As Matthew's bristly relationship with Mary begins to crackle with electricity, hope for the future of Downton's dynasty takes shape. But when petty jealousies and ambitions grow among the family and the staff, scheming and secrets--both delicious and dangerous--threaten to derail the scramble to preserve Downton Abbey. <i>Downton Abbey</i> offers a spot-on portrait of a vanishing way of life.</p>",
102+
"updated": 1627415536,
103+
"_links": {
104+
"self": {
105+
"href": "https://api.tvmaze.com/shows/251"
106+
},
107+
"previousepisode": {
108+
"href": "https://api.tvmaze.com/episodes/623237"
109+
}
110+
}
111+
}, {
112+
"id": 252,
113+
"url": "https://www.tvmaze.com/shows/252/girl-meets-world",
114+
"name": "Girl Meets World",
115+
"type": "Scripted",
116+
"language": "English",
117+
"genres": ["Drama", "Comedy", "Family"],
118+
"status": "Ended",
119+
"runtime": 30,
120+
"averageRuntime": 30,
121+
"premiered": "2014-06-27",
122+
"ended": "2017-01-20",
123+
"officialSite": "http://disneychannel.disney.com/girl-meets-world",
124+
"schedule": {
125+
"time": "18:00",
126+
"days": ["Friday"]
127+
},
128+
"rating": {
129+
"average": 7.7
130+
},
131+
"weight": 72,
132+
"network": {
133+
"id": 78,
134+
"name": "Disney Channel",
135+
"country": {
136+
"name": "United States",
137+
"code": "US",
138+
"timezone": "America/New_York"
139+
}
140+
},
141+
"webChannel": {
142+
"id": 83,
143+
"name": "DisneyNOW",
144+
"country": {
145+
"name": "United States",
146+
"code": "US",
147+
"timezone": "America/New_York"
148+
}
149+
},
150+
"dvdCountry": null,
151+
"externals": {
152+
"tvrage": 33436,
153+
"thetvdb": 267777,
154+
"imdb": "tt2543796"
155+
},
156+
"image": {
157+
"medium": "https://static.tvmaze.com/uploads/images/medium_portrait/316/792450.jpg",
158+
"original": "https://static.tvmaze.com/uploads/images/original_untouched/316/792450.jpg"
159+
},
160+
"summary": "<p><b>Girl Meets World</b> is based on ABC's hugely popular sitcom, Boy Meets World (1993). Set in New York City, the show tells the wonderfully funny heartfelt stories that Boy Meets World is renowned for - only this time from a tween girl's perspective - as the curious and bright 7th grader Riley Matthews and her quick-witted friend Maya Fox embark on an unforgettable middle school experience. But their plans for a carefree year will be adjusted slightly under the watchful eyes of Riley's parents - dad Cory, who's also a faculty member (and their new History teacher), and mom Topanga, who owns a trendy after school hangout that specializes in pudding.</p>",
161+
"updated": 1621082326,
162+
"_links": {
163+
"self": {
164+
"href": "https://api.tvmaze.com/shows/252"
165+
},
166+
"previousepisode": {
167+
"href": "https://api.tvmaze.com/episodes/1011244"
168+
}
169+
}
170+
}, {
171+
"id": 253,
172+
"url": "https://www.tvmaze.com/shows/253/hells-kitchen",
173+
"name": "Hell's Kitchen",
174+
"type": "Reality",
175+
"language": "English",
176+
"genres": ["Food"],
177+
"status": "Running",
178+
"runtime": 60,
179+
"averageRuntime": 60,
180+
"premiered": "2005-05-30",
181+
"ended": null,
182+
"officialSite": "https://www.fox.com/hells-kitchen",
183+
"schedule": {
184+
"time": "20:00",
185+
"days": ["Monday"]
186+
},
187+
"rating": {
188+
"average": 7.1
189+
},
190+
"weight": 93,
191+
"network": {
192+
"id": 4,
193+
"name": "FOX",
194+
"country": {
195+
"name": "United States",
196+
"code": "US",
197+
"timezone": "America/New_York"
198+
}
199+
},
200+
"webChannel": null,
201+
"dvdCountry": null,
202+
"externals": {
203+
"tvrage": 3828,
204+
"thetvdb": 74897,
205+
"imdb": "tt0437005"
206+
},
207+
"image": {
208+
"medium": "https://static.tvmaze.com/uploads/images/medium_portrait/324/811405.jpg",
209+
"original": "https://static.tvmaze.com/uploads/images/original_untouched/324/811405.jpg"
210+
},
211+
"summary": "<p>In <b>Hell's Kitchen</b>, aspiring chefs are put through an intense culinary academy to prove they possess the right combination of ingredients to win a life-changing grand prize.</p>",
212+
"updated": 1631607953,
213+
"_links": {
214+
"self": {
215+
"href": "https://api.tvmaze.com/shows/253"
216+
},
217+
"previousepisode": {
218+
"href": "https://api.tvmaze.com/episodes/2118484"
219+
}
220+
}
221+
}, {
222+
"id": 254,
223+
"url": "https://www.tvmaze.com/shows/254/world-series-of-poker",
224+
"name": "World Series of Poker",
225+
"type": "Sports",
226+
"language": "English",
227+
"genres": [],
228+
"status": "Running",
229+
"runtime": 60,
230+
"averageRuntime": 65,
231+
"premiered": "2006-08-22",
232+
"ended": null,
233+
"officialSite": null,
234+
"schedule": {
235+
"time": "21:00",
236+
"days": ["Monday", "Tuesday", "Sunday"]
237+
},
238+
"rating": {
239+
"average": 9
240+
},
241+
"weight": 77,
242+
"network": {
243+
"id": 180,
244+
"name": "ESPN2",
245+
"country": {
246+
"name": "United States",
247+
"code": "US",
248+
"timezone": "America/New_York"
249+
}
250+
},
251+
"webChannel": null,
252+
"dvdCountry": null,
253+
"externals": {
254+
"tvrage": 16764,
255+
"thetvdb": 79028,
256+
"imdb": "tt2733512"
257+
},
258+
"image": {
259+
"medium": "https://static.tvmaze.com/uploads/images/medium_portrait/1/4656.jpg",
260+
"original": "https://static.tvmaze.com/uploads/images/original_untouched/1/4656.jpg"
261+
},
262+
"summary": "<p>The <b>World Series of Poker</b> is where the world's best poker players battle for the title.</p>",
263+
"updated": 1574298803,
264+
"_links": {
265+
"self": {
266+
"href": "https://api.tvmaze.com/shows/254"
267+
},
268+
"previousepisode": {
269+
"href": "https://api.tvmaze.com/episodes/1684225"
270+
}
271+
}
272+
}]

0 commit comments

Comments
 (0)