From 11336931268173df592abfba612799c096a0916b Mon Sep 17 00:00:00 2001 From: Dima Krasner Date: Sat, 21 Dec 2024 20:44:02 +0200 Subject: [PATCH] show poll results even when voters count is 0 --- front/view.go | 2 +- test/poll_test.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/front/view.go b/front/view.go index c27fe76d..f61ec721 100644 --- a/front/view.go +++ b/front/view.go @@ -178,7 +178,7 @@ func (h *Handler) view(w text.Writer, r *Request, args ...string) { h.PrintNote(w, r, ¬e, &author, nil, note.Published.Time, false, false, true, false) } - if note.Type == ap.Question && note.VotersCount > 0 && offset == 0 { + if note.Type == ap.Question && offset == 0 { options := note.OneOf if len(options) == 0 { options = note.AnyOf diff --git a/test/poll_test.go b/test/poll_test.go index 1ed3a538..5d73ae40 100644 --- a/test/poll_test.go +++ b/test/poll_test.go @@ -145,8 +145,10 @@ func TestPoll_TwoOptionsOnlyZeroVotes(t *testing.T) { assert.Equal(1, n) view := server.Handle("/users/view/127.0.0.1/poll/1", server.Alice) - assert.NotContains(view, "## 📊 Results") - assert.NotContains(strings.Split(view, "\n"), "```Results graph") + assert.Contains(strings.Split(view, "\n"), "## 📊 Results (0 voters)") + assert.Contains(strings.Split(view, "\n"), "```Results graph") + assert.Contains(strings.Split(view, "\n"), "0 vanilla") + assert.Contains(strings.Split(view, "\n"), "0 chocolate") } func TestPoll_OneOption(t *testing.T) { @@ -777,8 +779,8 @@ func TestPoll_Local3OptionsAnd2VotesAndDeletedVote(t *testing.T) { assert.Contains(view, "Vote Nope") assert.Contains(view, "Vote Hell yeah!") assert.Contains(view, "Vote I couldn't care less") - assert.NotContains(strings.Split(view, "\n"), "1 ████████ Hell yeah!") - assert.NotContains(strings.Split(view, "\n"), "0 I couldn't care less") + assert.Contains(strings.Split(view, "\n"), "0 Hell yeah!") + assert.Contains(strings.Split(view, "\n"), "0 I couldn't care less") delete := server.Handle("/users/delete/"+reply[15:len(reply)-2], server.Carol) assert.Equal(fmt.Sprintf("30 /users/outbox/%s\r\n", strings.TrimPrefix(server.Carol.ID, "https://")), delete)