main 5041353

get_config_schema_test.go RawHistoryFolder

1package usecase_test
2
3import (
4	"context"
5	"testing"
6
7	"github.com/stretchr/testify/assert"
8	"github.com/stretchr/testify/mock"
9	"github.com/stretchr/testify/require"
10
11	"github.com/bnema/dumber/internal/application/port/mocks"
12	"github.com/bnema/dumber/internal/application/usecase"
13	"github.com/bnema/dumber/internal/domain/entity"
14)
15
16func TestGetConfigSchemaUseCase_Execute(t *testing.T) {
17	t.Run("returns schema keys from provider", func(t *testing.T) {
18		// Arrange
19		mockProvider := mocks.NewMockConfigSchemaProvider(t)
20		expectedKeys := []entity.ConfigKeyInfo{
21			{
22				Key:         "appearance.color_scheme",
23				Type:        "string",
24				Default:     "default",
25				Description: "Theme preference",
26				Values:      []string{"default", "prefer-dark", "prefer-light"},
27				Section:     "Appearance",
28			},
29			{
30				Key:         "logging.level",
31				Type:        "string",
32				Default:     "info",
33				Description: "Log verbosity level",
34				Values:      []string{"trace", "debug", "info", "warn", "error", "fatal"},
35				Section:     "Logging",
36			},
37		}
38		mockProvider.EXPECT().GetSchema().Return(expectedKeys)
39
40		uc := usecase.NewGetConfigSchemaUseCase(mockProvider)
41
42		// Act
43		result, err := uc.Execute(context.Background(), usecase.GetConfigSchemaInput{})
44
45		// Assert
46		require.NoError(t, err)
47		assert.NotNil(t, result)
48		assert.Len(t, result.Keys, 2)
49		assert.Equal(t, "appearance.color_scheme", result.Keys[0].Key)
50		assert.Equal(t, "logging.level", result.Keys[1].Key)
51		mock.AssertExpectationsForObjects(t, mockProvider)
52	})
53
54	t.Run("returns empty slice when no keys", func(t *testing.T) {
55		// Arrange
56		mockProvider := mocks.NewMockConfigSchemaProvider(t)
57		mockProvider.EXPECT().GetSchema().Return([]entity.ConfigKeyInfo{})
58
59		uc := usecase.NewGetConfigSchemaUseCase(mockProvider)
60
61		// Act
62		result, err := uc.Execute(context.Background(), usecase.GetConfigSchemaInput{})
63
64		// Assert
65		require.NoError(t, err)
66		assert.NotNil(t, result)
67		assert.Empty(t, result.Keys)
68		mock.AssertExpectationsForObjects(t, mockProvider)
69	})
70
71	t.Run("keys include all expected fields", func(t *testing.T) {
72		// Arrange
73		mockProvider := mocks.NewMockConfigSchemaProvider(t)
74		expectedKeys := []entity.ConfigKeyInfo{
75			{
76				Key:         "appearance.default_font_size",
77				Type:        "int",
78				Default:     "16",
79				Description: "Default font size in CSS pixels",
80				Range:       "1-72",
81				Section:     "Appearance",
82			},
83		}
84		mockProvider.EXPECT().GetSchema().Return(expectedKeys)
85
86		uc := usecase.NewGetConfigSchemaUseCase(mockProvider)
87
88		// Act
89		result, err := uc.Execute(context.Background(), usecase.GetConfigSchemaInput{})
90
91		// Assert
92		require.NoError(t, err)
93		assert.NotNil(t, result)
94		assert.Len(t, result.Keys, 1)
95
96		key := result.Keys[0]
97		assert.Equal(t, "appearance.default_font_size", key.Key)
98		assert.Equal(t, "int", key.Type)
99		assert.Equal(t, "16", key.Default)
100		assert.Equal(t, "Default font size in CSS pixels", key.Description)
101		assert.Equal(t, "1-72", key.Range)
102		assert.Equal(t, "Appearance", key.Section)
103		assert.Empty(t, key.Values) // No enum values for int type
104		mock.AssertExpectationsForObjects(t, mockProvider)
105	})
106}

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