Merged in feat/SW-1077-enter-details-edit-room (pull request #1360)
Feat/SW-1077 enter details edit room * feat(SW-1077): persist state when changing rooms * fix: issue with step state when closing accordion and transition to correct room when modifying step Approved-by: Pontus Dreij
This commit is contained in:
@@ -27,19 +27,26 @@ export function extractGuestFromUser(user: NonNullable<SafeUser>) {
|
||||
}
|
||||
}
|
||||
|
||||
export function checkIsSameRoom(
|
||||
export function checkIsSameBedTypes(
|
||||
storedBedTypes: string,
|
||||
bedTypesData: string
|
||||
) {
|
||||
return storedBedTypes === bedTypesData
|
||||
}
|
||||
|
||||
export function checkIsSameBooking(
|
||||
prev: SelectRateSearchParams,
|
||||
next: SelectRateSearchParams
|
||||
) {
|
||||
const { rooms: prevRooms, ...prevBooking } = prev
|
||||
|
||||
const prevRoomsWithoutRateCodes = prevRooms.map(
|
||||
({ rateCode, counterRateCode, ...room }) => room
|
||||
({ rateCode, counterRateCode, roomTypeCode, ...room }) => room
|
||||
)
|
||||
const { rooms: nextRooms, ...nextBooking } = next
|
||||
|
||||
const nextRoomsWithoutRateCodes = nextRooms.map(
|
||||
({ rateCode, counterRateCode, ...room }) => room
|
||||
({ rateCode, counterRateCode, roomTypeCode, ...room }) => room
|
||||
)
|
||||
|
||||
return isEqual(
|
||||
@@ -313,8 +320,9 @@ export function handleStepProgression(state: DetailsState) {
|
||||
|
||||
const roomStatus = selectRoomStatus(state)
|
||||
if (roomStatus.isComplete) {
|
||||
const nextRoomIndex = state.bookingProgress.currentRoomIndex + 1
|
||||
|
||||
const nextRoomIndex = state.bookingProgress.roomStatuses.findIndex(
|
||||
(room) => !room.isComplete
|
||||
)
|
||||
roomStatus.lastCompletedStep = roomStatus.currentStep ?? undefined
|
||||
roomStatus.currentStep = null
|
||||
const nextRoomStatus = selectRoomStatus(state, nextRoomIndex)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, test } from "@jest/globals"
|
||||
import { act, renderHook } from "@testing-library/react"
|
||||
import { act, renderHook, waitFor } from "@testing-library/react"
|
||||
import { type PropsWithChildren } from "react"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
@@ -18,6 +18,8 @@ import EnterDetailsProvider from "@/providers/EnterDetailsProvider"
|
||||
import { selectRoom, selectRoomStatus } from "./helpers"
|
||||
import { detailsStorageName, useEnterDetailsStore } from "."
|
||||
|
||||
import type { BedTypeSelection } from "@/types/components/hotelReservation/enterDetails/bedType"
|
||||
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
import { StepEnum } from "@/types/enums/step"
|
||||
import type { PersistedState } from "@/types/stores/enter-details"
|
||||
|
||||
@@ -38,7 +40,8 @@ interface CreateWrapperParams {
|
||||
showBreakfastStep?: boolean
|
||||
breakfastIncluded?: boolean
|
||||
mustBeGuaranteed?: boolean
|
||||
onlyOneBedType?: boolean
|
||||
bookingParams?: SelectRateSearchParams
|
||||
bedTypes?: BedTypeSelection[]
|
||||
}
|
||||
|
||||
function createWrapper(params: Partial<CreateWrapperParams> = {}) {
|
||||
@@ -46,19 +49,18 @@ function createWrapper(params: Partial<CreateWrapperParams> = {}) {
|
||||
showBreakfastStep = true,
|
||||
breakfastIncluded = false,
|
||||
mustBeGuaranteed = false,
|
||||
onlyOneBedType = false,
|
||||
bookingParams = booking,
|
||||
bedTypes = [bedType.king, bedType.queen],
|
||||
} = params
|
||||
|
||||
return function Wrapper({ children }: PropsWithChildren) {
|
||||
return (
|
||||
<EnterDetailsProvider
|
||||
booking={booking}
|
||||
booking={bookingParams}
|
||||
showBreakfastStep={showBreakfastStep}
|
||||
roomsData={[
|
||||
{
|
||||
bedTypes: onlyOneBedType
|
||||
? [bedType.king]
|
||||
: [bedType.king, bedType.queen],
|
||||
bedTypes,
|
||||
packages: null,
|
||||
mustBeGuaranteed,
|
||||
breakfastIncluded,
|
||||
@@ -68,9 +70,7 @@ function createWrapper(params: Partial<CreateWrapperParams> = {}) {
|
||||
roomRate: roomRate,
|
||||
},
|
||||
{
|
||||
bedTypes: onlyOneBedType
|
||||
? [bedType.king]
|
||||
: [bedType.king, bedType.queen],
|
||||
bedTypes,
|
||||
packages: null,
|
||||
mustBeGuaranteed,
|
||||
breakfastIncluded,
|
||||
@@ -95,102 +95,104 @@ describe("Enter Details Store", () => {
|
||||
window.sessionStorage.clear()
|
||||
})
|
||||
|
||||
test("initialize with correct default values", () => {
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
const state = result.current
|
||||
describe("initial state", () => {
|
||||
test("initialize with correct default values", () => {
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
const state = result.current
|
||||
|
||||
expect(state.booking).toEqual(booking)
|
||||
expect(state.breakfast).toEqual(undefined)
|
||||
expect(state.booking).toEqual(booking)
|
||||
expect(state.breakfast).toEqual(undefined)
|
||||
|
||||
// room 1
|
||||
const room1Status = selectRoomStatus(result.current, 0)
|
||||
const room1 = selectRoom(result.current, 0)
|
||||
// room 1
|
||||
const room1Status = selectRoomStatus(result.current, 0)
|
||||
const room1 = selectRoom(result.current, 0)
|
||||
|
||||
expect(room1Status.currentStep).toBe(StepEnum.selectBed)
|
||||
expect(room1Status.currentStep).toBe(StepEnum.selectBed)
|
||||
|
||||
expect(room1.roomPrice.perNight.local.price).toEqual(
|
||||
roomRate.publicRate.localPrice.pricePerNight
|
||||
)
|
||||
expect(room1.bedType).toEqual(undefined)
|
||||
expect(Object.values(room1.guest).every((value) => value === ""))
|
||||
expect(room1.roomPrice.perNight.local.price).toEqual(
|
||||
roomRate.publicRate.localPrice.pricePerNight
|
||||
)
|
||||
expect(room1.bedType).toEqual(undefined)
|
||||
expect(Object.values(room1.guest).every((value) => value === ""))
|
||||
|
||||
// room 2
|
||||
const room2Status = selectRoomStatus(result.current, 1)
|
||||
const room2 = selectRoom(result.current, 1)
|
||||
// room 2
|
||||
const room2Status = selectRoomStatus(result.current, 1)
|
||||
const room2 = selectRoom(result.current, 1)
|
||||
|
||||
expect(room2Status.currentStep).toBe(null)
|
||||
expect(room2.roomPrice.perNight.local.price).toEqual(
|
||||
room2.roomRate.publicRate.localPrice.pricePerNight
|
||||
)
|
||||
expect(room2.bedType).toEqual(undefined)
|
||||
expect(Object.values(room2.guest).every((value) => value === ""))
|
||||
})
|
||||
expect(room2Status.currentStep).toBe(null)
|
||||
expect(room2.roomPrice.perNight.local.price).toEqual(
|
||||
room2.roomRate.publicRate.localPrice.pricePerNight
|
||||
)
|
||||
expect(room2.bedType).toEqual(undefined)
|
||||
expect(Object.values(room2.guest).every((value) => value === ""))
|
||||
})
|
||||
|
||||
test("initialize with correct values from session storage", () => {
|
||||
const storage: PersistedState = {
|
||||
booking: booking,
|
||||
bookingProgress: {
|
||||
currentRoomIndex: 0,
|
||||
canProceedToPayment: true,
|
||||
roomStatuses: [
|
||||
{
|
||||
isComplete: false,
|
||||
currentStep: StepEnum.selectBed,
|
||||
lastCompletedStep: undefined,
|
||||
steps: {
|
||||
[StepEnum.selectBed]: {
|
||||
step: StepEnum.selectBed,
|
||||
isValid: true,
|
||||
},
|
||||
[StepEnum.breakfast]: {
|
||||
step: StepEnum.breakfast,
|
||||
isValid: true,
|
||||
},
|
||||
[StepEnum.details]: {
|
||||
step: StepEnum.details,
|
||||
isValid: true,
|
||||
test("initialize with correct values from session storage", () => {
|
||||
const storage: PersistedState = {
|
||||
booking: booking,
|
||||
bookingProgress: {
|
||||
currentRoomIndex: 0,
|
||||
canProceedToPayment: true,
|
||||
roomStatuses: [
|
||||
{
|
||||
isComplete: false,
|
||||
currentStep: StepEnum.selectBed,
|
||||
lastCompletedStep: undefined,
|
||||
steps: {
|
||||
[StepEnum.selectBed]: {
|
||||
step: StepEnum.selectBed,
|
||||
isValid: true,
|
||||
},
|
||||
[StepEnum.breakfast]: {
|
||||
step: StepEnum.breakfast,
|
||||
isValid: true,
|
||||
},
|
||||
[StepEnum.details]: {
|
||||
step: StepEnum.details,
|
||||
isValid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
rooms: [
|
||||
{
|
||||
roomFeatures: null,
|
||||
roomRate: roomRate,
|
||||
roomType: "Classic Double",
|
||||
cancellationText: "Non-refundable",
|
||||
rateDetails: [],
|
||||
bedType: {
|
||||
roomTypeCode: bedType.king.value,
|
||||
description: bedType.king.description,
|
||||
},
|
||||
adults: 1,
|
||||
childrenInRoom: [],
|
||||
breakfast: breakfastPackage,
|
||||
guest: guestDetailsNonMember,
|
||||
roomPrice: roomPrice,
|
||||
},
|
||||
],
|
||||
},
|
||||
rooms: [
|
||||
{
|
||||
roomFeatures: null,
|
||||
roomRate: roomRate,
|
||||
roomType: "Classic Double",
|
||||
cancellationText: "Non-refundable",
|
||||
rateDetails: [],
|
||||
bedType: {
|
||||
roomTypeCode: bedType.king.value,
|
||||
description: bedType.king.description,
|
||||
},
|
||||
adults: 1,
|
||||
childrenInRoom: [],
|
||||
breakfast: breakfastPackage,
|
||||
guest: guestDetailsNonMember,
|
||||
roomPrice: roomPrice,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
window.sessionStorage.setItem(detailsStorageName, JSON.stringify(storage))
|
||||
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
expect(result.current.booking).toEqual(storage.booking)
|
||||
expect(result.current.rooms[0]).toEqual(storage.rooms[0])
|
||||
expect(result.current.bookingProgress).toEqual(storage.bookingProgress)
|
||||
window.sessionStorage.setItem(detailsStorageName, JSON.stringify(storage))
|
||||
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
expect(result.current.booking).toEqual(storage.booking)
|
||||
expect(result.current.rooms[0]).toEqual(storage.rooms[0])
|
||||
expect(result.current.bookingProgress).toEqual(storage.bookingProgress)
|
||||
})
|
||||
})
|
||||
|
||||
test("add bedtype and proceed to next step", async () => {
|
||||
@@ -349,86 +351,6 @@ describe("Enter Details Store", () => {
|
||||
expect(result.current.bookingProgress.currentRoomIndex).toEqual(1)
|
||||
})
|
||||
|
||||
test("total price should be set properly", async () => {
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
const publicRate = roomRate.publicRate.localPrice.pricePerStay
|
||||
const memberRate = roomRate.memberRate?.localPrice.pricePerStay ?? 0
|
||||
|
||||
const initialTotalPrice = publicRate * result.current.rooms.length
|
||||
expect(result.current.totalPrice.local.price).toEqual(initialTotalPrice)
|
||||
|
||||
// room 1
|
||||
await act(async () => {
|
||||
result.current.actions.updateBedType({
|
||||
roomTypeCode: bedType.king.value,
|
||||
description: bedType.king.description,
|
||||
})
|
||||
result.current.actions.updateBreakfast(breakfastPackage)
|
||||
})
|
||||
|
||||
let expectedTotalPrice =
|
||||
initialTotalPrice + Number(breakfastPackage.localPrice.price)
|
||||
expect(result.current.totalPrice.local.price).toEqual(expectedTotalPrice)
|
||||
|
||||
await act(async () => {
|
||||
result.current.actions.updateDetails(guestDetailsMember)
|
||||
})
|
||||
|
||||
expectedTotalPrice =
|
||||
memberRate + publicRate + Number(breakfastPackage.localPrice.price)
|
||||
expect(result.current.totalPrice.local.price).toEqual(expectedTotalPrice)
|
||||
|
||||
// room 2
|
||||
await act(async () => {
|
||||
result.current.actions.updateBedType({
|
||||
roomTypeCode: bedType.king.value,
|
||||
description: bedType.king.description,
|
||||
})
|
||||
result.current.actions.updateBreakfast(breakfastPackage)
|
||||
})
|
||||
|
||||
expectedTotalPrice =
|
||||
memberRate + publicRate + Number(breakfastPackage.localPrice.price) * 2
|
||||
expect(result.current.totalPrice.local.price).toEqual(expectedTotalPrice)
|
||||
|
||||
await act(async () => {
|
||||
result.current.actions.updateDetails(guestDetailsNonMember)
|
||||
})
|
||||
|
||||
expect(result.current.totalPrice.local.price).toEqual(expectedTotalPrice)
|
||||
})
|
||||
|
||||
test("room price should be set properly", async () => {
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
const publicRate = roomRate.publicRate.localPrice.pricePerStay
|
||||
const memberRate = roomRate.memberRate?.localPrice.pricePerStay ?? 0
|
||||
|
||||
let room1 = selectRoom(result.current, 0)
|
||||
expect(room1.roomPrice.perStay.local.price).toEqual(publicRate)
|
||||
|
||||
let room2 = selectRoom(result.current, 0)
|
||||
expect(room2.roomPrice.perStay.local.price).toEqual(publicRate)
|
||||
|
||||
await act(async () => {
|
||||
result.current.actions.updateDetails(guestDetailsMember)
|
||||
})
|
||||
|
||||
room1 = selectRoom(result.current, 0)
|
||||
expect(room1.roomPrice.perStay.local.price).toEqual(memberRate)
|
||||
})
|
||||
|
||||
test("breakfast step should be hidden when breakfast is included", async () => {
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
@@ -448,7 +370,7 @@ describe("Enter Details Store", () => {
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper({ onlyOneBedType: true }),
|
||||
wrapper: createWrapper({ bedTypes: [bedType.queen] }),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -460,4 +382,252 @@ describe("Enter Details Store", () => {
|
||||
expect(room2Status.steps[StepEnum.selectBed].isValid).toEqual(true)
|
||||
expect(room2Status.currentStep).toEqual(null)
|
||||
})
|
||||
|
||||
describe("price calculation", () => {
|
||||
test("total price should be set properly", async () => {
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
const publicRate = roomRate.publicRate.localPrice.pricePerStay
|
||||
const memberRate = roomRate.memberRate?.localPrice.pricePerStay ?? 0
|
||||
|
||||
const initialTotalPrice = publicRate * result.current.rooms.length
|
||||
expect(result.current.totalPrice.local.price).toEqual(initialTotalPrice)
|
||||
|
||||
// room 1
|
||||
await act(async () => {
|
||||
result.current.actions.updateBedType({
|
||||
roomTypeCode: bedType.king.value,
|
||||
description: bedType.king.description,
|
||||
})
|
||||
result.current.actions.updateBreakfast(breakfastPackage)
|
||||
})
|
||||
|
||||
let expectedTotalPrice =
|
||||
initialTotalPrice + Number(breakfastPackage.localPrice.price)
|
||||
expect(result.current.totalPrice.local.price).toEqual(expectedTotalPrice)
|
||||
|
||||
await act(async () => {
|
||||
result.current.actions.updateDetails(guestDetailsMember)
|
||||
})
|
||||
|
||||
expectedTotalPrice =
|
||||
memberRate + publicRate + Number(breakfastPackage.localPrice.price)
|
||||
expect(result.current.totalPrice.local.price).toEqual(expectedTotalPrice)
|
||||
|
||||
// room 2
|
||||
await act(async () => {
|
||||
result.current.actions.updateBedType({
|
||||
roomTypeCode: bedType.king.value,
|
||||
description: bedType.king.description,
|
||||
})
|
||||
result.current.actions.updateBreakfast(breakfastPackage)
|
||||
})
|
||||
|
||||
expectedTotalPrice =
|
||||
memberRate + publicRate + Number(breakfastPackage.localPrice.price) * 2
|
||||
expect(result.current.totalPrice.local.price).toEqual(expectedTotalPrice)
|
||||
|
||||
await act(async () => {
|
||||
result.current.actions.updateDetails(guestDetailsNonMember)
|
||||
})
|
||||
|
||||
expect(result.current.totalPrice.local.price).toEqual(expectedTotalPrice)
|
||||
})
|
||||
|
||||
test("room price should be set properly", async () => {
|
||||
const { result } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
const publicRate = roomRate.publicRate.localPrice.pricePerStay
|
||||
const memberRate = roomRate.memberRate?.localPrice.pricePerStay ?? 0
|
||||
|
||||
let room1 = selectRoom(result.current, 0)
|
||||
expect(room1.roomPrice.perStay.local.price).toEqual(publicRate)
|
||||
|
||||
let room2 = selectRoom(result.current, 0)
|
||||
expect(room2.roomPrice.perStay.local.price).toEqual(publicRate)
|
||||
|
||||
await act(async () => {
|
||||
result.current.actions.updateDetails(guestDetailsMember)
|
||||
})
|
||||
|
||||
room1 = selectRoom(result.current, 0)
|
||||
expect(room1.roomPrice.perStay.local.price).toEqual(memberRate)
|
||||
})
|
||||
})
|
||||
|
||||
describe("change room", () => {
|
||||
test("changing to room with new bedtypes requires selecting bed again", async () => {
|
||||
const { result: firstRun } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper({ bedTypes: [bedType.king, bedType.queen] }),
|
||||
}
|
||||
)
|
||||
|
||||
const selectedBedType = {
|
||||
roomTypeCode: bedType.king.value,
|
||||
description: bedType.king.description,
|
||||
}
|
||||
|
||||
// add bedtype
|
||||
await act(async () => {
|
||||
firstRun.current.actions.updateBedType(selectedBedType)
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
firstRun.current.actions.updateBreakfast(false) // 'no breakfast' selected
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
firstRun.current.actions.updateDetails(guestDetailsNonMember)
|
||||
})
|
||||
|
||||
const updatedBooking = {
|
||||
...booking,
|
||||
rooms: booking.rooms.map((r) => ({
|
||||
...r,
|
||||
roomTypeCode: "NEW",
|
||||
})),
|
||||
}
|
||||
|
||||
// render again to change the bedtypes
|
||||
const { result: secondRun } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper({
|
||||
bookingParams: updatedBooking,
|
||||
bedTypes: [bedType.single, bedType.queen],
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
const room = selectRoom(secondRun.current, 0)
|
||||
const roomStatus = selectRoomStatus(secondRun.current, 0)
|
||||
|
||||
// bed type should be unset since the bed types have changed
|
||||
expect(room.bedType).toEqual(undefined)
|
||||
|
||||
// bed step should be unselected
|
||||
expect(roomStatus.currentStep).toBe(StepEnum.selectBed)
|
||||
expect(roomStatus.steps[StepEnum.selectBed].isValid).toBe(false)
|
||||
|
||||
// other steps should still be selected
|
||||
expect(room.breakfast).toBe(false)
|
||||
expect(roomStatus.steps[StepEnum.breakfast]?.isValid).toBe(true)
|
||||
expect(room.guest).toEqual(guestDetailsNonMember)
|
||||
expect(roomStatus.steps[StepEnum.details].isValid).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
test("changing to room with single bedtype option should skip step", async () => {
|
||||
const { result: firstRun } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper({ bedTypes: [bedType.king, bedType.queen] }),
|
||||
}
|
||||
)
|
||||
|
||||
const selectedBedType = {
|
||||
roomTypeCode: bedType.king.value,
|
||||
description: bedType.king.description,
|
||||
}
|
||||
|
||||
// add bedtype
|
||||
await act(async () => {
|
||||
firstRun.current.actions.updateBedType(selectedBedType)
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
firstRun.current.actions.updateBreakfast(breakfastPackage)
|
||||
})
|
||||
|
||||
const updatedBooking = {
|
||||
...booking,
|
||||
rooms: booking.rooms.map((r) => ({
|
||||
...r,
|
||||
roomTypeCode: "NEW",
|
||||
})),
|
||||
}
|
||||
|
||||
// render again to change the bedtypes
|
||||
const { result: secondRun } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper({
|
||||
bookingParams: updatedBooking,
|
||||
bedTypes: [bedType.queen],
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
const room = selectRoom(secondRun.current, 0)
|
||||
const roomStatus = selectRoomStatus(secondRun.current, 0)
|
||||
|
||||
expect(room.bedType).toEqual({
|
||||
roomTypeCode: bedType.queen.value,
|
||||
description: bedType.queen.description,
|
||||
})
|
||||
|
||||
expect(roomStatus.steps[StepEnum.selectBed].isValid).toBe(true)
|
||||
expect(roomStatus.steps[StepEnum.breakfast]?.isValid).toBe(true)
|
||||
|
||||
expect(roomStatus.steps[StepEnum.details].isValid).toBe(false)
|
||||
expect(roomStatus.currentStep).toBe(StepEnum.details)
|
||||
})
|
||||
})
|
||||
|
||||
test("if booking has changed, stored values should be discarded", async () => {
|
||||
const { result: firstRun } = renderHook(
|
||||
() => useEnterDetailsStore((state) => state),
|
||||
{
|
||||
wrapper: createWrapper({ bedTypes: [bedType.king, bedType.queen] }),
|
||||
}
|
||||
)
|
||||
|
||||
const selectedBedType = {
|
||||
roomTypeCode: bedType.king.value,
|
||||
description: bedType.king.description,
|
||||
}
|
||||
|
||||
// add bedtype
|
||||
await act(async () => {
|
||||
firstRun.current.actions.updateBedType(selectedBedType)
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
firstRun.current.actions.updateBreakfast(breakfastPackage)
|
||||
})
|
||||
|
||||
const updatedBooking = {
|
||||
...booking,
|
||||
hotelId: "0001",
|
||||
fromDate: "2030-01-01",
|
||||
toDate: "2030-01-02",
|
||||
}
|
||||
|
||||
renderHook(() => useEnterDetailsStore((state) => state), {
|
||||
wrapper: createWrapper({
|
||||
bookingParams: updatedBooking,
|
||||
bedTypes: [bedType.queen],
|
||||
}),
|
||||
})
|
||||
|
||||
await waitFor(() => {
|
||||
const storageItem = window.sessionStorage.getItem(detailsStorageName)
|
||||
expect(storageItem).toBe(null)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user