|
| 1 | +package sidebar |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + |
| 8 | + "github.com/docker/docker-agent/pkg/runtime" |
| 9 | + "github.com/docker/docker-agent/pkg/session" |
| 10 | + "github.com/docker/docker-agent/pkg/tui/service" |
| 11 | +) |
| 12 | + |
| 13 | +func TestSidebar_HandleClickType_Agent(t *testing.T) { |
| 14 | + t.Parallel() |
| 15 | + |
| 16 | + sess := session.New() |
| 17 | + sessionState := service.NewSessionState(sess) |
| 18 | + sessionState.SetCurrentAgentName("agent1") |
| 19 | + sb := New(sessionState) |
| 20 | + |
| 21 | + m := sb.(*model) |
| 22 | + m.sessionHasContent = true |
| 23 | + m.titleGenerated = true |
| 24 | + m.sessionTitle = "Test" |
| 25 | + m.currentAgent = "agent1" |
| 26 | + m.availableAgents = []runtime.AgentDetails{ |
| 27 | + {Name: "agent1", Provider: "openai", Model: "gpt-4", Description: "First agent"}, |
| 28 | + {Name: "agent2", Provider: "anthropic", Model: "claude", Description: "Second agent"}, |
| 29 | + } |
| 30 | + m.width = 40 |
| 31 | + m.height = 50 |
| 32 | + |
| 33 | + // Force a render to populate agentClickZones |
| 34 | + _ = sb.View() |
| 35 | + |
| 36 | + paddingLeft := m.layoutCfg.PaddingLeft |
| 37 | + |
| 38 | + // Verify clicking on agent1 lines returns ClickAgent with "agent1" |
| 39 | + foundAgent1 := false |
| 40 | + foundAgent2 := false |
| 41 | + for y := range len(m.cachedLines) { |
| 42 | + result, agentName := sb.HandleClickType(paddingLeft+2, y) |
| 43 | + if result == ClickAgent { |
| 44 | + if agentName == "agent1" { |
| 45 | + foundAgent1 = true |
| 46 | + } |
| 47 | + if agentName == "agent2" { |
| 48 | + foundAgent2 = true |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + assert.True(t, foundAgent1, "should be able to click on agent1") |
| 53 | + assert.True(t, foundAgent2, "should be able to click on agent2") |
| 54 | +} |
0 commit comments