|
| 1 | +import { put } from "redux-saga/effects"; |
| 2 | +import { Origin, Priorities } from "@core/constants/core.constants"; |
| 3 | +import { |
| 4 | + type Schema_GridEvent, |
| 5 | + type WithId, |
| 6 | +} from "@web/common/types/web.event.types"; |
| 7 | +import { eventsEntitiesSlice } from "@web/ducks/events/slices/event.slice"; |
| 8 | +import { getSomedayEventsSlice } from "@web/ducks/events/slices/someday.slice"; |
| 9 | +import { describe, expect, it, mock } from "bun:test"; |
| 10 | + |
| 11 | +mock.module("@web/common/classes/Session", () => ({ |
| 12 | + session: { |
| 13 | + doesSessionExist: mock(), |
| 14 | + }, |
| 15 | +})); |
| 16 | + |
| 17 | +mock.module("@web/common/repositories/event/event.repository.util", () => ({ |
| 18 | + getEventRepository: mock(), |
| 19 | +})); |
| 20 | + |
| 21 | +mock.module("@web/common/utils/event/event.util", () => ({ |
| 22 | + addId: (event: Schema_GridEvent) => ({ ...event, _id: "event-1" }), |
| 23 | + assembleGridEvent: (event: Schema_GridEvent) => event, |
| 24 | + hasEventDates: (event: Schema_GridEvent) => |
| 25 | + typeof event.startDate === "string" && typeof event.endDate === "string", |
| 26 | +})); |
| 27 | + |
| 28 | +const { insertOptimisticEvent } = |
| 29 | + require("./saga.util") as typeof import("./saga.util"); |
| 30 | + |
| 31 | +describe("insertOptimisticEvent", () => { |
| 32 | + it("stores a converted Someday event before adding its id to the Someday list", () => { |
| 33 | + const event: WithId<Schema_GridEvent> = { |
| 34 | + _id: "event-1", |
| 35 | + endDate: "2026-05-18", |
| 36 | + isAllDay: false, |
| 37 | + isSomeday: true, |
| 38 | + order: 0, |
| 39 | + origin: Origin.COMPASS, |
| 40 | + position: { |
| 41 | + dragOffset: { x: 0, y: 0 }, |
| 42 | + horizontalOrder: 1, |
| 43 | + initialX: null, |
| 44 | + initialY: null, |
| 45 | + isOverlapping: false, |
| 46 | + totalEventsInGroup: 1, |
| 47 | + widthMultiplier: 1, |
| 48 | + }, |
| 49 | + priority: Priorities.UNASSIGNED, |
| 50 | + startDate: "2026-05-11", |
| 51 | + title: "Moved to sidebar", |
| 52 | + user: "user-1", |
| 53 | + }; |
| 54 | + |
| 55 | + const iterator = insertOptimisticEvent(event, true); |
| 56 | + |
| 57 | + expect(iterator.next().value).toEqual( |
| 58 | + put( |
| 59 | + eventsEntitiesSlice.actions.insert({ |
| 60 | + [event._id]: event, |
| 61 | + }), |
| 62 | + ), |
| 63 | + ); |
| 64 | + expect(iterator.next().value).toEqual( |
| 65 | + put(getSomedayEventsSlice.actions.insert(event._id)), |
| 66 | + ); |
| 67 | + }); |
| 68 | +}); |
0 commit comments