mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-15 07:09:47 +01:00
Merge pull request '[v7.0/forgejo] [BUG] Fix crash in issue forms' (#3036) from bp-v7.0/forgejo-b0cd0eb into v7.0/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3036 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
2bf3723939
2 changed files with 57 additions and 3 deletions
|
@ -1065,9 +1065,12 @@ func filePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
|
|||
|
||||
next := node.NextSibling
|
||||
for node != nil && node != next {
|
||||
locale, ok := ctx.Ctx.Value(translation.ContextKey).(translation.Locale)
|
||||
if !ok {
|
||||
locale = translation.NewLocale("en-US")
|
||||
locale := translation.NewLocale("en-US")
|
||||
if ctx.Ctx != nil {
|
||||
ctxLocale, ok := ctx.Ctx.Value(translation.ContextKey).(translation.Locale)
|
||||
if ok {
|
||||
locale = ctxLocale
|
||||
}
|
||||
}
|
||||
|
||||
preview := NewFilePreview(ctx, node, locale)
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
unit_model "code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/indexer/issues"
|
||||
|
@ -25,6 +26,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
@ -815,3 +817,52 @@ func TestIssueFilterNoFollow(t *testing.T) {
|
|||
assert.Equal(t, "nofollow", rel)
|
||||
})
|
||||
}
|
||||
|
||||
func TestIssueForm(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
session := loginUser(t, user2.Name)
|
||||
repo, _, f := CreateDeclarativeRepo(t, user2, "",
|
||||
[]unit_model.Type{unit_model.TypeCode, unit_model.TypeIssues}, nil,
|
||||
[]*files_service.ChangeRepoFile{
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: ".forgejo/issue_template/test.yaml",
|
||||
ContentReader: strings.NewReader(`name: Test
|
||||
about: Hello World
|
||||
body:
|
||||
- type: checkboxes
|
||||
id: test
|
||||
attributes:
|
||||
label: Test
|
||||
options:
|
||||
- label: This is a label
|
||||
`),
|
||||
},
|
||||
},
|
||||
)
|
||||
defer f()
|
||||
|
||||
t.Run("Choose list", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", repo.Link()+"/issues/new/choose")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
htmlDoc.AssertElement(t, "a[href$='/issues/new?template=.forgejo%2fissue_template%2ftest.yaml']", true)
|
||||
})
|
||||
|
||||
t.Run("Issue template", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", repo.Link()+"/issues/new?template=.forgejo%2fissue_template%2ftest.yaml")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
htmlDoc.AssertElement(t, "#new-issue .field .ui.checkbox input[name='form-field-test-0']", true)
|
||||
checkboxLabel := htmlDoc.Find("#new-issue .field .ui.checkbox label").Text()
|
||||
assert.Contains(t, checkboxLabel, "This is a label")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue