dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit ef56ad1f119e2bf5479be986b650cfe9dc1cc2ed
parent 780da8e7b476a5a727c5b79b12f0edb689e86728
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 19 Jan 2023 00:08:47 -0800

adding tests for quote code

Diffstat:
Mpkg/web/handlers/api/v1/topBarHandler_test.go | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/pkg/web/handlers/api/v1/topBarHandler_test.go b/pkg/web/handlers/api/v1/topBarHandler_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/assert" "strings" "testing" + "time" ) func TestColorifyTaggedUsers(t *testing.T) { @@ -96,3 +97,24 @@ EsRtZTXRbbiR809TVRcFOn5iro5Ez6Q6K1d7fRwtfwEAz7cX1RUfG0r5cwM03/RG converted = convertInlinePGPPublicKey(inlinePKey) assert.Equal(t, originPKey, converted) } + +func TestGetQuoteTxt(t *testing.T) { + // Quotes do not include original message quote if any + txt := getQuoteTxt("", database.ChatMessage{RawMessage: `“[00:00:01] user1 - this is a test” another one`, User: database.User{Username: "user1"}, CreatedAt: time.Date(0, 0, 0, 0, 0, 2, 0, time.UTC)}) + expected := "“[00:00:02] user1 - another one”" + assert.Equal(t, expected, txt) + + // Quoted should inline a multiline message + txt = getQuoteTxt("", database.ChatMessage{RawMessage: "line1\nline2\nline3", User: database.User{Username: "user1"}, CreatedAt: time.Date(0, 0, 0, 0, 0, 2, 0, time.UTC)}) + expected = "“[00:00:02] user1 - line1 line2 line3”" + assert.Equal(t, expected, txt) + + // Quoted should replace "special double quotes" to normal "double quote" + txt = getQuoteTxt("", database.ChatMessage{RawMessage: `instead of showing +“[00:00:01] user2 - an article about HHVM... +https://www.zapbuild.com/bitsntricks/hiphop-…” that looks perfect for my chat +i think it would be better if it shows +“[00:00:01] user2 - an article about HHVM...” that looks perfect for my chat`, User: database.User{Username: "user1"}, CreatedAt: time.Date(0, 0, 0, 0, 0, 2, 0, time.UTC)}) + expected = "“[00:00:02] user1 - instead of showing \"[00:00:01] user2 - an article about HHVM...…”" + assert.Equal(t, expected, txt) +}