mirror of
https://github.com/onyx-dot-app/onyx.git
synced 2026-10-22 19:32:55 -05:00
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import React from "react";
|
|
import { fireEvent, screen } from "@testing-library/react";
|
|
import { render } from "@tests/setup/test-utils";
|
|
import BaseInputBar from "@/sections/input/BaseInputBar";
|
|
|
|
describe("BaseInputBar queue handoff", () => {
|
|
it.each([
|
|
{ outcome: false, retained: true },
|
|
{ outcome: true, retained: false },
|
|
{ outcome: undefined, retained: false },
|
|
])(
|
|
"retains draft only when queue rejects with $outcome",
|
|
({ outcome, retained }) => {
|
|
const onQueueMessage = jest.fn(() => outcome);
|
|
const onSubmit = jest.fn();
|
|
render(
|
|
<BaseInputBar
|
|
onSubmit={onSubmit}
|
|
isRunning
|
|
onQueueMessage={onQueueMessage}
|
|
/>
|
|
);
|
|
const input = screen.getByRole("textbox", { name: "Message input" });
|
|
input.textContent = "Keep this draft";
|
|
fireEvent.input(input);
|
|
fireEvent.keyDown(input, { key: "Enter" });
|
|
expect(onQueueMessage).toHaveBeenCalledWith("Keep this draft");
|
|
expect(onSubmit).not.toHaveBeenCalled();
|
|
expect(input.textContent).toBe(retained ? "Keep this draft" : "");
|
|
}
|
|
);
|
|
});
|