package tui
import (
"testing"
)
func TestSlashCommandRoutingLogic(t *testing.T) {
tests := []struct {
name string
terminalFocused bool
hasCurrentSession bool
expectedInterceptSlash bool
description string
}{
{
name: "Terminal not focused",
terminalFocused: false,
hasCurrentSession: true,
expectedInterceptSlash: true,
description: "When terminal is not focused, slash should always open Brummer commands",
},
{
name: "No current session",
terminalFocused: true,
hasCurrentSession: false,
expectedInterceptSlash: true,
description: "When no session exists, slash should open Brummer commands",
},
{
name: "Terminal focused with session",
terminalFocused: true,
hasCurrentSession: true,
expectedInterceptSlash: false, // This will depend on cursor position
description: "When terminal focused with session, behavior depends on cursor position",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Create PTY view for testing the basic logic
view := &AICoderPTYView{
terminalFocused: tt.terminalFocused,
currentSession: nil, // Will be set based on hasCurrentSession
}
// The specific cursor position logic is tested separately
// since it requires a real PTY session with terminal state
// Test the basic routing logic without cursor position
shouldIntercept := view.ShouldInterceptSlashCommand()
if tt.hasCurrentSession {
// When there's no session, it should always intercept
if view.currentSession == nil && !shouldIntercept {
t.Errorf("%s: expected shouldIntercept=true when no session", tt.description)
}
} else {
// When there's no session, it should always intercept
if !shouldIntercept {
t.Errorf("%s: expected shouldIntercept=true when no session", tt.description)
}
}
})
}
}
func TestSlashCommandContextLogic(t *testing.T) {
// Test the core decision logic
view := &AICoderPTYView{}
// Case 1: Terminal not focused -> always intercept
view.terminalFocused = false
view.currentSession = nil
if !view.ShouldInterceptSlashCommand() {
t.Error("Should intercept when terminal not focused")
}
// Case 2: No current session -> always intercept
view.terminalFocused = true
view.currentSession = nil
if !view.ShouldInterceptSlashCommand() {
t.Error("Should intercept when no current session")
}
// Case 3: With session and focused -> depends on cursor position
// (This would require a mock session to test fully)
}