mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
- `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>
37 lines
1.1 KiB
Go
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):")
|
|
}
|