import React from "react";
import {
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react-native";
import { actionExecutor } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor";
jest.mock(
"@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor",
() => ({
actionExecutor: {
handleAction: jest.fn().mockResolvedValue(undefined),
handleActions: jest.fn().mockResolvedValue(undefined),
},
ActionResult: { Success: "success", Error: "error" },
})
);
jest.mock("../AudioPlayer/Components/Input", () => ({
AudioPlayerInput: ({ value, onChangeText, data }: any) => {
const { TextInput, Text } = require("react-native");
return (
<>
{data?.label}
>
);
},
VARIANT_NAME_PLAYLIST_INPUT: {},
}));
jest.mock("../AudioPlayer/Components/Button", () => ({
AudioPlayerButton: ({ data, onPress }: any) => {
const { Pressable, Text } = require("react-native");
return (
{data?.title}
);
},
VARIANT_TEXT_ONLY: {},
}));
import { TextInputContent } from "../TextInputContent";
const submitAction = {
type: "sendCloudEvent",
options: {
url: "https://server.com/cloud-events",
type: "com.applicaster.collection.create.v1",
subject: "edit_collection",
data: { collectionId: "playlist-123" },
},
};
const baseProps = {
inputLabel: "Name your playlist",
defaultValue: "Summer Hits",
buttonLabel: "Update",
actions: [submitAction],
};
describe("TextInputContent", () => {
beforeEach(() => {
jest.clearAllMocks();
});
it("renders default value and button label without a modal header", () => {
render();
expect(screen.queryByTestId("sheet-header")).toBeNull();
expect(screen.getByTestId("playlist-input").props.value).toBe(
"Summer Hits"
);
expect(screen.getByTestId("submit-button")).toBeTruthy();
expect(screen.getByText("Update")).toBeTruthy();
});
it("on submit merges name into sendCloudEvent data then dismisses", async () => {
render();
fireEvent.changeText(screen.getByTestId("playlist-input"), "New Name");
fireEvent.press(screen.getByTestId("submit-button"));
await waitFor(() => {
expect(actionExecutor.handleActions).toHaveBeenCalledTimes(1);
expect(actionExecutor.handleAction).toHaveBeenCalledTimes(1);
});
expect(actionExecutor.handleActions).toHaveBeenCalledWith([
{
type: "sendCloudEvent",
options: {
url: "https://server.com/cloud-events",
type: "com.applicaster.collection.create.v1",
subject: "edit_collection",
data: {
collectionId: "playlist-123",
name: "New Name",
},
},
},
]);
expect(actionExecutor.handleAction).toHaveBeenCalledWith({
type: "dismissBottomSheet",
});
});
it("forwards actionContext into handleActions so rename can refresh the List", async () => {
const actionContext = {
component: {
id: "list-1",
data: { source: "https://example.com/user/collections/abc" },
},
screenData: { id: "playlist-screen" },
};
render();
fireEvent.press(screen.getByTestId("submit-button"));
await waitFor(() => {
expect(actionExecutor.handleActions).toHaveBeenCalledTimes(1);
});
expect(actionExecutor.handleActions).toHaveBeenCalledWith(
[
{
type: "sendCloudEvent",
options: {
url: "https://server.com/cloud-events",
type: "com.applicaster.collection.create.v1",
subject: "edit_collection",
data: {
collectionId: "playlist-123",
name: "Summer Hits",
},
},
},
],
actionContext
);
});
});