navigation_url_usecase_integration_test.go RawHistoryFolder

1package usecase
2
3import (
4	"context"
5	"path/filepath"
6	"testing"
7
8	"github.com/bnema/dumber/internal/domain/entity"
9)
10
11type fakeLocalPathResolver struct {
12	paths map[string]string
13	err   error
14}
15
16func (r fakeLocalPathResolver) ResolveExistingPath(_ context.Context, input string) (string, bool, error) {
17	if r.err != nil {
18		return "", false, r.err
19	}
20	abs, ok := r.paths[input]
21	return abs, ok, nil
22}
23
24func TestManageTabsCreateResolvesExistingLocalInitialURL(t *testing.T) {
25	ctx := context.Background()
26	tabs := entity.NewTabList()
27	tabsFile := filepath.Join(string(filepath.Separator), "tmp", "tabs.html")
28	uc := NewManageTabsUseCase(
29		sequentialIDGenerator("tab", "workspace", "pane"),
30		fakeLocalPathResolver{paths: map[string]string{"tabs.html": tabsFile}},
31	)
32
33	out, err := uc.Create(ctx, CreateTabInput{TabList: tabs, InitialURL: "tabs.html"})
34	if err != nil {
35		t.Fatalf("Create returned error: %v", err)
36	}
37	if got, want := out.Tab.Workspace.Root.Pane.URI, "file://"+tabsFile; got != want {
38		t.Fatalf("created pane URI = %q, want %q", got, want)
39	}
40}
41
42func TestManageTabsCreateWithPaneResolvesExistingLocalInitialURL(t *testing.T) {
43	ctx := context.Background()
44	tabs := entity.NewTabList()
45	tabsFile := filepath.Join(string(filepath.Separator), "tmp", "provided.html")
46	uc := NewManageTabsUseCase(
47		sequentialIDGenerator("tab", "workspace"),
48		fakeLocalPathResolver{paths: map[string]string{"provided.html": tabsFile}},
49	)
50	pane := entity.NewPane("provided-pane")
51
52	out, err := uc.CreateWithPane(ctx, CreateTabWithPaneInput{TabList: tabs, Pane: pane, InitialURL: "provided.html"})
53	if err != nil {
54		t.Fatalf("CreateWithPane returned error: %v", err)
55	}
56	if got, want := out.Tab.Workspace.Root.Pane.URI, "file://"+tabsFile; got != want {
57		t.Fatalf("provided pane URI = %q, want %q", got, want)
58	}
59}
60
61func TestManagePanesSplitResolvesExistingLocalInitialURL(t *testing.T) {
62	ctx := context.Background()
63	paneFile := filepath.Join(string(filepath.Separator), "tmp", "split.html")
64	uc := NewManagePanesUseCase(
65		sequentialIDGenerator("new-pane", "parent"),
66		fakeLocalPathResolver{paths: map[string]string{"split.html": paneFile}},
67	)
68	active := entity.NewPane("active-pane")
69	activeNode := &entity.PaneNode{ID: "active-node", Pane: active}
70	workspace := &entity.Workspace{ID: "workspace", Root: activeNode, ActivePaneID: active.ID}
71
72	out, err := uc.Split(ctx, SplitPaneInput{
73		Workspace:  workspace,
74		TargetPane: activeNode,
75		Direction:  SplitRight,
76		InitialURL: "split.html",
77	})
78	if err != nil {
79		t.Fatalf("Split returned error: %v", err)
80	}
81	if got, want := out.NewPaneNode.Pane.URI, "file://"+paneFile; got != want {
82		t.Fatalf("split pane URI = %q, want %q", got, want)
83	}
84}
85
86func TestManagePanesCreateStackResolvesExistingLocalInitialURL(t *testing.T) {
87	ctx := context.Background()
88	stackFile := filepath.Join(string(filepath.Separator), "tmp", "stack.html")
89	uc := NewManagePanesUseCase(
90		sequentialIDGenerator("new-pane"),
91		fakeLocalPathResolver{paths: map[string]string{"stack.html": stackFile}},
92	)
93	active := entity.NewPane("active-pane")
94	activeNode := &entity.PaneNode{ID: "active-node", Pane: active}
95	workspace := &entity.Workspace{ID: "workspace", Root: activeNode, ActivePaneID: active.ID}
96
97	out, err := uc.CreateStack(ctx, workspace, activeNode, "stack.html")
98	if err != nil {
99		t.Fatalf("CreateStack returned error: %v", err)
100	}
101	if got, want := out.NewPaneNode.Pane.URI, "file://"+stackFile; got != want {
102		t.Fatalf("stack pane URI = %q, want %q", got, want)
103	}
104}
105
106func TestManagePanesAddToStackResolvesExistingLocalInitialURL(t *testing.T) {
107	ctx := context.Background()
108	stackFile := filepath.Join(string(filepath.Separator), "tmp", "added.html")
109	uc := NewManagePanesUseCase(
110		sequentialIDGenerator("added-pane"),
111		fakeLocalPathResolver{paths: map[string]string{"added.html": stackFile}},
112	)
113	active := entity.NewPane("active-pane")
114	activeNode := &entity.PaneNode{ID: "active-node", Pane: active}
115	stackNode := &entity.PaneNode{
116		ID:               "stack",
117		IsStacked:        true,
118		ActiveStackIndex: 0,
119		Children:         []*entity.PaneNode{activeNode},
120	}
121	activeNode.Parent = stackNode
122	workspace := &entity.Workspace{ID: "workspace", Root: stackNode, ActivePaneID: active.ID}
123
124	out, err := uc.AddToStack(ctx, workspace, stackNode, nil, "added.html")
125	if err != nil {
126		t.Fatalf("AddToStack returned error: %v", err)
127	}
128	if got, want := out.NewPaneNode.Pane.URI, "file://"+stackFile; got != want {
129		t.Fatalf("added stack pane URI = %q, want %q", got, want)
130	}
131}
132
133func sequentialIDGenerator(ids ...string) IDGenerator {
134	idx := 0
135	return func() string {
136		if idx >= len(ids) {
137			return "extra-id"
138		}
139		id := ids[idx]
140		idx++
141		return id
142	}
143}

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 8

Tags 42

↑↓ moveenter openesc close