main 6af0a61

form_view_test.go RawHistoryFolder

1package views
2
3import (
4	"errors"
5	"strings"
6	"testing"
7
8	"github.com/bnema/archup/internal/interfaces/tui/models"
9)
10
11func TestRenderForm(t *testing.T) {
12	// Create a test form model
13	fm := models.NewFormModel()
14
15	// Render the form
16	output := RenderForm(fm, "")
17
18	// Verify key content is present
19	checks := []string{
20		"ArchUp Installer", // Title
21		"Hostname:",        // Field labels
22		"Username:",
23		"↑↓ Navigate", // Instructions
24	}
25
26	for _, check := range checks {
27		if !strings.Contains(output, check) {
28			t.Errorf("Expected form output to contain '%s', but it didn't", check)
29		}
30	}
31
32	// Verify output is not empty
33	if len(output) == 0 {
34		t.Error("Form output should not be empty")
35	}
36
37	t.Logf("Form rendered successfully with %d characters", len(output))
38}
39
40func TestRenderFormWithError(t *testing.T) {
41	// Create a test form model with error
42	fm := models.NewFormModel()
43	testErr := "Test error message"
44	fm.SetError(errors.New(testErr))
45
46	// Render the form
47	output := RenderForm(fm, "")
48
49	// Verify error is displayed
50	if !strings.Contains(output, testErr) {
51		t.Errorf("Expected error message '%s' in form output", testErr)
52	}
53}
54
55func TestRenderFormWithDifferentFocus(t *testing.T) {
56	// Create a test form model
57	fm := models.NewFormModel()
58
59	// Render initial form
60	output1 := RenderForm(fm, "")
61
62	// Move focus
63	fm.FocusNext()
64
65	// Render form with different focus
66	output2 := RenderForm(fm, "")
67
68	// Both should render successfully
69	if len(output1) == 0 || len(output2) == 0 {
70		t.Error("Both renders should produce output")
71	}
72
73	// They should be different (different field is focused)
74	if output1 == output2 {
75		t.Log("Outputs are the same, but that's okay as the visual difference might not be captured")
76	}
77
78	t.Logf("Form 1: %d chars, Form 2: %d chars", len(output1), len(output2))
79}
80
81func TestFormModelCreation(t *testing.T) {
82	fm := models.NewFormModel()
83
84	// Verify initial state
85	fields := fm.GetFields()
86	if len(fields) != 7 {
87		t.Errorf("Expected 7 form fields, got %d", len(fields))
88	}
89
90	if fm.GetFocusIndex() != 0 {
91		t.Errorf("Expected initial focus index to be 0, got %d", fm.GetFocusIndex())
92	}
93
94	if fm.GetError() != nil {
95		t.Errorf("Expected no initial error, got %v", fm.GetError())
96	}
97
98	if fm.IsSubmitted() {
99		t.Error("Form should not be submitted initially")
100	}
101}
102
103func TestFormFieldInteraction(t *testing.T) {
104	fm := models.NewFormModel()
105
106	// Test focus navigation
107	initialIndex := fm.GetFocusIndex()
108	fm.FocusNext()
109	if fm.GetFocusIndex() != initialIndex+1 {
110		t.Error("FocusNext should increment focus index")
111	}
112
113	fm.FocusPrevious()
114	if fm.GetFocusIndex() != initialIndex {
115		t.Error("FocusPrevious should decrement focus index")
116	}
117
118	// Test data extraction
119	formData := fm.GetData()
120	if formData.Hostname != "" || formData.Username != "" {
121		t.Error("Initial form data should be empty")
122	}
123
124	// Set data
125	testData := models.FormData{
126		Hostname:       "test-host",
127		Username:       "testuser",
128		TargetDisk:     "/dev/sda",
129		EncryptionType: "LUKS",
130	}
131	fm.SetData(testData)
132
133	// Verify data was set
134	retrievedData := fm.GetData()
135	if retrievedData.Hostname != testData.Hostname {
136		t.Errorf("Expected hostname '%s', got '%s'", testData.Hostname, retrievedData.Hostname)
137	}
138}
139
140func BenchmarkRenderForm(b *testing.B) {
141	fm := models.NewFormModel()
142
143	b.ResetTimer()
144	for i := 0; i < b.N; i++ {
145		_ = RenderForm(fm, "")
146	}
147}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 0

    ↑↓ moveenter openesc close