mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-04 22:00:39 +00:00
fix: preserve object format dropdown options on /repo/create error (#4360)
To reproduce: - make the repo creation form return with an error, like a duplicate name - click on the Object format dropdown - the options are missing as the listbox is empty Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4360 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Solomon Victorino <git@solomonvictorino.com> Co-committed-by: Solomon Victorino <git@solomonvictorino.com>
This commit is contained in:
parent
8e56f61d0f
commit
df22f8da5f
4 changed files with 89 additions and 21 deletions
|
@ -5,6 +5,7 @@ package integration
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
@ -36,6 +37,37 @@ func (doc *HTMLDoc) GetInputValueByName(name string) string {
|
|||
return text
|
||||
}
|
||||
|
||||
func (doc *HTMLDoc) AssertDropdown(t testing.TB, name string) *goquery.Selection {
|
||||
t.Helper()
|
||||
|
||||
dropdownGroup := doc.Find(fmt.Sprintf(".dropdown:has(input[name='%s'])", name))
|
||||
assert.Equal(t, dropdownGroup.Length(), 1, fmt.Sprintf("%s dropdown does not exist", name))
|
||||
return dropdownGroup
|
||||
}
|
||||
|
||||
// Assert that a dropdown has at least one non-empty option
|
||||
func (doc *HTMLDoc) AssertDropdownHasOptions(t testing.TB, dropdownName string) {
|
||||
t.Helper()
|
||||
|
||||
options := doc.AssertDropdown(t, dropdownName).Find(".menu [data-value]:not([data-value=''])")
|
||||
assert.Greater(t, options.Length(), 0, fmt.Sprintf("%s dropdown has no options", dropdownName))
|
||||
}
|
||||
|
||||
func (doc *HTMLDoc) AssertDropdownHasSelectedOption(t testing.TB, dropdownName, expectedValue string) {
|
||||
t.Helper()
|
||||
|
||||
dropdownGroup := doc.AssertDropdown(t, dropdownName)
|
||||
|
||||
selectedValue, _ := dropdownGroup.Find(fmt.Sprintf("input[name='%s']", dropdownName)).Attr("value")
|
||||
assert.Equal(t, expectedValue, selectedValue, fmt.Sprintf("%s dropdown doesn't have expected value selected", dropdownName))
|
||||
|
||||
dropdownValues := dropdownGroup.Find(".menu [data-value]").Map(func(i int, s *goquery.Selection) string {
|
||||
value, _ := s.Attr("data-value")
|
||||
return value
|
||||
})
|
||||
assert.Contains(t, dropdownValues, expectedValue, fmt.Sprintf("%s dropdown doesn't have an option with expected value", dropdownName))
|
||||
}
|
||||
|
||||
// Find gets the descendants of each element in the current set of
|
||||
// matched elements, filtered by a selector. It returns a new Selection
|
||||
// object containing these matched elements.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue