test: add regression test for issue-only fields in FieldsToEditSurvey

Verifies Type and Parent only appear in the interactive picker when
Allowed is explicitly set. Prevents regression where issue-only
fields leak into gh pr edit's interactive mode.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Kynan Ware 2026-03-29 17:48:09 -06:00
parent 2a72a59f76
commit 4a196ddf1d

View file

@ -260,3 +260,38 @@ func TestTitleSurvey(t *testing.T) {
})
}
}
func TestFieldsToEditSurvey_IssueOnlyFields(t *testing.T) {
t.Run("without Allowed flags omits Type and Parent", func(t *testing.T) {
pm := prompter.NewMockPrompter(t)
pm.RegisterMultiSelect("What would you like to edit?", []string{},
// Type and Parent should NOT appear here
[]string{"Title", "Body", "Assignees", "Labels", "Projects", "Milestone"},
func(_ string, _, _ []string) ([]int, error) {
return []int{0}, nil
})
editable := &Editable{}
err := FieldsToEditSurvey(pm, editable)
require.NoError(t, err)
assert.True(t, editable.Title.Edited)
})
t.Run("with Allowed flags includes Type and Parent", func(t *testing.T) {
pm := prompter.NewMockPrompter(t)
pm.RegisterMultiSelect("What would you like to edit?", []string{},
// Type and Parent should appear between Labels and Projects
[]string{"Title", "Body", "Assignees", "Labels", "Type", "Parent", "Projects", "Milestone"},
func(_ string, _, _ []string) ([]int, error) {
return []int{4, 5}, nil // select Type and Parent
})
editable := &Editable{}
editable.IssueType.Allowed = true
editable.Parent.Allowed = true
err := FieldsToEditSurvey(pm, editable)
require.NoError(t, err)
assert.True(t, editable.IssueType.Edited)
assert.True(t, editable.Parent.Edited)
})
}