mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
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:
3 files changed
+45
-11
No files matched your search
@@ -356,11 +356,15 @@ func notificationStatus(item services.Notification) string {
|
||||
|
||||
// notificationLabel names a notification in feedback: "notification 28 (alice/project#17)".
|
||||
func notificationLabel(item services.Notification) string {
|
||||
subject := item.Repository
|
||||
if item.Number != 0 {
|
||||
subject += "#" + strconv.FormatInt(item.Number, 10)
|
||||
return fmt.Sprintf("notification %d (%s)", item.ID, subjectRef(item))
|
||||
}
|
||||
|
||||
// subjectRef names the subject of a notification by its repository and number: "alice/project#17".
|
||||
func subjectRef(item services.Notification) string {
|
||||
if item.Number == 0 {
|
||||
return item.Repository
|
||||
}
|
||||
return fmt.Sprintf("notification %d (%s)", item.ID, strings.TrimSpace(subject))
|
||||
return item.Repository + "#" + strconv.FormatInt(item.Number, 10)
|
||||
}
|
||||
|
||||
// notificationKinds names the subject types in a view footer.
|
||||
@@ -399,10 +403,7 @@ func watchLine(item services.Notification, d terminal.Display) string {
|
||||
if when.IsZero() {
|
||||
when = d.Now
|
||||
}
|
||||
subject := item.Repository
|
||||
if item.Number != 0 {
|
||||
subject += "#" + strconv.FormatInt(item.Number, 10)
|
||||
}
|
||||
subject := subjectRef(item)
|
||||
details := strings.ToLower(item.Type)
|
||||
if item.State != "" {
|
||||
details += " · " + terminal.Colorize(stateColors[item.State], item.State, d.Color)
|
||||
@@ -415,7 +416,7 @@ func (a *application) completeNotifications() cobra.CompletionFunc {
|
||||
return a.apiCompletion(false, func(ctx context.Context, t target, _ string) ([]cobra.Completion, error) {
|
||||
page, err := services.Notifications{Client: t.client, Repository: t.Repo}.List(ctx, services.NotificationOptions{Limit: completionLimit, Page: 1, Statuses: []string{"unread", "pinned", "read"}})
|
||||
return describe(page.Items, func(item services.Notification) (string, string) {
|
||||
return strconv.FormatInt(item.ID, 10), strings.TrimPrefix(notificationLabel(item)+" "+item.Title, "notification "+strconv.FormatInt(item.ID, 10)+" ")
|
||||
return strconv.FormatInt(item.ID, 10), subjectRef(item) + " " + item.Title
|
||||
}), err
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user