import { actionExecutor, ActionResult, } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor"; import { TextInputContent } from "../TextInputContent"; import { showTextInputAction } from "../showTextInput"; jest.mock( "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor", () => ({ actionExecutor: { handleAction: jest.fn().mockResolvedValue("success"), }, ActionResult: { Success: "success", Error: "error" }, }) ); jest.mock("../TextInputContent", () => ({ TextInputContent: function MockTextInputContent() { return null; }, })); describe("showTextInputAction", () => { beforeEach(() => { jest.clearAllMocks(); }); it("delegates to openBottomSheet with TextInputContent as body-only component", async () => { const action = { type: "showTextInput", options: { headerTitle: "Create Playlist", inputLabel: "Name your playlist", defaultValue: "", buttonLabel: "Create", actions: [ { type: "sendCloudEvent", options: { url: "https://example.com/events", type: "com.applicaster.collection.create.v1", data: {}, }, }, { type: "showToast", options: { message: "Playlist created.", }, }, ], }, }; const result = await showTextInputAction(action as any); expect(result).toBe(ActionResult.Success); expect(actionExecutor.handleAction).toHaveBeenCalledTimes(1); expect(actionExecutor.handleAction).toHaveBeenCalledWith( { type: "openBottomSheet", options: { header: { title: "Create Playlist", }, content: { component: TextInputContent, props: { inputLabel: "Name your playlist", defaultValue: "", buttonLabel: "Create", actions: action.options.actions, }, }, }, }, undefined ); }); it("returns Error when required options are missing", async () => { const action = { type: "showTextInput", options: { headerTitle: "Create Playlist", }, }; const result = await showTextInputAction(action as any); expect(result).toBe(ActionResult.Error); expect(actionExecutor.handleAction).not.toHaveBeenCalled(); }); });