Skip to content

Commit 5bd8d68

Browse files
committed
test(catalog): address code review feedback from ako
- Add default/unknown test case for getMicroflowObjectType - Replace non-printable bytes in formatGUID short-data test with legible ASCII - Add Pages$DivContainer test case to TestExtractWidgetsRecursive
1 parent 9019199 commit 5bd8d68

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

mdl/catalog/builder_microflows_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ import (
66
"testing"
77

88
"github.com/mendixlabs/mxcli/sdk/microflows"
9+
"github.com/mendixlabs/mxcli/model"
910
)
1011

12+
// unknownMicroflowObject satisfies MicroflowObject but is not in the type switch.
13+
type unknownMicroflowObject struct{}
14+
15+
func (u *unknownMicroflowObject) GetID() model.ID { return "" }
16+
func (u *unknownMicroflowObject) GetPosition() model.Point { return model.Point{} }
17+
func (u *unknownMicroflowObject) SetPosition(model.Point) {}
18+
1119
func TestGetMicroflowObjectType(t *testing.T) {
1220
tests := []struct {
1321
name string
@@ -25,6 +33,7 @@ func TestGetMicroflowObjectType(t *testing.T) {
2533
{"BreakEvent", &microflows.BreakEvent{}, "BreakEvent"},
2634
{"ContinueEvent", &microflows.ContinueEvent{}, "ContinueEvent"},
2735
{"ErrorEvent", &microflows.ErrorEvent{}, "ErrorEvent"},
36+
{"unknown object falls to default", &unknownMicroflowObject{}, "MicroflowObject"},
2837
}
2938

3039
for _, tt := range tests {

mdl/catalog/builder_pages_test.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,29 @@ func TestExtractWidgetsRecursive(t *testing.T) {
146146
}
147147
})
148148

149+
t.Run("skips Pages$DivContainer but includes children", func(t *testing.T) {
150+
w := map[string]any{
151+
"$ID": "div2",
152+
"Name": "pagesDivContainer",
153+
"$Type": "Pages$DivContainer",
154+
"Widgets": []any{
155+
int32(0),
156+
map[string]any{
157+
"$ID": "child2",
158+
"Name": "childWidget2",
159+
"$Type": "Pages$Button",
160+
},
161+
},
162+
}
163+
got := extractWidgetsRecursive(w)
164+
if len(got) != 1 {
165+
t.Fatalf("expected 1 widget (child only), got %d", len(got))
166+
}
167+
if got[0].ID != "child2" {
168+
t.Errorf("expected child2, got %q", got[0].ID)
169+
}
170+
})
171+
149172
t.Run("CustomWidget resolves WidgetId", func(t *testing.T) {
150173
w := map[string]any{
151174
"$ID": "cw1",
@@ -412,9 +435,9 @@ func TestFormatGUID(t *testing.T) {
412435
want: "00000000-0000-0000-0000-000000000000",
413436
},
414437
{
415-
name: "short data — returns as string",
416-
data: []byte{0x01, 0x02},
417-
want: "\x01\x02",
438+
name: "short data — returns raw string passthrough",
439+
data: []byte{0x41, 0x42},
440+
want: "AB",
418441
},
419442
}
420443

0 commit comments

Comments
 (0)