|
|
@@ -445,13 +445,15 @@ describe("ChatTextArea", () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it("should navigate to previous prompt on arrow up", () => {
|
|
|
+ it("should navigate to previous prompt on arrow up when cursor is at beginning", () => {
|
|
|
const setInputValue = vi.fn()
|
|
|
const { container } = render(
|
|
|
<ChatTextArea {...defaultProps} setInputValue={setInputValue} inputValue="" />,
|
|
|
)
|
|
|
|
|
|
const textarea = container.querySelector("textarea")!
|
|
|
+ // Ensure cursor is at the beginning
|
|
|
+ textarea.setSelectionRange(0, 0)
|
|
|
|
|
|
// Simulate arrow up key press
|
|
|
fireEvent.keyDown(textarea, { key: "ArrowUp" })
|
|
|
@@ -755,6 +757,86 @@ describe("ChatTextArea", () => {
|
|
|
fireEvent.keyDown(textarea, { key: "ArrowUp" })
|
|
|
expect(setInputValue).toHaveBeenCalledWith("Message 2")
|
|
|
})
|
|
|
+
|
|
|
+ it("should not navigate history with arrow up when cursor is not at beginning", () => {
|
|
|
+ const setInputValue = vi.fn()
|
|
|
+ const { container } = render(
|
|
|
+ <ChatTextArea {...defaultProps} setInputValue={setInputValue} inputValue="Some text here" />,
|
|
|
+ )
|
|
|
+
|
|
|
+ const textarea = container.querySelector("textarea")!
|
|
|
+ // Set cursor to middle of text (not at beginning)
|
|
|
+ textarea.setSelectionRange(5, 5)
|
|
|
+
|
|
|
+ // Clear any calls from initial render
|
|
|
+ setInputValue.mockClear()
|
|
|
+
|
|
|
+ // Simulate arrow up key press
|
|
|
+ fireEvent.keyDown(textarea, { key: "ArrowUp" })
|
|
|
+
|
|
|
+ // Should not navigate history, allowing default behavior (move cursor to start)
|
|
|
+ expect(setInputValue).not.toHaveBeenCalled()
|
|
|
+ })
|
|
|
+
|
|
|
+ it("should navigate history with arrow up when cursor is at beginning", () => {
|
|
|
+ const setInputValue = vi.fn()
|
|
|
+ const { container } = render(
|
|
|
+ <ChatTextArea {...defaultProps} setInputValue={setInputValue} inputValue="Some text here" />,
|
|
|
+ )
|
|
|
+
|
|
|
+ const textarea = container.querySelector("textarea")!
|
|
|
+ // Set cursor to beginning of text
|
|
|
+ textarea.setSelectionRange(0, 0)
|
|
|
+
|
|
|
+ // Clear any calls from initial render
|
|
|
+ setInputValue.mockClear()
|
|
|
+
|
|
|
+ // Simulate arrow up key press
|
|
|
+ fireEvent.keyDown(textarea, { key: "ArrowUp" })
|
|
|
+
|
|
|
+ // Should navigate to history since cursor is at beginning
|
|
|
+ expect(setInputValue).toHaveBeenCalledWith("Third prompt")
|
|
|
+ })
|
|
|
+
|
|
|
+ it("should navigate history with Command+Up when cursor is at beginning", () => {
|
|
|
+ const setInputValue = vi.fn()
|
|
|
+ const { container } = render(
|
|
|
+ <ChatTextArea {...defaultProps} setInputValue={setInputValue} inputValue="Some text here" />,
|
|
|
+ )
|
|
|
+
|
|
|
+ const textarea = container.querySelector("textarea")!
|
|
|
+ // Set cursor to beginning of text
|
|
|
+ textarea.setSelectionRange(0, 0)
|
|
|
+
|
|
|
+ // Clear any calls from initial render
|
|
|
+ setInputValue.mockClear()
|
|
|
+
|
|
|
+ // Simulate Command+Up key press
|
|
|
+ fireEvent.keyDown(textarea, { key: "ArrowUp", metaKey: true })
|
|
|
+
|
|
|
+ // Should navigate to history since cursor is at beginning (same as regular Up)
|
|
|
+ expect(setInputValue).toHaveBeenCalledWith("Third prompt")
|
|
|
+ })
|
|
|
+
|
|
|
+ it("should not navigate history with Command+Up when cursor is not at beginning", () => {
|
|
|
+ const setInputValue = vi.fn()
|
|
|
+ const { container } = render(
|
|
|
+ <ChatTextArea {...defaultProps} setInputValue={setInputValue} inputValue="Some text here" />,
|
|
|
+ )
|
|
|
+
|
|
|
+ const textarea = container.querySelector("textarea")!
|
|
|
+ // Set cursor to middle of text (not at beginning)
|
|
|
+ textarea.setSelectionRange(5, 5)
|
|
|
+
|
|
|
+ // Clear any calls from initial render
|
|
|
+ setInputValue.mockClear()
|
|
|
+
|
|
|
+ // Simulate Command+Up key press
|
|
|
+ fireEvent.keyDown(textarea, { key: "ArrowUp", metaKey: true })
|
|
|
+
|
|
|
+ // Should not navigate history, allowing default behavior (same as regular Up)
|
|
|
+ expect(setInputValue).not.toHaveBeenCalled()
|
|
|
+ })
|
|
|
})
|
|
|
})
|
|
|
|