diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-01-07 18:50:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-07 10:50:03 +0000 |
commit | 9296c31ff7c42a6d3ddc9a1d7a54b084d786425e (patch) | |
tree | 2ce8dd8726e7474464912a3a0107eccd0e7d3546 /tests | |
parent | c5901b622dd5fae8da336b94150e63292489afed (diff) | |
download | gitea-9296c31ff7c42a6d3ddc9a1d7a54b084d786425e.tar.gz gitea-9296c31ff7c42a6d3ddc9a1d7a54b084d786425e.zip |
Fix incorrect URL for "Reference in New Issue" (#28716)
Gitea prefers to use relative URLs in code (to make multiple domain work
for some users)
So it needs to use `toAbsoluteUrl` to generate a full URL when click
"Reference in New Issues"
And add some comments in the test code
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/issue_test.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index b1080c998a..4b3f581c2b 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -607,3 +607,22 @@ func TestUpdateIssueDeadline(t *testing.T) { assert.EqualValues(t, "2022-04-06", apiIssue.Deadline.Format("2006-01-02")) } + +func TestIssueReferenceURL(t *testing.T) { + defer tests.PrepareTestEnv(t)() + session := loginUser(t, "user2") + + issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) + + req := NewRequest(t, "GET", fmt.Sprintf("%s/issues/%d", repo.FullName(), issue.Index)) + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + // the "reference" uses relative URLs, then JS code will convert them to absolute URLs for current origin, in case users are using multiple domains + ref, _ := htmlDoc.Find(`.timeline-item.comment.first .reference-issue`).Attr("data-reference") + assert.EqualValues(t, "/user2/repo1/issues/1#issue-1", ref) + + ref, _ = htmlDoc.Find(`.timeline-item.comment:not(.first) .reference-issue`).Attr("data-reference") + assert.EqualValues(t, "/user2/repo1/issues/1#issuecomment-2", ref) +} |