Skip to content

Commit

Permalink
rename webassert.InputsInForm->ElementsInForm
Browse files Browse the repository at this point in the history
  • Loading branch information
cblgh committed Mar 12, 2021
1 parent 5ac0780 commit 7d6d992
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions web/handlers/admin/allow_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestAllowListAdd(t *testing.T) {

a.Equal(addURL.String(), action)

webassert.InputsInForm(t, formSelection, []webassert.InputElement{
webassert.ElementsInForm(t, formSelection, []webassert.FormElement{
{Tag: "input", Name: "pub_key", Type: "text"},
})

Expand Down Expand Up @@ -181,7 +181,7 @@ func TestAllowListRemoveConfirmation(t *testing.T) {

a.Equal(addURL.String(), action)

webassert.InputsInForm(t, form, []webassert.InputElement{
webassert.ElementsInForm(t, form, []webassert.FormElement{
{Tag: "input", Name: "id", Type: "hidden", Value: "666"},
})
}
Expand Down
2 changes: 1 addition & 1 deletion web/handlers/admin/invites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestInvitesCreateForm(t *testing.T) {

a.Equal(addURL.String(), action)

webassert.InputsInForm(t, formSelection, []webassert.InputElement{
webassert.ElementsInForm(t, formSelection, []webassert.FormElement{
{Name: "alias_suggestion", Type: "text"},
})
}
Expand Down
10 changes: 7 additions & 3 deletions web/handlers/admin/notices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import (
"github.com/stretchr/testify/assert"
)
/* TODO:
* add a new test that makes sure that /translation/add only accepts POST
* add a new
* add a check inside the handler proper
*/

// Verifies that /translation/add only accepts POST requests
func TestNoticeAddLanguageOnlyAllowsPost(t *testing.T) {
}

func TestNoticeDraftLanguageIncludesAllFields(t *testing.T) {
ts := newSession(t)
a := assert.New(t)
Expand All @@ -36,7 +40,7 @@ func TestNoticeDraftLanguageIncludesAllFields(t *testing.T) {
html, resp := ts.Client.GetHTML(u.String())
form := html.Find("form")
a.Equal(http.StatusOK, resp.Code, "Wrong HTTP status code")
webassert.InputsInForm(t, form, []webassert.InputElement{
webassert.ElementsInForm(t, form, []webassert.FormElement{
{ Tag: "input", Name: "title" },
{ Tag: "input", Name: "language" },
{ Tag: "textarea", Name: "content" },
Expand Down Expand Up @@ -64,7 +68,7 @@ func TestNoticeEditFormIncludesAllFields(t *testing.T) {

a.Equal(http.StatusOK, resp.Code, "Wrong HTTP status code")
// check for all the form elements & verify their initial contents are set correctly
webassert.InputsInForm(t, form, []webassert.InputElement{
webassert.ElementsInForm(t, form, []webassert.FormElement{
{ Tag: "input", Name: "title", Value: notice.Title },
{ Tag: "input", Name: "language", Value: notice.Language },
{ Tag: "input", Name: "id", Value: fmt.Sprintf("%d", notice.ID), Type: "hidden" },
Expand Down
4 changes: 2 additions & 2 deletions web/handlers/invites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestInviteShowAcceptForm(t *testing.T) {

webassert.CSRFTokenPresent(t, form)

webassert.InputsInForm(t, form, []webassert.InputElement{
webassert.ElementsInForm(t, form, []webassert.FormElement{
{Name: "token", Type: "hidden", Value: testToken},
{Name: "alias", Type: "text", Value: fakeExistingInvite.AliasSuggestion},
{Name: "new_member", Type: "text", Placeholder: wantNewMemberPlaceholder},
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestInviteShowAcceptForm(t *testing.T) {
r.Equal(1, form.Length())

webassert.CSRFTokenPresent(t, form)
webassert.InputsInForm(t, form, []webassert.InputElement{
webassert.ElementsInForm(t, form, []webassert.FormElement{
{Name: "token", Type: "hidden", Value: testToken},
{Name: "alias", Type: "text", Placeholder: "you@this.room"},
{Name: "new_member", Type: "text", Placeholder: wantNewMemberPlaceholder},
Expand Down
8 changes: 4 additions & 4 deletions web/webassert/asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func CSRFTokenPresent(t *testing.T, sel *goquery.Selection) {
a.Equal("hidden", tipe, "wrong type on csrf field")
}

type InputElement struct {
type FormElement struct {
Tag, Name, Value, Type, Placeholder string
}

// InputsInForm checks a list of defined elements. It tries to find them by input[name=$name]
// and then proceeds with asserting their value, type or placeholder (if the fields in InputElement are not "")
func InputsInForm(t *testing.T, form *goquery.Selection, elems []InputElement) {
// ElementsInForm checks a list of defined elements. It tries to find them by input[name=$name]
// and then proceeds with asserting their value, type or placeholder (if the fields in FormElement are not "")
func ElementsInForm(t *testing.T, form *goquery.Selection, elems []FormElement) {
a := assert.New(t)
for _, e := range elems {

Expand Down

0 comments on commit 7d6d992

Please sign in to comment.