Created
November 20, 2019 01:40
-
-
Save irek02/a43d4192d2de1fb8037d215ff4e6e595 to your computer and use it in GitHub Desktop.
jmathieu-riis
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
diff --git a/src/app/src/components/booking/booking.component.html b/src/app/src/components/booking/booking.component.html | |
index c3b4807..854496d 100644 | |
--- a/src/app/src/components/booking/booking.component.html | |
+++ b/src/app/src/components/booking/booking.component.html | |
@@ -1,11 +1,9 @@ | |
<div data-test="title">Book {{data.home.title}}</div> | |
<div data-test="price">${{data.home.price}} per night</div> | |
<label for="checkin">Select Date to Check In</label> | |
-<input type="date" | |
- id="checkin" | |
+<input id="checkin" | |
[(ngModel)]="checkinDate"> | |
<label for="checkout">Select Date to Check Out</label> | |
-<input type="date" | |
- id="checkout" | |
+<input id="checkout" | |
[(ngModel)]="checkoutDate"> | |
-<div data-test="total">${{calculateTotal()}}</div> | |
+<div data-test="total">${{calculateTotal(checkinDate, checkoutDate)}}</div> | |
diff --git a/src/app/src/components/booking/booking.component.spec.ts b/src/app/src/components/booking/booking.component.spec.ts | |
index 98c5650..9909e0a 100644 | |
--- a/src/app/src/components/booking/booking.component.spec.ts | |
+++ b/src/app/src/components/booking/booking.component.spec.ts | |
@@ -69,15 +69,18 @@ describe('BookingComponent (shows dialog of booking data per home)', () => { | |
})); | |
// FAILING TEST | |
- it('should show total price (non-functional version)', async(() => { | |
- const checkin = el('input#checkin[type="date"]'); | |
- const checkout = el('input#checkout[type="date"]'); | |
+ fit('should show total price (non-functional version)', async(() => { | |
+ const checkin = el('input#checkin'); | |
+ const checkout = el('input#checkout'); | |
+ | |
// user enters a check-in date: i.e. 12/20/19 | |
checkin.value = '2019/12/20'; | |
+ checkin.dispatchEvent(new Event('input')); | |
fixture.detectChanges(); | |
// user enters a check-out date: i.e. 12/23/19 | |
checkout.value = '2019/12/23'; | |
+ checkout.dispatchEvent(new Event('input')); | |
fixture.detectChanges(); | |
const totalElement = el('[data-test="total"]'); | |
diff --git a/src/app/src/components/booking/booking.component.ts b/src/app/src/components/booking/booking.component.ts | |
index 7ecc739..da704b2 100644 | |
--- a/src/app/src/components/booking/booking.component.ts | |
+++ b/src/app/src/components/booking/booking.component.ts | |
@@ -17,9 +17,9 @@ export class BookingComponent implements OnInit { | |
// console.log(this.data); | |
} | |
- calculateTotal() { | |
- const checkinMoment = moment(this.checkinDate, 'YYYY-MM-DD'); | |
- const checkoutMoment = moment(this.checkoutDate, 'YYYY-MM-DD'); | |
+ calculateTotal(checkIn, checkOut) { | |
+ const checkinMoment = moment(checkIn, 'YYYY-MM-DD'); | |
+ const checkoutMoment = moment(checkOut, 'YYYY-MM-DD'); | |
const days = checkoutMoment.diff(checkinMoment, 'days'); | |
return days <= 0 || isNaN(days) ? 0 : days * this.data.home.price; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment