internal/tui/view/detail/detail_test.go

package detail

import (
	"strings"
	"testing"

	tea "github.com/charmbracelet/bubbletea"

	"mercemay.top/httptap/internal/parser"
	"mercemay.top/httptap/internal/tui/theme"
)

func TestSetMessageRendersHeaders(t *testing.T) {
	m := New(theme.Default())
	m.SetSize(80, 20)
	m.SetMessage(parser.Message{
		StartLine: "GET / HTTP/1.1",
		Headers:   [][2]string{{"Host", "example.com"}},
	})
	if !strings.Contains(m.View(), "example.com") {
		t.Errorf("headers not shown:\n%s", m.View())
	}
}

func TestTabSwitching(t *testing.T) {
	m := New(theme.Default())
	m.SetSize(80, 20)
	m.SetMessage(parser.Message{StartLine: "GET /", Body: []byte("hello")})
	next, _ := m.Update(tea.KeyMsg{Type: tea.KeyTab})
	m = next
	if m.active != 1 {
		t.Fatalf("active = %d, want 1", m.active)
	}
	if !strings.Contains(m.View(), "hello") {
		t.Errorf("body not shown on body tab")
	}
}

func TestShiftTabWrapsAround(t *testing.T) {
	m := New(theme.Default())
	m.SetSize(40, 10)
	next, _ := m.Update(tea.KeyMsg{Type: tea.KeyShiftTab})
	m = next
	if m.active != 2 {
		t.Errorf("active = %d, want 2 (wrap)", m.active)
	}
}

func TestDetailHeight(t *testing.T) {
	m := New(theme.Default())
	m.SetSize(80, 17)
	if m.Height() != 17 {
		t.Errorf("Height = %d", m.Height())
	}
}