Merged in chore/SW-3321-move-selectratecontext-to- (pull request #2729)
chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Moved Select rate context to booking-flow package * chore(SW-3321): Optimised code Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user