Files
gitea-tea/internal/terminal/issue_form_test.go
T
bircni faea86cd94 refactor: add terminal output and forms package (#1124)
- `internal/terminal`: streams and the prompting policy, interactive forms (issue, PR, review, merge, milestone), editor / pager / browser launching, JSON and `--jq` output.
- An aligned table renderer and a record renderer for human output; both strip control and escape characters from server-supplied text so titles and bodies cannot inject terminal sequences.

Reviewed-on: https://gitea.com/gitea/tea/pulls/1124
Reviewed-by: TheFox0x7 <95654+thefox0x7@noreply.gitea.com>
2026-10-11 17:12:23 +00:00

37 lines
1.1 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package terminal
import (
"bytes"
"context"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestCollectIssuePropertiesUsesEditBodyDraft(t *testing.T) {
var initial string
p, _ := testPrompter(bytes.NewBufferString("Drafted Title\r"))
values, err := p.collectIssueProperties(context.Background(), "", "template body", IssueFormChoices{
EditBody: func(_ context.Context, body string) (Draft, error) {
initial = body
return Draft{Path: filepath.Join(t.TempDir(), "draft.md"), Body: "edited body"}, nil
},
})
require.NoError(t, err)
require.Equal(t, "template body", initial)
require.Equal(t, "Drafted Title", values.Title)
require.Equal(t, "edited body", values.Body)
require.NotEmpty(t, values.Draft.Path)
}
func TestIssueFormMarksTitleRequired(t *testing.T) {
p, rendered := accessiblePrompter(t, "Title\n")
_, err := p.collectIssueProperties(context.Background(), "", "", IssueFormChoices{EditBody: noEdit})
require.NoError(t, err)
require.Contains(t, rendered.String(), "Issue title (required):")
}