feat(SW-2873): Move select-hotel to booking flow * crude setup of select-hotel in partner-sas * wip * Fix linting * restructure tracking files * Remove dependency on trpc in tracking hooks * Move pageview tracking to common * Fix some lint and import issues * Add AlternativeHotelsPage * Add SelectHotelMapPage * Add AlternativeHotelsMapPage * remove next dependency in tracking store * Remove dependency on react in tracking hooks * move isSameBooking to booking-flow * Inject searchParamsComparator into tracking store * Move useTrackHardNavigation to common * Move useTrackSoftNavigation to common * Add TrackingSDK to partner-sas * call serverclient in layout * Remove unused css * Update types * Move HotelPin type * Fix todos * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Fix component Approved-by: Joakim Jäderberg
118 lines
3.1 KiB
TypeScript
118 lines
3.1 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import { RateEnum } from "@scandic-hotels/common/constants/rate"
|
|
|
|
import { isRateSelected } from "./isRateSelected"
|
|
|
|
describe("isRateSelected", () => {
|
|
it("should return false when selectedRateCode is undefined", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: undefined,
|
|
selectedRoomTypeCode: "ROOM1",
|
|
rate: { public: { rateCode: "RATE1" } },
|
|
roomTypeCode: "ROOM1",
|
|
} as any)
|
|
|
|
expect(result).toBe(false)
|
|
})
|
|
|
|
it("should return false when selectedRoomTypeCode is null", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: "RATE1",
|
|
selectedRoomTypeCode: null,
|
|
rate: { public: { rateCode: "RATE1" } },
|
|
roomTypeCode: "ROOM1",
|
|
} as any)
|
|
|
|
expect(result).toBe(false)
|
|
})
|
|
|
|
it("should return false when rateCode is undefined", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: "RATE1",
|
|
selectedRoomTypeCode: "ROOM1",
|
|
rate: { public: { rateCode: undefined } },
|
|
roomTypeCode: "ROOM1",
|
|
} as any)
|
|
|
|
expect(result).toBe(false)
|
|
})
|
|
|
|
it("should return false when roomTypeCode is null", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: "RATE1",
|
|
selectedRoomTypeCode: "ROOM1",
|
|
rate: { public: { rateCode: "RATE1" } },
|
|
roomTypeCode: null,
|
|
} as any)
|
|
|
|
expect(result).toBe(false)
|
|
})
|
|
|
|
it("should return false when rate codes don't match", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: "RATE1",
|
|
selectedRoomTypeCode: "ROOM1",
|
|
rate: { public: { rateCode: "RATE2" } },
|
|
roomTypeCode: "ROOM1",
|
|
} as any)
|
|
|
|
expect(result).toBe(false)
|
|
})
|
|
|
|
it("should return false when room type codes don't match", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: "RATE1",
|
|
selectedRoomTypeCode: "ROOM1",
|
|
rate: { public: { rateCode: "RATE1" } },
|
|
roomTypeCode: "ROOM2",
|
|
} as any)
|
|
|
|
expect(result).toBe(false)
|
|
})
|
|
|
|
it("should return true when both rate code and room type code match", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: "RATE1",
|
|
selectedRoomTypeCode: "ROOM1",
|
|
rate: { public: { rateCode: "RATE1" } },
|
|
roomTypeCode: "ROOM1",
|
|
} as any)
|
|
|
|
expect(result).toBe(true)
|
|
})
|
|
|
|
it("should handle case insensitivity in rate codes", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: "RATE1",
|
|
selectedRoomTypeCode: "ROOM1",
|
|
rate: { public: { rateCode: "rate1" } },
|
|
roomTypeCode: "ROOM1",
|
|
} as any)
|
|
|
|
expect(result).toBe(true)
|
|
})
|
|
|
|
it("should handle case insensitivity in room type codes", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: "RATE1",
|
|
selectedRoomTypeCode: "ROOM1",
|
|
rate: { public: { rateCode: "RATE1" } },
|
|
roomTypeCode: "room1",
|
|
} as any)
|
|
|
|
expect(result).toBe(true)
|
|
})
|
|
|
|
it("should work with RateEnum values", () => {
|
|
const result = isRateSelected({
|
|
selectedRateCode: RateEnum.save,
|
|
selectedRoomTypeCode: "ROOM1",
|
|
rate: { public: { rateCode: RateEnum.save } },
|
|
roomTypeCode: "ROOM1",
|
|
} as any)
|
|
|
|
expect(result).toBe(true)
|
|
})
|
|
})
|