Last active 1748325732

lolpee69 revised this gist 1748325732. Go to revision

1 file changed, 977 insertions

error(file created)

@@ -0,0 +1,977 @@
1 +
2 + FAIL src/test/home.test.js
3 + Home component
4 + ✕ DidMount (108ms)
5 + ✕ play zone content (2ms)
6 + ✕ card content (1ms)
7 + ✕ BookNow Click (1ms)
8 + ✕ On Clicking Book Now (1ms)
9 +
10 + ● Home component › DidMount
11 +
12 + TypeError: Cannot read property 'contextTypes' of undefined
13 +
14 + 36 | { id: 3, src: FootBall, name: "FootBall", slots: bookSlot4 }
15 + 37 | ]
16 + > 38 | component = shallow(
17 + | ^
18 + 39 | <Games
19 + 40 | Games={Games1}
20 + 41 | selectGame={mockfn3}
21 +
22 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
23 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
24 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
25 + at Object.beforeEach (src/test/home.test.js:38:24)
26 +
27 + ● Home component › DidMount
28 +
29 + expect(jest.fn()).toHaveBeenCalledTimes(expected)
30 +
31 + Expected number of calls: 1
32 + Received number of calls: 0
33 +
34 + 48 | });
35 + 49 | it("DidMount", () => {
36 + > 50 | expect(mockfn1).toHaveBeenCalledTimes(1);
37 + | ^
38 + 51 | expect(mockfn2).toHaveBeenCalledTimes(1);
39 + 52 | })
40 + 53 | it("play zone content", () => {
41 +
42 + at Object.it (src/test/home.test.js:50:21)
43 +
44 + ● Home component › play zone content
45 +
46 + TypeError: Cannot read property 'contextTypes' of undefined
47 +
48 + 36 | { id: 3, src: FootBall, name: "FootBall", slots: bookSlot4 }
49 + 37 | ]
50 + > 38 | component = shallow(
51 + | ^
52 + 39 | <Games
53 + 40 | Games={Games1}
54 + 41 | selectGame={mockfn3}
55 +
56 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
57 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
58 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
59 + at Object.beforeEach (src/test/home.test.js:38:24)
60 +
61 + ● Home component › play zone content
62 +
63 + TypeError: Cannot read property 'find' of undefined
64 +
65 + 52 | })
66 + 53 | it("play zone content", () => {
67 + > 54 | expect(component.find("header").length).toBe(1);
68 + | ^
69 + 55 | expect(component.find("header").text()).toEqual("Play Zone ");
70 + 56 | expect(component.find(".Card").length).toBe(4);
71 + 57 | const align = component
72 +
73 + at Object.it (src/test/home.test.js:54:22)
74 +
75 + ● Home component › card content
76 +
77 + TypeError: Cannot read property 'contextTypes' of undefined
78 +
79 + 36 | { id: 3, src: FootBall, name: "FootBall", slots: bookSlot4 }
80 + 37 | ]
81 + > 38 | component = shallow(
82 + | ^
83 + 39 | <Games
84 + 40 | Games={Games1}
85 + 41 | selectGame={mockfn3}
86 +
87 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
88 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
89 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
90 + at Object.beforeEach (src/test/home.test.js:38:24)
91 +
92 + ● Home component › card content
93 +
94 + TypeError: Cannot read property 'find' of undefined
95 +
96 + 64 | });
97 + 65 | it("card content", () => {
98 + > 66 | const Cards = component.find(".Card");
99 + | ^
100 + 67 | const Product = Cards.find("ul").map(child => child.text());
101 + 68 | expect(Product).toEqual([
102 + 69 | "BasketBallBook Now",
103 +
104 + at Object.it (src/test/home.test.js:66:29)
105 +
106 + ● Home component › BookNow Click
107 +
108 + TypeError: Cannot read property 'contextTypes' of undefined
109 +
110 + 36 | { id: 3, src: FootBall, name: "FootBall", slots: bookSlot4 }
111 + 37 | ]
112 + > 38 | component = shallow(
113 + | ^
114 + 39 | <Games
115 + 40 | Games={Games1}
116 + 41 | selectGame={mockfn3}
117 +
118 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
119 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
120 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
121 + at Object.beforeEach (src/test/home.test.js:38:24)
122 +
123 + ● Home component › BookNow Click
124 +
125 + TypeError: Cannot read property 'instance' of undefined
126 +
127 + 74 | });
128 + 75 | it("BookNow Click", () => {
129 + > 76 | const spy = jest.spyOn(component.instance(), "handlebook");
130 + | ^
131 + 77 | const BookNow_Btn = component
132 + 78 | .find("center")
133 + 79 | .at(0)
134 +
135 + at Object.it (src/test/home.test.js:76:38)
136 +
137 + ● Home component › On Clicking Book Now
138 +
139 + TypeError: Cannot read property 'contextTypes' of undefined
140 +
141 + 36 | { id: 3, src: FootBall, name: "FootBall", slots: bookSlot4 }
142 + 37 | ]
143 + > 38 | component = shallow(
144 + | ^
145 + 39 | <Games
146 + 40 | Games={Games1}
147 + 41 | selectGame={mockfn3}
148 +
149 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
150 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
151 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
152 + at Object.beforeEach (src/test/home.test.js:38:24)
153 +
154 + ● Home component › On Clicking Book Now
155 +
156 + TypeError: Cannot read property 'instance' of undefined
157 +
158 + 86 | });
159 + 87 | it("On Clicking Book Now", () => {
160 + > 88 | const spy = jest.spyOn(component.instance(), "handleSearch");
161 + | ^
162 + 89 | const check_btn = component
163 + 90 | .find("center")
164 + 91 | .at(1)
165 +
166 + at Object.it (src/test/home.test.js:88:38)
167 +
168 + console.error node_modules/react/cjs/react.development.js:315
169 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
170 +
171 + Check your code at book.test.js:50.
172 +
173 + console.error node_modules/react/cjs/react.development.js:315
174 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
175 +
176 + Check your code at book.test.js:50.
177 +
178 + console.error node_modules/react/cjs/react.development.js:315
179 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
180 +
181 + Check your code at book.test.js:50.
182 +
183 + console.error node_modules/react/cjs/react.development.js:315
184 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
185 +
186 + Check your code at book.test.js:50.
187 +
188 + console.error node_modules/react/cjs/react.development.js:315
189 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
190 +
191 + Check your code at book.test.js:143.
192 +
193 + console.error node_modules/react/cjs/react.development.js:315
194 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
195 +
196 + Check your code at book.test.js:50.
197 +
198 + console.error node_modules/react/cjs/react.development.js:315
199 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
200 +
201 + Check your code at book.test.js:50.
202 +
203 + console.error node_modules/react/cjs/react.development.js:315
204 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
205 +
206 + Check your code at book.test.js:214.
207 +
208 + console.error node_modules/react/cjs/react.development.js:315
209 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
210 +
211 + Check your code at book.test.js:50.
212 +
213 + console.error node_modules/react/cjs/react.development.js:315
214 + Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
215 +
216 + Check your code at book.test.js:250.
217 +
218 + FAIL src/test/book.test.js
219 + Book page
220 + ✕ Book Content (81ms)
221 + ✕ input fields (1ms)
222 + ✕ err msg: select your slot (1ms)
223 + ✕ err msg check your field (2ms)
224 + ✕ Display slot (1ms)
225 + ✕ Booking not opened (1ms)
226 + ✕ Booking Closed (2ms)
227 +
228 + ● Book page › Book Content
229 +
230 + TypeError: Cannot read property 'contextTypes' of undefined
231 +
232 + 47 | )
233 + 48 | const slotBooked1 = undefined
234 + > 49 | component = shallow(
235 + | ^
236 + 50 | <Booking
237 + 51 | game={Games1}
238 + 52 | selectedGame={selectedGame1}
239 +
240 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
241 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
242 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
243 + at Object.beforeEach (src/test/book.test.js:49:24)
244 +
245 + ● Book page › Book Content
246 +
247 + TypeError: Cannot read property 'find' of undefined
248 +
249 + 65 | const Date_display =
250 + 66 | new Date().getDate() + 1 + "/" + (new Date().getMonth() + 1) + "/" + new Date().getFullYear();
251 + > 67 | expect(component.find("header").length).toBe(1);
252 + | ^
253 + 68 | expect(component.find("header").childAt(0).length).toBe(1);
254 + 69 | expect(component.find("header").find("p").length).toBe(1);
255 + 70 | expect(component.find("header").text()).toBe(
256 +
257 + at Object.it (src/test/book.test.js:67:22)
258 +
259 + ● Book page › input fields
260 +
261 + TypeError: Cannot read property 'contextTypes' of undefined
262 +
263 + 47 | )
264 + 48 | const slotBooked1 = undefined
265 + > 49 | component = shallow(
266 + | ^
267 + 50 | <Booking
268 + 51 | game={Games1}
269 + 52 | selectedGame={selectedGame1}
270 +
271 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
272 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
273 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
274 + at Object.beforeEach (src/test/book.test.js:49:24)
275 +
276 + ● Book page › input fields
277 +
278 + TypeError: Cannot read property 'find' of undefined
279 +
280 + 81 | });
281 + 82 | it("input fields", () => {
282 + > 83 | expect(component.find("#contact").length).toBe(2);
283 + | ^
284 + 84 | component
285 + 85 | .find("#contact")
286 + 86 | .at(0)
287 +
288 + at Object.it (src/test/book.test.js:83:22)
289 +
290 + ● Book page › err msg: select your slot
291 +
292 + TypeError: Cannot read property 'contextTypes' of undefined
293 +
294 + 47 | )
295 + 48 | const slotBooked1 = undefined
296 + > 49 | component = shallow(
297 + | ^
298 + 50 | <Booking
299 + 51 | game={Games1}
300 + 52 | selectedGame={selectedGame1}
301 +
302 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
303 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
304 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
305 + at Object.beforeEach (src/test/book.test.js:49:24)
306 +
307 + ● Book page › err msg: select your slot
308 +
309 + TypeError: Cannot read property 'find' of undefined
310 +
311 + 104 | });
312 + 105 | it("err msg: select your slot", () => {
313 + > 106 | component.find("#book_button").simulate("Click");
314 + | ^
315 + 107 | expect(component.state().errorStmt).toEqual("Select your slot!!!");
316 + 108 | component
317 + 109 | .find("#contact")
318 +
319 + at Object.it (src/test/book.test.js:106:15)
320 +
321 + ● Book page › err msg check your field
322 +
323 + TypeError: Cannot read property 'contextTypes' of undefined
324 +
325 + 47 | )
326 + 48 | const slotBooked1 = undefined
327 + > 49 | component = shallow(
328 + | ^
329 + 50 | <Booking
330 + 51 | game={Games1}
331 + 52 | selectedGame={selectedGame1}
332 +
333 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
334 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
335 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
336 + at Object.beforeEach (src/test/book.test.js:49:24)
337 +
338 + ● Book page › err msg check your field
339 +
340 + TypeError: Cannot read property 'contextTypes' of undefined
341 +
342 + 140 | { id: 3, startTime: "11.00 A.M", endTime: "12.00 P.M", slotStatus: "btn btn-success" }
343 + 141 | ]
344 + > 142 | const wrapper = shallow(
345 + | ^
346 + 143 | <Booking
347 + 144 | game={Games2}
348 + 145 | selectedGame={selectedGame2}
349 +
350 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
351 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
352 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
353 + at Object.it (src/test/book.test.js:142:28)
354 +
355 + ● Book page › Display slot
356 +
357 + TypeError: Cannot read property 'contextTypes' of undefined
358 +
359 + 47 | )
360 + 48 | const slotBooked1 = undefined
361 + > 49 | component = shallow(
362 + | ^
363 + 50 | <Booking
364 + 51 | game={Games1}
365 + 52 | selectedGame={selectedGame1}
366 +
367 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
368 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
369 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
370 + at Object.beforeEach (src/test/book.test.js:49:24)
371 +
372 + ● Book page › Display slot
373 +
374 + TypeError: Cannot read property 'find' of undefined
375 +
376 + 193 |
377 + 194 | it("Display slot", () => {
378 + > 195 | expect(component.find("Connect(Slots)").length).toBe(1);
379 + | ^
380 + 196 | });
381 + 197 | it("Booking not opened", () => {
382 + 198 | const Games3 = [
383 +
384 + at Object.it (src/test/book.test.js:195:22)
385 +
386 + ● Book page › Booking not opened
387 +
388 + TypeError: Cannot read property 'contextTypes' of undefined
389 +
390 + 47 | )
391 + 48 | const slotBooked1 = undefined
392 + > 49 | component = shallow(
393 + | ^
394 + 50 | <Booking
395 + 51 | game={Games1}
396 + 52 | selectedGame={selectedGame1}
397 +
398 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
399 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
400 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
401 + at Object.beforeEach (src/test/book.test.js:49:24)
402 +
403 + ● Book page › Booking not opened
404 +
405 + TypeError: Cannot read property 'contextTypes' of undefined
406 +
407 + 211 | )
408 + 212 | const slotBooked3 = undefined
409 + > 213 | const wrapper = shallow(
410 + | ^
411 + 214 | <Booking
412 + 215 | game={Games3}
413 + 216 | selectedGame={selectedGame3}
414 +
415 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
416 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
417 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
418 + at Object.it (src/test/book.test.js:213:28)
419 +
420 + ● Book page › Booking Closed
421 +
422 + TypeError: Cannot read property 'contextTypes' of undefined
423 +
424 + 47 | )
425 + 48 | const slotBooked1 = undefined
426 + > 49 | component = shallow(
427 + | ^
428 + 50 | <Booking
429 + 51 | game={Games1}
430 + 52 | selectedGame={selectedGame1}
431 +
432 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
433 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
434 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
435 + at Object.beforeEach (src/test/book.test.js:49:24)
436 +
437 + ● Book page › Booking Closed
438 +
439 + TypeError: Cannot read property 'contextTypes' of undefined
440 +
441 + 247 | const slotBooked1 = undefined
442 + 248 | const Date_display = new Date().getDate() + 1 + "/" + (new Date().getMonth() + 1) + "/" + new Date().getFullYear();
443 + > 249 | const wrapper = shallow(
444 + | ^
445 + 250 | <Booking
446 + 251 | game={Games1}
447 + 252 | selectedGame={selectedGame1}
448 +
449 + at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:693:54)
450 + at new ShallowWrapper (node_modules/enzyme/src/ShallowWrapper.js:411:22)
451 + at shallow (node_modules/enzyme/src/shallow.js:10:10)
452 + at Object.it (src/test/book.test.js:249:28)
453 +
454 + FAIL src/test/slot.test.js
455 + Slot component
456 + ✕ Slot Content (27ms)
457 + ✕ handle_Slot (59ms)
458 +
459 + ● Slot component › Slot Content
460 +
461 + expect(received).toEqual(expected) // deep equality
462 +
463 + - Expected
464 + + Received
465 +
466 + - Array [
467 + - "09.00 A.M - 10.00 A.M",
468 + - "10.00 A.M - 11.00 A.M",
469 + - "11.00 A.M - 12.00 P.M",
470 + - "12.00 P.M - 01.00 P.M",
471 + - "01.00 P.M - 02.00 P.M",
472 + - "02.00 P.M - 03.00 P.M",
473 + - "03.00 P.M - 04.00 P.M",
474 + - "04.00 P.M - 05.00 P.M",
475 + - "05.00 P.M - 06.00 P.M",
476 + - ]
477 + + Array []
478 +
479 + 62 | let slot = component.find(".slot_list");
480 + 63 | const Product = slot.find("h4").map(child => child.text());
481 + > 64 | expect(Product).toEqual([
482 + | ^
483 + 65 | "09.00 A.M - 10.00 A.M",
484 + 66 | "10.00 A.M - 11.00 A.M",
485 + 67 | "11.00 A.M - 12.00 P.M",
486 +
487 + at Object.it (src/test/slot.test.js:64:21)
488 +
489 + ● Slot component › handle_Slot
490 +
491 + Method “simulate” is meant to be run on 1 node. 0 found instead.
492 +
493 + 81 | .find("span")
494 + 82 | .at(3);
495 + > 83 | slot.simulate("click");
496 + | ^
497 + 84 | expect(spy).toBeCalledTimes(1);
498 + 85 | });
499 + 86 | });
500 +
501 + at ShallowWrapper.single (node_modules/enzyme/src/ShallowWrapper.js:1652:13)
502 + at ShallowWrapper.simulate (node_modules/enzyme/src/ShallowWrapper.js:1133:17)
503 + at Object.it (src/test/slot.test.js:83:10)
504 +
505 + FAIL src/test/reducer.test.js
506 + testing cart reducer
507 + ✕ initial state check (7ms)
508 + ✕ UPDATE_BOOKING (4ms)
509 + ✕ select game(onBook) (6ms)
510 + ✕ onShow (1ms)
511 + ✕ on select slot (5ms)
512 + ✕ DONE_BOOKING (1ms)
513 + ✕ doneBooking (1ms)
514 + ✕ check Booking (2ms)
515 +
516 + ● testing cart reducer › initial state check
517 +
518 + expect(received).toEqual(expected) // deep equality
519 +
520 + - Expected
521 + + Received
522 +
523 + Object {
524 + - "Games": Array [],
525 + + "Games": Array [
526 + + "Cricket",
527 + + "Football",
528 + + "Tennis",
529 + + ],
530 + "bookingCheck": Array [],
531 + "details": Array [],
532 + - "selectedDate": 2025-05-28T00:00:00.000Z,
533 + + "selectedDate": "2025-05-28",
534 + "selectedGame": Array [],
535 + "slotBooked": undefined,
536 + }
537 +
538 + 19 | };
539 + 20 | it("initial state check", () => {
540 + > 21 | expect(bookNowReducer(undefined, {})).toEqual(initState);
541 + | ^
542 + 22 | });
543 + 23 | it("UPDATE_BOOKING", () => {
544 + 24 | const state = {
545 +
546 + at Object.it (src/test/reducer.test.js:21:43)
547 +
548 + ● testing cart reducer › UPDATE_BOOKING
549 +
550 + expect(received).toEqual(expected) // deep equality
551 +
552 + - Expected
553 + + Received
554 +
555 + Object {
556 + - "Games": Array [
557 + - Object {
558 + - "id": 0,
559 + - "name": "BasketBall",
560 + - "slots": Array [
561 + - Object {
562 + - "endTime": "10.00 A.M",
563 + - "id": 1,
564 + - "slotStatus": "btn btn-success",
565 + - "startTime": "09.00 A.M",
566 + - },
567 + - Object {
568 + - "endTime": "11.00 A.M",
569 + - "id": 2,
570 + - "slotStatus": "btn btn-success",
571 + - "startTime": "10.00 A.M",
572 + - },
573 + - Object {
574 + - "endTime": "12.00 P.M",
575 + - "id": 3,
576 + - "slotStatus": "btn btn-success",
577 + - "startTime": "11.00 A.M",
578 + - },
579 + - Object {
580 + - "endTime": "01.00 P.M",
581 + - "id": 4,
582 + - "slotStatus": "btn btn-success",
583 + - "startTime": "12.00 P.M",
584 + - },
585 + - Object {
586 + - "endTime": "02.00 P.M",
587 + - "id": 5,
588 + - "slotStatus": "btn btn-success",
589 + - "startTime": "01.00 P.M",
590 + - },
591 + - Object {
592 + - "endTime": "03.00 P.M",
593 + - "id": 6,
594 + - "slotStatus": "btn btn-success",
595 + - "startTime": "02.00 P.M",
596 + - },
597 + - Object {
598 + - "endTime": "04.00 P.M",
599 + - "id": 7,
600 + - "slotStatus": "btn btn-success",
601 + - "startTime": "03.00 P.M",
602 + - },
603 + - Object {
604 + - "endTime": "05.00 P.M",
605 + - "id": 8,
606 + - "slotStatus": "btn btn-success",
607 + - "startTime": "04.00 P.M",
608 + - },
609 + - Object {
610 + - "endTime": "06.00 P.M",
611 + - "id": 9,
612 + - "slotStatus": "btn btn-success",
613 + - "startTime": "05.00 P.M",
614 + - },
615 + - ],
616 + - "src": "basket_ball.jpeg",
617 + - },
618 + - Object {
619 + - "id": 1,
620 + - "name": "VolleyBall",
621 + - "slots": Array [
622 + - Object {
623 + - "endTime": "10.00 A.M",
624 + - "id": 1,
625 + - "slotStatus": "btn btn-success",
626 + - "startTime": "09.00 A.M",
627 + - },
628 + - Object {
629 + - "endTime": "11.00 A.M",
630 + - "id": 2,
631 + - "slotStatus": "btn btn-success",
632 + - "startTime": "10.00 A.M",
633 + - },
634 + - Object {
635 + - "endTime": "12.00 P.M",
636 + - "id": 3,
637 + - "slotStatus": "btn btn-success",
638 + - "startTime": "11.00 A.M",
639 + - },
640 + - Object {
641 + - "endTime": "01.00 P.M",
642 + - "id": 4,
643 + - "slotStatus": "btn btn-success",
644 + - "startTime": "12.00 P.M",
645 + - },
646 + - Object {
647 + - "endTime": "02.00 P.M",
648 + - "id": 5,
649 + - "slotStatus": "btn btn-success",
650 + - "startTime": "01.00 P.M",
651 + - },
652 + - Object {
653 + - "endTime": "03.00 P.M",
654 + - "id": 6,
655 + - "slotStatus": "btn btn-success",
656 + - "startTime": "02.00 P.M",
657 + - },
658 + - Object {
659 + - "endTime": "04.00 P.M",
660 + - "id": 7,
661 + - "slotStatus": "btn btn-success",
662 + - "startTime": "03.00 P.M",
663 + - },
664 + - Object {
665 + - "endTime": "05.00 P.M",
666 + - "id": 8,
667 + - "slotStatus": "btn btn-success",
668 + - "startTime": "04.00 P.M",
669 + - },
670 + - Object {
671 + - "endTime": "06.00 P.M",
672 + - "id": 9,
673 + - "slotStatus": "btn btn-success",
674 + - "startTime": "05.00 P.M",
675 + - },
676 + - ],
677 + - "src": "volleyBall.jpeg",
678 + - },
679 + - ],
680 + - "details": Array [
681 + - Object {
682 + - "bookingId": "14440074",
683 + - "contact": "9876443111",
684 + - "game": "BasketBall",
685 + - "name": "Roger",
686 + - "slot": Object {
687 + - "endTime": "01.00 P.M",
688 + - "id": 4,
689 + - "slotStatus": "btn btn-success",
690 + - "startTime": "12.00 P.M",
691 + - },
692 + - "slotDate": "6/12/2020",
693 + - },
694 + - Object {
695 + - "bookingId": "92303869",
696 + - "contact": "9867844311",
697 + - "game": "FootBall",
698 + - "name": "shelly",
699 + - "slot": Object {
700 + - "endTime": "12.00 P.M",
701 + - "id": 3,
702 + - "slotStatus": "btn btn-success",
703 + - "startTime": "11.00 A.M",
704 + - },
705 + - "slotDate": "6/12/2020",
706 + - },
707 + - ],
708 + + "Games": Array [],
709 + + "details": Array [],
710 + }
711 +
712 + 42 | }
713 + 43 | ]
714 + > 44 | })).toEqual({
715 + | ^
716 + 45 | Games: [
717 + 46 | { id: 0, src: BasketBall, name: "BasketBall", slots: bookSlot1 },
718 + 47 | { id: 1, src: VolleyBall, name: "VolleyBall", slots: bookSlot2 }
719 +
720 + at Object.it (src/test/reducer.test.js:44:9)
721 +
722 + ● testing cart reducer › select game(onBook)
723 +
724 + expect(received).toEqual(expected) // deep equality
725 +
726 + - Expected
727 + + Received
728 +
729 + @@ -121,67 +121,9 @@
730 + },
731 + ],
732 + "src": "volleyBall.jpeg",
733 + },
734 + ],
735 + - "selectedGame": Object {
736 + - "id": 1,
737 + - "name": "VolleyBall",
738 + - "slots": Array [
739 + - Object {
740 + - "endTime": "10.00 A.M",
741 + - "id": 1,
742 + - "slotStatus": "btn btn-success",
743 + - "startTime": "09.00 A.M",
744 + - },
745 + - Object {
746 + - "endTime": "11.00 A.M",
747 + - "id": 2,
748 + - "slotStatus": "btn btn-success",
749 + - "startTime": "10.00 A.M",
750 + - },
751 + - Object {
752 + - "endTime": "12.00 P.M",
753 + - "id": 3,
754 + - "slotStatus": "btn btn-success",
755 + - "startTime": "11.00 A.M",
756 + - },
757 + - Object {
758 + - "endTime": "01.00 P.M",
759 + - "id": 4,
760 + - "slotStatus": "btn btn-success",
761 + - "startTime": "12.00 P.M",
762 + - },
763 + - Object {
764 + - "endTime": "02.00 P.M",
765 + - "id": 5,
766 + - "slotStatus": "btn btn-success",
767 + - "startTime": "01.00 P.M",
768 + - },
769 + - Object {
770 + - "endTime": "03.00 P.M",
771 + - "id": 6,
772 + - "slotStatus": "btn btn-success",
773 + - "startTime": "02.00 P.M",
774 + - },
775 + - Object {
776 + - "endTime": "04.00 P.M",
777 + - "id": 7,
778 + - "slotStatus": "btn btn-success",
779 + - "startTime": "03.00 P.M",
780 + - },
781 + - Object {
782 + - "endTime": "05.00 P.M",
783 + - "id": 8,
784 + - "slotStatus": "btn btn-success",
785 + - "startTime": "04.00 P.M",
786 + - },
787 + - Object {
788 + - "endTime": "06.00 P.M",
789 + - "id": 9,
790 + - "slotStatus": "btn btn-success",
791 + - "startTime": "05.00 P.M",
792 + - },
793 + + "selectedGame": Array [
794 + + undefined,
795 + ],
796 + - "src": "volleyBall.jpeg",
797 + - },
798 + }
799 +
800 + 67 | selectedGame: []
801 + 68 | };
802 + > 69 | expect(bookNowReducer(state, { type: "SELECT_GAME", id: 1 })).toEqual({
803 + | ^
804 + 70 | Games: [
805 + 71 | { id: 0, src: BasketBall, name: "BasketBall", slots: bookSlot1 },
806 + 72 | { id: 1, src: VolleyBall, name: "VolleyBall", slots: bookSlot2 }
807 +
808 + at Object.it (src/test/reducer.test.js:69:67)
809 +
810 + ● testing cart reducer › onShow
811 +
812 + expect(received).toEqual(expected) // deep equality
813 +
814 + - Expected
815 + + Received
816 +
817 + Object {
818 + - "selectedDate": "Wed Mar 11 2020 12:00:00 GMT+0530 (India Standard Time)",
819 + + "selectedDate": 2025-05-28T00:00:00.000Z,
820 + }
821 +
822 + 124 | Day: "Wed Mar 11 2020 12:00:00 GMT+0530 (India Standard Time)"
823 + 125 | })
824 + > 126 | ).toEqual({
825 + | ^
826 + 127 | selectedDate: "Wed Mar 11 2020 12:00:00 GMT+0530 (India Standard Time)"
827 + 128 | });
828 + 129 | });
829 +
830 + at Object.it (src/test/reducer.test.js:126:7)
831 +
832 + ● testing cart reducer › on select slot
833 +
834 + expect(received).toEqual(expected) // deep equality
835 +
836 + - Expected
837 + + Received
838 +
839 + @@ -58,12 +58,7 @@
840 + "startTime": "05.00 P.M",
841 + },
842 + ],
843 + "src": "volleyBall.jpeg",
844 + },
845 + - "slotBooked": Object {
846 + - "endTime": "11.00 A.M",
847 + - "id": 2,
848 + - "slotStatus": "btn btn-primary",
849 + - "startTime": "10.00 A.M",
850 + - },
851 + + "slotBooked": undefined,
852 + }
853 +
854 + 133 | slotBooked: undefined
855 + 134 | };
856 + > 135 | expect(bookNowReducer(state, { type: "ON_SELECT_SLOT", id: 2 })).toEqual({
857 + | ^
858 + 136 | selectedGame: { id: 1, src: VolleyBall, name: "VolleyBall", slots: bookSlot2 },
859 + 137 | slotBooked: { id: 2, startTime: "10.00 A.M", endTime: "11.00 A.M", slotStatus: "btn btn-primary" }
860 + 138 | });
861 +
862 + at Object.it (src/test/reducer.test.js:135:70)
863 +
864 + ● testing cart reducer › DONE_BOOKING
865 +
866 + expect(received).toEqual(expected) // deep equality
867 +
868 + - Expected
869 + + Received
870 +
871 + @@ -10,13 +10,18 @@
872 + "startTime": "09.00 A.M",
873 + },
874 + Object {
875 + "endTime": "11.00 A.M",
876 + "id": 2,
877 + - "slotStatus": "btn btn-danger",
878 + + "slotStatus": "btn btn-primary",
879 + "startTime": "10.00 A.M",
880 + },
881 + ],
882 + "src": "volleyBall.jpeg",
883 + },
884 + - "slotBooked": undefined,
885 + + "slotBooked": Object {
886 + + "endTime": "11.00 A.M",
887 + + "id": 2,
888 + + "slotStatus": "btn btn-primary",
889 + + "startTime": "10.00 A.M",
890 + + },
891 + }
892 +
893 + 177 | slotBooked: { id: 2, startTime: "10.00 A.M", endTime: "11.00 A.M", slotStatus: "btn btn-primary" }
894 + 178 | };
895 + > 179 | expect(bookNowReducer(state, { type: "DONE_BOOKING" })).toEqual({
896 + | ^
897 + 180 | selectedGame: {
898 + 181 | id: 1, src: VolleyBall, name: "VolleyBall",
899 + 182 | slots: [
900 +
901 + at Object.it (src/test/reducer.test.js:179:61)
902 +
903 + ● testing cart reducer › doneBooking
904 +
905 + expect(received).toEqual(expected) // deep equality
906 +
907 + - Expected
908 + + Received
909 +
910 + Object {
911 + - "slotBooked": undefined,
912 + + "slotBooked": Object {
913 + + "endTime": "11.00 A.M",
914 + + "id": 2,
915 + + "slotStatus": "btn btn-primary",
916 + + "startTime": "10.00 A.M",
917 + + },
918 + }
919 +
920 + 193 | slotBooked: { id: 2, startTime: "10.00 A.M", endTime: "11.00 A.M", slotStatus: "btn btn-primary" }
921 + 194 | };
922 + > 195 | expect(bookNowReducer(state, { type: "ICON_CLICK", id: 2 })).toEqual({
923 + | ^
924 + 196 | slotBooked: undefined
925 + 197 | })
926 + 198 | })
927 +
928 + at Object.it (src/test/reducer.test.js:195:66)
929 +
930 + ● testing cart reducer › check Booking
931 +
932 + expect(received).toEqual(expected) // deep equality
933 +
934 + - Expected
935 + + Received
936 +
937 + @@ -1,21 +1,7 @@
938 + Object {
939 + - "bookingCheck": Array [
940 + - Object {
941 + - "bookingId": "92303869",
942 + - "contact": "9867844311",
943 + - "game": "FootBall",
944 + - "name": "shelly",
945 + - "slot": Object {
946 + - "endTime": "12.00 P.M",
947 + - "id": 3,
948 + - "slotStatus": "btn btn-success",
949 + - "startTime": "11.00 A.M",
950 + - },
951 + - "slotDate": "6/12/2020",
952 + - },
953 + - ],
954 + + "bookingCheck": Array [],
955 + "details": Array [
956 + Object {
957 + "bookingId": "14440074",
958 + "contact": "9876443111",
959 + "game": "BasketBall",
960 +
961 + 219 | expect(
962 + 220 | bookNowReducer(state, { type: "CHECK_BOOKING", payload: "9230" })
963 + > 221 | ).toEqual({
964 + | ^
965 + 222 | bookingCheck: [
966 + 223 | {
967 + 224 | bookingId: "92303869",
968 +
969 + at Object.it (src/test/reducer.test.js:221:7)
970 +
971 + Test Suites: 5 failed, 5 total
972 + Tests: 29 failed, 29 total
973 + Snapshots: 0 total
974 + Time: 5.281s
975 + Ran all test suites.
976 + npm ERR! Test failed. See above for more details.
977 + user@c067045535d2:/projects/challenge$

lolpee69 revised this gist 1748325007. Go to revision

8 files changed, 321 insertions

Action(file created)

@@ -0,0 +1,31 @@
1 +
2 + export const SELECT_GAME = 'SELECT_GAME';
3 + export const SELECT_DATE = 'SELECT_DATE';
4 + export const SELECT_SLOT = 'SELECT_SLOT';
5 + export const BOOK_SLOT = 'BOOK_SLOT';
6 + export const SAVE_DETAILS = 'SAVE_DETAILS';
7 +
8 + export const selectGame = (game) => ({
9 + type: SELECT_GAME,
10 + payload: game,
11 + });
12 +
13 + export const selectDate = (date) => ({
14 + type: SELECT_DATE,
15 + payload: date,
16 + });
17 +
18 + export const selectSlot = (slot) => ({
19 + type: SELECT_SLOT,
20 + payload: slot,
21 + });
22 +
23 + export const bookSlot = (booking) => ({
24 + type: BOOK_SLOT,
25 + payload: booking,
26 + });
27 +
28 + export const saveDetails = (details) => ({
29 + type: SAVE_DETAILS,
30 + payload: details,
31 + });

App.js(file created)

@@ -0,0 +1,26 @@
1 + import "./App.css";
2 + import Games from "./pages/home";
3 + import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
4 + import React, { Component } from "react";
5 + import Booking from "./pages/book";
6 + import Search_Booking from "./pages/search_booking";
7 + class App extends Component {
8 + state = {};
9 + render() {
10 + return (
11 + <div>
12 + <Router>
13 + <div>
14 + <Switch>
15 + <Route exact path="/" component={Games} />
16 + <Route exact path="/booking" component={Booking} />
17 + <Route exact path="/search" component={Search_Booking} />
18 + </Switch>
19 + </div>
20 + </Router>
21 + </div>
22 + );
23 + }
24 + }
25 +
26 + export default App;

Book(file created)

@@ -0,0 +1,91 @@
1 + import React, { useState } from 'react';
2 + import { useSelector, useDispatch } from 'react-redux';
3 + import { bookSlot, saveDetails, selectSlot } from './action';
4 + import { useNavigate } from 'react-router-dom';
5 +
6 + const slots = ['10AM', '11AM', '12PM', '1PM', '2PM', '3PM', '4PM'];
7 +
8 + const Book = () => {
9 + const dispatch = useDispatch();
10 + const navigate = useNavigate();
11 + const { selectedGame, selectedDate, slotBooked, bookingCheck } = useSelector(state => state);
12 +
13 + const [selectedSlot, setSelectedSlot] = useState(null);
14 + const [name, setName] = useState('');
15 + const [contact, setContact] = useState('');
16 +
17 + const today = new Date().toISOString().split('T')[0];
18 + const tomorrow = new Date();
19 + tomorrow.setDate(new Date().getDate() + 1);
20 + const formattedTomorrow = tomorrow.toISOString().split('T')[0];
21 +
22 + const handleSlotClick = (slot) => {
23 + if (bookingCheck.some(b => b.slot === slot && b.date === selectedDate)) return;
24 + setSelectedSlot(slot);
25 + dispatch(selectSlot(slot));
26 + };
27 +
28 + const validate = () => {
29 + if (!selectedSlot) {
30 + alert('Select your slot!!!');
31 + return false;
32 + }
33 + const nameRegex = /^[A-Za-z ]+$/;
34 + const phoneRegex = /^[0-9]{10}$/;
35 + if (!nameRegex.test(name) || !phoneRegex.test(contact)) {
36 + alert('Invalid Input!!!');
37 + return false;
38 + }
39 + return true;
40 + };
41 +
42 + const handleBook = () => {
43 + if (!validate()) return;
44 + const bookingID = Math.floor(1000 + Math.random() * 9000);
45 + dispatch(bookSlot({ id: bookingID, name, contact, game: selectedGame[0], slot: selectedSlot, date: selectedDate }));
46 + dispatch(saveDetails({ id: bookingID, name, contact }));
47 + alert(`Booking successful! Your ID is ${bookingID}`);
48 + navigate('/');
49 + };
50 +
51 + const renderSlots = () => {
52 + return slots.map(slot => {
53 + const isBooked = bookingCheck.some(b => b.slot === slot && b.date === selectedDate);
54 + const isSelected = selectedSlot === slot;
55 + let color = 'green';
56 + if (isBooked) color = 'red';
57 + else if (isSelected) color = 'blue';
58 +
59 + return (
60 + <button
61 + key={slot}
62 + onClick={() => handleSlotClick(slot)}
63 + style={{ backgroundColor: color, margin: '5px' }}
64 + >
65 + {slot}
66 + </button>
67 + );
68 + });
69 + };
70 +
71 + return (
72 + <div>
73 + <h2>Game: {selectedGame[0]}</h2>
74 + <h3>Date: {selectedDate}</h3>
75 + <button onClick={() => navigate('/')}>Back</button>
76 +
77 + {selectedDate === today && <p>Booking has been closed. Book your slot for {formattedTomorrow}</p>}
78 + {selectedDate === formattedTomorrow && (
79 + <>
80 + <div>{renderSlots()}</div>
81 + <input placeholder="Name" value={name} onChange={(e) => setName(e.target.value)} />
82 + <input placeholder="Contact" value={contact} onChange={(e) => setContact(e.target.value)} />
83 + <button onClick={handleBook}>Book Now</button>
84 + </>
85 + )}
86 + {selectedDate > formattedTomorrow && <p>Booking is not opened yet</p>}
87 + </div>
88 + );
89 + };
90 +
91 + export default Book;

Home(file created)

@@ -0,0 +1,30 @@
1 + import React from 'react';
2 + import { useDispatch } from 'react-redux';
3 + import { useNavigate } from 'react-router-dom';
4 + import { selectGame } from './action';
5 +
6 + const Home = () => {
7 + const games = ['Cricket', 'Football', 'Tennis'];
8 + const dispatch = useDispatch();
9 + const navigate = useNavigate();
10 +
11 + const handleBookNow = (game) => {
12 + dispatch(selectGame(game));
13 + navigate('/book');
14 + };
15 +
16 + return (
17 + <div>
18 + <h1>Available Games</h1>
19 + {games.map((game) => (
20 + <div key={game} style={{ margin: '10px', border: '1px solid black', padding: '10px' }}>
21 + <h2>{game}</h2>
22 + <button onClick={() => handleBookNow(game)}>Book Now</button>
23 + </div>
24 + ))}
25 + <button onClick={() => navigate('/search')}>Check your booking</button>
26 + </div>
27 + );
28 + };
29 +
30 + export default Home;

Index(file created)

@@ -0,0 +1,14 @@
1 + import React from 'react';
2 + import ReactDOM from 'react-dom/client';
3 + import App from './App';
4 + import { Provider } from 'react-redux';
5 + import { createStore } from 'redux';
6 + import reducer from './reducer';
7 +
8 + const store = createStore(reducer);
9 + const root = ReactDOM.createRoot(document.getElementById('root'));
10 + root.render(
11 + <Provider store={store}>
12 + <App />
13 + </Provider>
14 + );

Reducer(file created)

@@ -0,0 +1,40 @@
1 +
2 + import {
3 + SELECT_GAME,
4 + SELECT_DATE,
5 + SELECT_SLOT,
6 + BOOK_SLOT,
7 + SAVE_DETAILS
8 + } from './action';
9 +
10 + const tomorrow = new Date();
11 + tomorrow.setDate(tomorrow.getDate() + 1);
12 + const formattedTomorrow = tomorrow.toISOString().split('T')[0];
13 +
14 + const initialState = {
15 + Games: ['Cricket', 'Football', 'Tennis'],
16 + selectedGame: [],
17 + selectedDate: formattedTomorrow,
18 + slotBooked: undefined,
19 + details: [],
20 + bookingCheck: [],
21 + };
22 +
23 + const reducer = (state = initialState, action) => {
24 + switch (action.type) {
25 + case SELECT_GAME:
26 + return { ...state, selectedGame: [action.payload] };
27 + case SELECT_DATE:
28 + return { ...state, selectedDate: action.payload };
29 + case SELECT_SLOT:
30 + return { ...state, slotBooked: action.payload };
31 + case BOOK_SLOT:
32 + return { ...state, bookingCheck: [...state.bookingCheck, action.payload] };
33 + case SAVE_DETAILS:
34 + return { ...state, details: [...state.details, action.payload] };
35 + default:
36 + return state;
37 + }
38 + };
39 +
40 + export default reducer;

Search(file created)

@@ -0,0 +1,44 @@
1 + import React, { useState } from 'react';
2 + import { useSelector } from 'react-redux';
3 + import { useNavigate } from 'react-router-dom';
4 +
5 + const Search = () => {
6 + const { bookingCheck } = useSelector((state) => state);
7 + const [searchId, setSearchId] = useState('');
8 + const [foundBooking, setFoundBooking] = useState(null);
9 + const navigate = useNavigate();
10 +
11 + const handleSearch = () => {
12 + const match = bookingCheck.find(b => b.id.toString() === searchId.trim());
13 + setFoundBooking(match || 'not_found');
14 + };
15 +
16 + return (
17 + <div>
18 + <h2>Search Booking</h2>
19 + <input
20 + type="text"
21 + placeholder="Enter Booking ID"
22 + value={searchId}
23 + onChange={(e) => setSearchId(e.target.value)}
24 + />
25 + <button onClick={handleSearch}>Search</button>
26 + <button onClick={() => navigate('/')}>Back</button>
27 +
28 + {bookingCheck.length === 0 && <p>No Booking happened yet</p>}
29 + {foundBooking === 'not_found' && <p>No Booking Found</p>}
30 + {foundBooking && foundBooking !== 'not_found' && (
31 + <div style={{ marginTop: '10px' }}>
32 + <p>ID: {foundBooking.id}</p>
33 + <p>Name: {foundBooking.name}</p>
34 + <p>Contact: {foundBooking.contact}</p>
35 + <p>Game: {foundBooking.game}</p>
36 + <p>Slot: {foundBooking.slot}</p>
37 + <p>Date: {foundBooking.date}</p>
38 + </div>
39 + )}
40 + </div>
41 + );
42 + };
43 +
44 + export default Search;

Slot(file created)

@@ -0,0 +1,45 @@
1 + Components/slot.js
2 +
3 + import React, { Component } from "react";
4 + import { connect } from "react-redux";
5 + import { selectSlot } from "../Action/action";
6 + class Slots extends Component {
7 + handleSlot = id => {
8 + this.props.selectSlot(id);
9 + };
10 +
11 + render() {
12 + // Template for each slot
13 + // <div key={slot.id} className="slot_list">
14 + // <h4>
15 + // <span
16 + // className={slot.slotStatus}
17 + // style={{ cursor: "pointer" }}
18 + // >
19 +
20 + // </span>
21 + // </h4>
22 + // </div>
23 +
24 + return (<div>
25 + {/* code for slot goes here */}
26 + </div>);
27 + }
28 + }
29 +
30 + const mapStateToProps = state => {
31 + return {
32 + selectedGame: state.selectedGame,
33 + bookingSlot: state.slotBooked
34 + };
35 + };
36 + const mapDispatchToProps = dispatch => {
37 + return {
38 + selectSlot: id => dispatch(selectSlot(id))
39 + };
40 + };
41 +
42 + export default connect(
43 + mapStateToProps,
44 + mapDispatchToProps
45 + )(Slots);
Newer Older