v0.31.0 bf0756b

app_download_test.go RawHistoryFolder

1package ui
2
3import (
4	"testing"
5
6	"github.com/stretchr/testify/require"
7
8	"github.com/bnema/dumber/internal/application/port"
9	"github.com/bnema/dumber/internal/ui/component"
10)
11
12func TestDownloadEventAdapterToastSpecLifecycle(t *testing.T) {
13	adapter := newDownloadEventAdapter(nil)
14	event := port.DownloadEvent{
15		Filename:    "archlinux.iso",
16		Destination: "/tmp/archlinux.iso",
17	}
18
19	started := adapter.toastSpecForEvent(port.DownloadEvent{
20		Type:        port.DownloadEventStarted,
21		Filename:    event.Filename,
22		Destination: event.Destination,
23	})
24	require.True(t, started.show)
25	require.Equal(t, component.ToastInfo, started.level)
26	require.Equal(t, 0, started.duration)
27	require.Equal(t, "Download started: archlinux.iso (0%)", started.message)
28
29	progress := adapter.toastSpecForEvent(port.DownloadEvent{
30		Type:        port.DownloadEventProgress,
31		Filename:    event.Filename,
32		Destination: event.Destination,
33		Progress:    0.37,
34	})
35	require.True(t, progress.show)
36	require.Equal(t, component.ToastInfo, progress.level)
37	require.Equal(t, 0, progress.duration)
38	require.Equal(t, "Downloading: archlinux.iso (37%)", progress.message)
39
40	finished := adapter.toastSpecForEvent(port.DownloadEvent{
41		Type:        port.DownloadEventFinished,
42		Filename:    event.Filename,
43		Destination: event.Destination,
44	})
45	require.True(t, finished.show)
46	require.Equal(t, component.ToastSuccess, finished.level)
47	require.Equal(t, downloadToastTerminalDuration, finished.duration)
48	require.Equal(t, "Download complete: archlinux.iso", finished.message)
49}
50
51func TestDownloadEventAdapterToastSpecSuppressesDuplicateProgress(t *testing.T) {
52	adapter := newDownloadEventAdapter(nil)
53	event := port.DownloadEvent{
54		Filename:    "ubuntu.iso",
55		Destination: "/tmp/ubuntu.iso",
56	}
57
58	adapter.toastSpecForEvent(port.DownloadEvent{
59		Type:        port.DownloadEventStarted,
60		Filename:    event.Filename,
61		Destination: event.Destination,
62	})
63
64	first := adapter.toastSpecForEvent(port.DownloadEvent{
65		Type:        port.DownloadEventProgress,
66		Filename:    event.Filename,
67		Destination: event.Destination,
68		Progress:    0.12,
69	})
70	require.True(t, first.show)
71
72	duplicate := adapter.toastSpecForEvent(port.DownloadEvent{
73		Type:        port.DownloadEventProgress,
74		Filename:    event.Filename,
75		Destination: event.Destination,
76		Progress:    0.12,
77	})
78	require.False(t, duplicate.show)
79}
80
81func TestDownloadProgressPercentRoundsReasonably(t *testing.T) {
82	require.Equal(t, 0, downloadProgressPercent(0))
83	require.Equal(t, 1, downloadProgressPercent(0.0051))
84	require.Equal(t, 37, downloadProgressPercent(0.37))
85	require.Equal(t, 100, downloadProgressPercent(1.2))
86}

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