Skip to content

Commit

Permalink
Added test for the bug fix: 1966
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-in-go committed Dec 13, 2024
1 parent f024435 commit 30fc273
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions widget/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,28 @@ func TestForm_RefreshFromStructInit(t *testing.T) {
})

}

func TestEnsureRenderItemsCapacity(t *testing.T) {
form := &Form{
Items: []*FormItem{
{Text: "Label1", Widget: NewEntry()},
{Text: "Label2", Widget: NewCheck("Check", nil)},
},
itemGrid: &fyne.Container{
Objects: []fyne.CanvasObject{},
},
}

// Call ensureRenderItems
form.ensureRenderItems()

// Check that the capacity is sufficient
if cap(form.itemGrid.Objects) < len(form.Items)*2 {
t.Errorf("Expected capacity >= %d, got %d", len(form.Items)*2, cap(form.itemGrid.Objects))
}

// Check that objects are updated correctly
if len(form.itemGrid.Objects) != len(form.Items)*2 {
t.Errorf("Expected %d objects, got %d", len(form.Items)*2, len(form.itemGrid.Objects))
}
}

0 comments on commit 30fc273

Please sign in to comment.