use more robust identifier for test
This commit is contained in:
parent
a5f7701437
commit
c6077337d1
|
@ -68,7 +68,6 @@ func (c Config) SetPrivacyMode(ctx context.Context, pm roomdb.PrivacyMode) error
|
||||||
return nil // alles gut!!
|
return nil // alles gut!!
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use proper language tag from "golang.org/x/text/language"?
|
|
||||||
func (c Config) GetDefaultLanguage(ctx context.Context) (string, error) {
|
func (c Config) GetDefaultLanguage(ctx context.Context) (string, error) {
|
||||||
config, err := models.FindConfig(ctx, c.db, configRowID)
|
config, err := models.FindConfig(ctx, c.db, configRowID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -21,8 +21,8 @@ import (
|
||||||
"github.com/ssb-ngi-pointer/go-ssb-room/roomstate"
|
"github.com/ssb-ngi-pointer/go-ssb-room/roomstate"
|
||||||
"github.com/ssb-ngi-pointer/go-ssb-room/web"
|
"github.com/ssb-ngi-pointer/go-ssb-room/web"
|
||||||
weberrors "github.com/ssb-ngi-pointer/go-ssb-room/web/errors"
|
weberrors "github.com/ssb-ngi-pointer/go-ssb-room/web/errors"
|
||||||
"github.com/ssb-ngi-pointer/go-ssb-room/web/router"
|
|
||||||
"github.com/ssb-ngi-pointer/go-ssb-room/web/i18n"
|
"github.com/ssb-ngi-pointer/go-ssb-room/web/i18n"
|
||||||
|
"github.com/ssb-ngi-pointer/go-ssb-room/web/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTMLTemplates define the list of files the template system should load.
|
// HTMLTemplates define the list of files the template system should load.
|
||||||
|
@ -86,8 +86,8 @@ func Handler(
|
||||||
var sh = settingsHandler{
|
var sh = settingsHandler{
|
||||||
r: r,
|
r: r,
|
||||||
urlTo: urlTo,
|
urlTo: urlTo,
|
||||||
db: dbs.Config,
|
db: dbs.Config,
|
||||||
loc: locHelper,
|
loc: locHelper,
|
||||||
}
|
}
|
||||||
mux.HandleFunc("/settings", r.HTML("admin/settings.tmpl", sh.overview))
|
mux.HandleFunc("/settings", r.HTML("admin/settings.tmpl", sh.overview))
|
||||||
mux.HandleFunc("/settings/set-privacy", sh.setPrivacy)
|
mux.HandleFunc("/settings/set-privacy", sh.setPrivacy)
|
||||||
|
|
|
@ -2,17 +2,16 @@ package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ssb-ngi-pointer/go-ssb-room/web/router"
|
"github.com/ssb-ngi-pointer/go-ssb-room/web/router"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
/* can't test English atm due to web/i18n/i18ntesting/testing.go:justTheKeys, which generates translations that are just
|
/* can't test English atm due to web/i18n/i18ntesting/testing.go:justTheKeys, which generates translations that are just
|
||||||
* translationLabel = "translationLabel"
|
* translationLabel = "translationLabel"
|
||||||
*/
|
*/
|
||||||
// func TestLanguageSetDefaultLanguageEnglish(t *testing.T) {
|
// func TestLanguageSetDefaultLanguageEnglish(t *testing.T) {
|
||||||
// ts := newSession(t)
|
// ts := newSession(t)
|
||||||
// a := assert.New(t)
|
// a := assert.New(t)
|
||||||
|
@ -40,6 +39,6 @@ func TestLanguageSetDefaultLanguage(t *testing.T) {
|
||||||
a.Equal(http.StatusOK, resp.Code, "Wrong HTTP status code")
|
a.Equal(http.StatusOK, resp.Code, "Wrong HTTP status code")
|
||||||
|
|
||||||
summaryElement := html.Find("#language-summary")
|
summaryElement := html.Find("#language-summary")
|
||||||
summaryText := strings.TrimSpace(summaryElement.Text())
|
summaryText := strings.TrimSpace(summaryElement.Text())
|
||||||
a.Equal("Deutsch", summaryText, "summary language should display german translation of language name")
|
a.Equal("Deutsch", summaryText, "summary language should display german translation of language name")
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type settingsHandler struct {
|
type settingsHandler struct {
|
||||||
r *render.Renderer
|
r *render.Renderer
|
||||||
urlTo web.URLMaker
|
urlTo web.URLMaker
|
||||||
db roomdb.RoomConfig
|
db roomdb.RoomConfig
|
||||||
loc *i18n.Helper
|
loc *i18n.Helper
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h settingsHandler) overview(w http.ResponseWriter, req *http.Request) (interface{}, error) {
|
func (h settingsHandler) overview(w http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-kit/kit/log/level"
|
"github.com/go-kit/kit/log/level"
|
||||||
|
@ -283,7 +283,7 @@ func New(
|
||||||
|
|
||||||
session, err := cookieStore.Get(req, i18n.LanguageCookieName)
|
session, err := cookieStore.Get(req, i18n.LanguageCookieName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
eh.Handle(w, req, http.StatusInternalServerError,err)
|
eh.Handle(w, req, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ func TestInviteConsumeInviteHTTP(t *testing.T) {
|
||||||
doc, resp := ts.Client.GetHTML(validAcceptURL)
|
doc, resp := ts.Client.GetHTML(validAcceptURL)
|
||||||
a.Equal(http.StatusOK, resp.Code)
|
a.Equal(http.StatusOK, resp.Code)
|
||||||
|
|
||||||
form := doc.Find("form#consume")
|
form := doc.Find("form#inviteConsume")
|
||||||
r.Equal(1, form.Length())
|
r.Equal(1, form.Length())
|
||||||
|
|
||||||
consumeInviteURLString, has := form.Attr("action")
|
consumeInviteURLString, has := form.Attr("action")
|
||||||
|
@ -131,7 +131,7 @@ func TestInviteConsumeInviteHTTP(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// get the corresponding token from the page
|
// get the corresponding token from the page
|
||||||
csrfTokenElem := doc.Find(`form[action="/invite/consume"] input[name="gorilla.csrf.Token"]`)
|
csrfTokenElem := form.Find(`input[name="gorilla.csrf.Token"]`)
|
||||||
a.Equal(1, csrfTokenElem.Length())
|
a.Equal(1, csrfTokenElem.Length())
|
||||||
csrfName, has := csrfTokenElem.Attr("name")
|
csrfName, has := csrfTokenElem.Attr("name")
|
||||||
a.True(has, "should have a name attribute")
|
a.True(has, "should have a name attribute")
|
||||||
|
|
|
@ -92,7 +92,7 @@ func TestNoticesEditButtonVisible(t *testing.T) {
|
||||||
csrfCookie := resp.Result().Cookies()
|
csrfCookie := resp.Result().Cookies()
|
||||||
a.True(len(csrfCookie) > 0, "should have one cookie for CSRF protection validation")
|
a.True(len(csrfCookie) > 0, "should have one cookie for CSRF protection validation")
|
||||||
|
|
||||||
csrfTokenElem := doc.Find(`form[action="/fallback/finalize"] input[type="hidden"]`)
|
csrfTokenElem := doc.Find(`form#password-fallback input[type="hidden"]`)
|
||||||
a.Equal(1, csrfTokenElem.Length())
|
a.Equal(1, csrfTokenElem.Length())
|
||||||
|
|
||||||
csrfName, has := csrfTokenElem.Attr("name")
|
csrfName, has := csrfTokenElem.Attr("name")
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -17,13 +16,11 @@ func TestLanguageDefaultNoCookie(t *testing.T) {
|
||||||
ts := setup(t)
|
ts := setup(t)
|
||||||
a := assert.New(t)
|
a := assert.New(t)
|
||||||
route := ts.URLTo(router.CompleteIndex)
|
route := ts.URLTo(router.CompleteIndex)
|
||||||
postEndpoint := ts.URLTo(router.CompleteSetLanguage)
|
|
||||||
formAction := postEndpoint.Path
|
|
||||||
|
|
||||||
html, res := ts.Client.GetHTML(route)
|
html, res := ts.Client.GetHTML(route)
|
||||||
a.Equal(http.StatusOK, res.Code, "wrong HTTP status code")
|
a.Equal(http.StatusOK, res.Code, "wrong HTTP status code")
|
||||||
|
|
||||||
languageForms := html.Find(fmt.Sprintf(`form[action="%s"]`, formAction))
|
languageForms := html.Find("#visitor-set-language form")
|
||||||
// two languages: english, deutsch => two <form> elements
|
// two languages: english, deutsch => two <form> elements
|
||||||
a.Equal(2, languageForms.Length())
|
a.Equal(2, languageForms.Length())
|
||||||
|
|
||||||
|
@ -40,13 +37,12 @@ func TestLanguageChooseGerman(t *testing.T) {
|
||||||
a := assert.New(t)
|
a := assert.New(t)
|
||||||
route := ts.URLTo(router.CompleteIndex)
|
route := ts.URLTo(router.CompleteIndex)
|
||||||
postEndpoint := ts.URLTo(router.CompleteSetLanguage)
|
postEndpoint := ts.URLTo(router.CompleteSetLanguage)
|
||||||
formAction := postEndpoint.Path
|
|
||||||
|
|
||||||
html, res := ts.Client.GetHTML(route)
|
html, res := ts.Client.GetHTML(route)
|
||||||
a.Equal(http.StatusOK, res.Code, "wrong HTTP status code")
|
a.Equal(http.StatusOK, res.Code, "wrong HTTP status code")
|
||||||
|
|
||||||
csrfTokenElem := html.Find(fmt.Sprintf(`form[action="%s"] input[type="hidden"]`, formAction))
|
csrfTokenElem := html.Find(`#visitor-set-language input[name="gorilla.csrf.Token"]`)
|
||||||
a.Equal(6, csrfTokenElem.Length())
|
a.Equal(2, csrfTokenElem.Length())
|
||||||
|
|
||||||
csrfName, has := csrfTokenElem.First().Attr("name")
|
csrfName, has := csrfTokenElem.First().Attr("name")
|
||||||
a.True(has, "should have a name attribute")
|
a.True(has, "should have a name attribute")
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
class="mb-2 mx-auto px-3 py-1 text-gray-500 w-32 rounded shadow bg-gray-50 ring-1 ring-gray-300 hover:bg-gray-100 cursor-pointer">
|
class="mb-2 mx-auto px-3 py-1 text-gray-500 w-32 rounded shadow bg-gray-50 ring-1 ring-gray-300 hover:bg-gray-100 cursor-pointer">
|
||||||
Language
|
Language
|
||||||
</summary>
|
</summary>
|
||||||
<div class="grid grid-cols-2 justify-items-center gap-x-1">
|
<div id="visitor-set-language" class="grid grid-cols-2 justify-items-center gap-x-1">
|
||||||
{{ list_languages $setLanguageUrl "text-gray-500 hover:underline cursor-pointer" }}
|
{{ list_languages $setLanguageUrl "text-gray-500 hover:underline cursor-pointer" }}
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<span id="welcome" class="text-center mt-8">{{i18n "InviteInsertWelcome"}}</span>
|
<span id="welcome" class="text-center mt-8">{{i18n "InviteInsertWelcome"}}</span>
|
||||||
|
|
||||||
<form
|
<form
|
||||||
id="consume"
|
id="inviteConsume"
|
||||||
action="{{urlTo "complete:invite:consume"}}"
|
action="{{urlTo "complete:invite:consume"}}"
|
||||||
method="POST"
|
method="POST"
|
||||||
class="flex flex-col items-center self-stretch"
|
class="flex flex-col items-center self-stretch"
|
||||||
|
@ -24,4 +24,4 @@
|
||||||
>{{i18n "GenericSubmit"}}</button>
|
>{{i18n "GenericSubmit"}}</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in New Issue