test(notification): complete platform values and read watch output as NDJSON

A table test covers the completions of alias, config, auth and notification commands, including notification IDs from the inbox. The integration test reads tea notification watch --json as one object per line, and notification feedback, watch lines and completions name a subject the same way.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 23:50:46 +02:00
1 parent 6c124fc998
commit 9e74ec54ad
3 files changed
+45 -11

No files matched your search

+32
View File
@@ -5,6 +5,7 @@ package app
import (
"context"
"net/http"
"os"
"path/filepath"
"strings"
@@ -13,6 +14,7 @@ import (
"gitea.dev/tea/internal/clierr"
"gitea.dev/tea/internal/settings"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
)
@@ -263,3 +265,33 @@ func TestAliasDeleteAndList(t *testing.T) {
require.NoError(t, err)
require.Empty(t, snapshot.Preferences.Aliases)
}
func TestPlatformCommandsComplete(t *testing.T) {
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "/api/v1/notifications", r.URL.Path)
_, _ = w.Write([]byte(notificationThreads))
}))
defer server.Close()
deps, out, _ := testDeps(t)
configureAccounts(t, deps, server.URL, "alice", "alice", "bob")
require.NoError(t, Execute(context.Background(), deps, []string{"alias", "set", "il", "issue list"}))
for _, tc := range []struct {
args []string
want []string
}{
{[]string{"alias", "delete", ""}, []string{"il\tissue list"}},
{[]string{"config", "get", "hyp"}, []string{"hyperlinks"}},
{[]string{"config", "set", "hyperlinks", ""}, []string{"auto", "always", "never"}},
{[]string{"config", "set", "markdown", ""}, []string{"auto", "raw"}},
{[]string{"auth", "switch", ""}, []string{"alice\t" + server.URL + " (active)", "bob\t" + server.URL}},
{[]string{"auth", "logout", "b"}, []string{"bob\t" + server.URL}},
{[]string{"auth", "login", "--credential-store", ""}, []string{"keyring", "file"}},
{[]string{"auth", "login", "--scopes", "read:repository,write:re"}, []string{"read:repository,write:repository"}},
{[]string{"notification", "list", "--type", ""}, []string{"issue", "pull", "commit", "repository"}},
{[]string{"notification", "view", ""}, []string{"12\talice/project#17 Improve greeting", "3\talice/project#8 Improve error messages"}},
} {
candidates, directive := complete(t, deps, out, tc.args...)
require.Equal(t, tc.want, candidates, tc.args)
require.NotZero(t, directive&cobra.ShellCompDirectiveNoFileComp, tc.args)
}
}