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

38 lines
1.0 KiB
Go
Raw Normal View History

2021-02-11 15:43:19 +00:00
package admin
import (
"bytes"
2021-02-11 15:43:19 +00:00
"net/http"
"testing"
"github.com/ssb-ngi-pointer/go-ssb-room/web/router"
"github.com/ssb-ngi-pointer/go-ssb-room/web/webassert"
2021-02-11 15:43:19 +00:00
"github.com/stretchr/testify/assert"
refs "go.mindeco.de/ssb-refs"
2021-02-11 15:43:19 +00:00
)
func TestDashoard(t *testing.T) {
ts := newSession(t)
a := assert.New(t)
testRef := refs.FeedRef{Algo: "test", ID: bytes.Repeat([]byte{0}, 16)}
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
2021-04-01 07:04:38 +00:00
dashURL := ts.URLTo(router.AdminDashboard)
2021-02-11 15:43:19 +00:00
2021-04-01 07:04:38 +00:00
html, resp := ts.Client.GetHTML(dashURL)
2021-02-11 15:43:19 +00:00
a.Equal(http.StatusOK, resp.Code, "wrong HTTP status code")
2021-02-15 13:56:17 +00:00
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{
2021-02-11 15:43:19 +00:00
{"title", "AdminDashboardTitle"},
})
}