test(render): add refresh frequency test

This commit is contained in:
Alexis Couvreur
2022-10-31 17:55:47 +00:00
parent cf9f2f8ae3
commit f842b491c6

View File

@@ -3,9 +3,12 @@ package pages
import (
"bytes"
"fmt"
"io"
"testing"
"testing/fstest"
"time"
"github.com/stretchr/testify/assert"
)
var instanceStates []RenderOptionsInstanceState = []RenderOptionsInstanceState{
@@ -214,3 +217,48 @@ func TestRender(t *testing.T) {
})
}
}
func TestRenderContent(t *testing.T) {
type args struct {
options RenderOptions
}
tests := []struct {
name string
args args
wantContent string
}{
{
name: "refresh frequency is 10 seconds",
args: args{
options: RenderOptions{
DisplayName: "Test",
InstanceStates: instanceStates,
Theme: "ghost",
SessionDuration: 10 * time.Minute,
RefreshFrequency: 10 * time.Second,
CustomThemes: nil,
Version: "v0.0.0",
},
},
wantContent: "<meta http-equiv=\"refresh\" content=\"10\" />",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
writer := &bytes.Buffer{}
if err := Render(tt.args.options, writer); err != nil {
t.Errorf("Render() error = %v", err)
return
}
content, err := io.ReadAll(writer)
if err != nil {
t.Errorf("ReadAll() error = %v", err)
return
}
assert.Contains(t, string(content), tt.wantContent)
})
}
}