xonecas.io
60255
Zn

Zoea-Nova / files

Zoea-Nova / internal / tui / scrollbar_test.go

2.1 KB
1package tui
2
3import (
4	"strings"
5	"testing"
6)
7
8func TestRenderScrollbar_AtTop(t *testing.T) {
9	height := 10
10	totalLines := 100
11	scrollOffset := 0
12
13	bar := renderScrollbar(height, totalLines, scrollOffset)
14
15	// Should be height lines
16	lines := strings.Split(bar, "\n")
17	if len(lines) != height {
18		t.Errorf("Expected %d lines, got %d", height, len(lines))
19	}
20
21	// First line should have thumb indicator
22	if !strings.Contains(lines[0], "█") && !strings.Contains(lines[0], "▓") {
23		t.Error("Expected thumb indicator in first line when at top")
24	}
25}
26
27func TestRenderScrollbar_AtBottom(t *testing.T) {
28	height := 10
29	totalLines := 100
30	scrollOffset := 90 // At bottom (90 + 10 = 100)
31
32	bar := renderScrollbar(height, totalLines, scrollOffset)
33
34	lines := strings.Split(bar, "\n")
35	if len(lines) != height {
36		t.Errorf("Expected %d lines, got %d", height, len(lines))
37	}
38
39	// Last line should have thumb indicator
40	lastLine := lines[len(lines)-1]
41	if !strings.Contains(lastLine, "█") && !strings.Contains(lastLine, "▓") {
42		t.Error("Expected thumb indicator in last line when at bottom")
43	}
44}
45
46func TestRenderScrollbar_Middle(t *testing.T) {
47	height := 10
48	totalLines := 100
49	scrollOffset := 45 // Roughly middle
50
51	bar := renderScrollbar(height, totalLines, scrollOffset)
52
53	lines := strings.Split(bar, "\n")
54
55	// Thumb should be somewhere in the middle lines (not first or last)
56	hasThumbInMiddle := false
57	for i := 2; i < len(lines)-2; i++ {
58		if strings.Contains(lines[i], "█") || strings.Contains(lines[i], "▓") {
59			hasThumbInMiddle = true
60			break
61		}
62	}
63
64	if !hasThumbInMiddle {
65		t.Error("Expected thumb indicator in middle lines when scrolled to middle")
66	}
67}
68
69func TestRenderScrollbar_NoScroll(t *testing.T) {
70	height := 10
71	totalLines := 5 // Content fits in viewport
72	scrollOffset := 0
73
74	bar := renderScrollbar(height, totalLines, scrollOffset)
75
76	lines := strings.Split(bar, "\n")
77
78	// All lines should show track (no thumb needed when everything fits)
79	for i, line := range lines {
80		if !strings.Contains(line, "│") && !strings.Contains(line, "║") {
81			t.Errorf("Expected track character in line %d when no scroll needed", i)
82		}
83	}
84}