|
| 1 | +import React from "react"; |
| 2 | +import { DraggableProvided, DraggableStateSnapshot } from "@hello-pangea/dnd"; |
| 3 | +import "@testing-library/jest-dom"; |
| 4 | +import { LEARN_CHINESE } from "@core/__mocks__/v1/events/events.misc"; |
| 5 | +import { Categories_Event } from "@core/types/event.types"; |
| 6 | +import { fireEvent, render } from "@web/__tests__/__mocks__/mock.render"; |
| 7 | +import { SidebarDraftContext } from "../../../../Draft/sidebar/context/SidebarDraftContext"; |
| 8 | +import { SomedayEventContainer } from "./SomedayEventContainer"; |
| 9 | + |
| 10 | +jest.mock( |
| 11 | + "@web/views/Calendar/components/Draft/hooks/state/useDraftForm", |
| 12 | + () => ({ |
| 13 | + useDraftForm: () => ({ |
| 14 | + context: {}, |
| 15 | + refs: { setFloating: jest.fn(), setReference: jest.fn() }, |
| 16 | + strategy: "absolute", |
| 17 | + x: 0, |
| 18 | + y: 0, |
| 19 | + getReferenceProps: () => ({}), |
| 20 | + getFloatingProps: () => ({}), |
| 21 | + }), |
| 22 | + }), |
| 23 | +); |
| 24 | + |
| 25 | +describe("SomedayEventContainer keyboard interactions", () => { |
| 26 | + it("opens the form when Enter is pressed", async () => { |
| 27 | + const onDraft = jest.fn(); |
| 28 | + const contextValue = { |
| 29 | + state: { |
| 30 | + draft: null, |
| 31 | + isDrafting: false, |
| 32 | + isOverGrid: false, |
| 33 | + isSomedayFormOpen: false, |
| 34 | + } as any, |
| 35 | + setters: { |
| 36 | + setIsSomedayFormOpen: jest.fn(), |
| 37 | + } as any, |
| 38 | + actions: { |
| 39 | + onDraft, |
| 40 | + onMigrate: jest.fn(), |
| 41 | + discard: jest.fn(), |
| 42 | + reset: jest.fn(), |
| 43 | + closeForm: jest.fn(), |
| 44 | + close: jest.fn(), |
| 45 | + } as any, |
| 46 | + }; |
| 47 | + |
| 48 | + render( |
| 49 | + <SidebarDraftContext.Provider value={contextValue as any}> |
| 50 | + <SomedayEventContainer |
| 51 | + category={Categories_Event.SOMEDAY_WEEK} |
| 52 | + event={LEARN_CHINESE} |
| 53 | + isDrafting={false} |
| 54 | + isDragging={false} |
| 55 | + isOverGrid={false} |
| 56 | + onSubmit={jest.fn()} |
| 57 | + provided={ |
| 58 | + { |
| 59 | + draggableProps: { |
| 60 | + "data-rfd-draggable-context-id": "mock-context", |
| 61 | + "data-rfd-draggable-id": "mock-id", |
| 62 | + style: {}, |
| 63 | + }, |
| 64 | + dragHandleProps: null, |
| 65 | + innerRef: jest.fn(), |
| 66 | + } as DraggableProvided |
| 67 | + } |
| 68 | + snapshot={{ isDragging: false } as DraggableStateSnapshot} |
| 69 | + setEvent={jest.fn()} |
| 70 | + weekViewRange={{ startDate: "2020-01-01", endDate: "2020-01-07" }} |
| 71 | + /> |
| 72 | + </SidebarDraftContext.Provider>, |
| 73 | + ); |
| 74 | + |
| 75 | + const btn = document.querySelector( |
| 76 | + `[data-event-id="${LEARN_CHINESE._id}"]`, |
| 77 | + )! as HTMLElement; |
| 78 | + btn.focus(); |
| 79 | + fireEvent.keyDown(btn, { key: "Enter" }); |
| 80 | + |
| 81 | + expect(onDraft).toHaveBeenCalledTimes(1); |
| 82 | + expect(onDraft).toHaveBeenCalledWith( |
| 83 | + LEARN_CHINESE, |
| 84 | + Categories_Event.SOMEDAY_WEEK, |
| 85 | + ); |
| 86 | + }); |
| 87 | +}); |
0 commit comments