go-ssb-room/web/handlers/admin/handler_test.go

38 lines
1.0 KiB
Go

package admin
import (
"bytes"
"net/http"
"testing"
"github.com/ssb-ngi-pointer/go-ssb-room/v2/web/router"
"github.com/ssb-ngi-pointer/go-ssb-room/v2/web/webassert"
"github.com/stretchr/testify/assert"
refs "go.mindeco.de/ssb-refs"
)
func TestDashoard(t *testing.T) {
ts := newSession(t)
a := assert.New(t)
testRef := refs.FeedRef{Algo: "ed25519", ID: bytes.Repeat([]byte{0}, 32)}
ts.RoomState.AddEndpoint(testRef, nil) // 1 online
ts.MembersDB.CountReturns(4, nil) // 4 members
ts.InvitesDB.CountReturns(3, nil) // 3 invites
ts.DeniedKeysDB.CountReturns(2, nil) // 2 banned
dashURL := ts.URLTo(router.AdminDashboard)
html, resp := ts.Client.GetHTML(dashURL)
a.Equal(http.StatusOK, resp.Code, "wrong HTTP status code")
a.Equal("1", html.Find("#online-count").Text())
a.Equal("4", html.Find("#member-count").Text())
a.Equal("3", html.Find("#invite-count").Text())
a.Equal("2", html.Find("#denied-count").Text())
webassert.Localized(t, html, []webassert.LocalizedElement{
{"title", "AdminDashboardTitle"},
})
}