Skip to content

Commit

Permalink
Merge pull request #411 from rusq/i406-followup
Browse files Browse the repository at this point in the history
Adding divider support and fixing test on windows
  • Loading branch information
rusq authored Jan 18, 2025
2 parents 303b24a + 6797dcf commit 1eb5fe5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 23 deletions.
15 changes: 0 additions & 15 deletions internal/viewer/renderer/fixtures/polly.html

This file was deleted.

Binary file added internal/viewer/renderer/fixtures/polly.html.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions internal/viewer/renderer/slack_fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,6 @@ const (
var (
//go:embed fixtures/polly.json
fxtrPolly string
//go:embed fixtures/polly.html
fxtrPollyHTML string
//go:embed fixtures/polly.html.gz
fxtrPollyHTML []byte
)
2 changes: 1 addition & 1 deletion internal/viewer/renderer/slack_rich_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *Slack) rtseText(ie slack.RichTextSectionElement) (string, string, error
if !ok {
return "", "", NewErrIncorrectType(&slack.RichTextSectionTextElement{}, ie)
}
var t = strings.Replace(e.Text, "\n", "<br>", -1)
t := strings.ReplaceAll(e.Text, "\n", "<br>")

return applyStyle(t, e.Style), "", nil
}
Expand Down
4 changes: 4 additions & 0 deletions internal/viewer/renderer/slack_sundry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ import "github.com/rusq/slack"
func (*Slack) mbtCall(slack.Block) (string, string, error) {
return div("slack-call", "(Call)"), "", nil
}

func (*Slack) mbtDivider(slack.Block) (string, string, error) {
return div("slack-divider", "<hr/>"), "", nil
}
26 changes: 21 additions & 5 deletions internal/viewer/renderer/slack_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package renderer

import (
"bytes"
"compress/gzip"
"context"
"html/template"
"reflect"
"io"
"strings"
"testing"

"github.com/rusq/slack"
"github.com/stretchr/testify/assert"

"github.com/rusq/slackdump/v3/internal/viewer/renderer/functions"
)
Expand Down Expand Up @@ -73,19 +76,32 @@ func TestSlack_Render(t *testing.T) {
args{
m: loadmsg(t, fxtrPolly),
},
template.HTML(fxtrPollyHTML),
template.HTML(strings.TrimSpace(ungzip(t, fxtrPollyHTML))),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
sm := &Slack{}
if gotV := sm.Render(context.Background(), tt.args.m); !reflect.DeepEqual(gotV, tt.wantV) {
t.Errorf("Slack.Render() = %v, want %v", gotV, tt.wantV)
}
gotV := sm.Render(context.Background(), tt.args.m)
assert.Equal(t, gotV, tt.wantV)
})
}
}

func ungzip(t *testing.T, b []byte) string {
t.Helper()
gr, err := gzip.NewReader(bytes.NewReader(b))
if err != nil {
t.Fatal(err)
}
defer gr.Close()
var buf strings.Builder
if _, err := io.Copy(&buf, gr); err != nil {
t.Fatal(err)
}
return buf.String()
}

func TestSlack_renderAttachment(t *testing.T) {
type fields struct {
tmpl *template.Template
Expand Down
1 change: 1 addition & 0 deletions internal/viewer/renderer/slack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (
slack.MBTContext: (*Slack).mbtContext,
slack.MBTSection: (*Slack).mbtSection,
slack.MBTAction: (*Slack).mbtAction,
slack.MBTDivider: (*Slack).mbtDivider,
"call": (*Slack).mbtCall,
}

Expand Down

0 comments on commit 1eb5fe5

Please sign in to comment.