From 82753dfa946508f754260e236951061376ab98fd Mon Sep 17 00:00:00 2001 From: SanttuA Date: Thu, 30 May 2024 09:10:32 +0300 Subject: [PATCH] Added more tests for overnight continous check --- .../tests/overnightUtils.spec.js | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/app/shared/overnight-calendar/tests/overnightUtils.spec.js b/app/shared/overnight-calendar/tests/overnightUtils.spec.js index 51b608f47..e3341f5d7 100644 --- a/app/shared/overnight-calendar/tests/overnightUtils.spec.js +++ b/app/shared/overnight-calendar/tests/overnightUtils.spec.js @@ -785,12 +785,24 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { end: '2024-04-29T09:00:00+03:00' }) ]; + const reservationsB = [ + Reservation.build({ + begin: '2024-04-27T13:00:00+03:00', + end: '2024-04-29T13:00:00+03:00' + }) + ]; const reservations2 = [ Reservation.build({ begin: '2024-04-27T13:00:00+03:00', end: '2024-04-28T09:00:00+03:00' }) ]; + const reservations2B = [ + Reservation.build({ + begin: '2024-04-27T13:00:00+03:00', + end: '2024-04-28T13:00:00+03:00' + }) + ]; const openingHours = [ { date: '2024-04-19', closes: null, opens: null }, { date: '2024-04-20', closes: '2024-04-20T20:00:00+03:00', opens: '2024-04-20T06:00:00+03:00' }, @@ -807,6 +819,7 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { ]; const overnightStartTime = '13:00:00'; const overnightEndTime = '09:00:00'; + const overnightEndTime2 = '13:00:00'; test('returns true when no reservations or closed days in selection', () => { const startDate = moment('2024-04-23').toDate(); @@ -823,6 +836,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { startDate, endDate, reservations, openingHours, overnightStartTime, overnightEndTime })) .toBe(true); + expect(isSelectionContinous({ + startDate, + endDate, + reservations: reservationsB, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(true); expect(isSelectionContinous({ startDate: startDate2, endDate: endDate2, @@ -832,6 +854,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(true); + expect(isSelectionContinous({ + startDate: startDate2, + endDate: endDate2, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(true); expect(isSelectionContinous({ startDate: startDate3, endDate: endDate3, @@ -841,6 +872,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(true); + expect(isSelectionContinous({ + startDate: startDate3, + endDate: endDate3, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(true); }); test('returns false when reservations or closed days in selection', () => { const startDate1 = moment('2024-04-23').toDate(); @@ -862,6 +902,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate1, + endDate: endDate1, + reservations: reservationsB, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate1, endDate: endDate1, @@ -871,6 +920,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate1, + endDate: endDate1, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate2, endDate: endDate2, @@ -880,6 +938,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate2, + endDate: endDate2, + reservations: reservationsB, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate2, endDate: endDate2, @@ -889,6 +956,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate2, + endDate: endDate2, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate3, endDate: endDate3, @@ -898,6 +974,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate3, + endDate: endDate3, + reservations: reservationsB, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate4, endDate: endDate4, @@ -907,6 +992,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate4, + endDate: endDate4, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); expect(isSelectionContinous({ startDate: startDate5, endDate: endDate5, @@ -916,6 +1010,15 @@ describe('app/shared/overnight-calendar/overnightUtils', () => { overnightEndTime })) .toBe(false); + expect(isSelectionContinous({ + startDate: startDate5, + endDate: endDate5, + reservations: reservations2B, + openingHours, + overnightStartTime, + overnightEndTime: overnightEndTime2 + })) + .toBe(false); }); });