mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 06:43:34 +01:00
ui: fix go to citation button url (#4597)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4597 Reviewed-by: Ghost <twenty-panda@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Bram Hagens <bram@bramh.me> Co-committed-by: Bram Hagens <bram@bramh.me>
This commit is contained in:
parent
b670f111ff
commit
7f62acb4d9
4 changed files with 85 additions and 3 deletions
|
@ -781,7 +781,8 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {
|
|||
if content, err := entry.Blob().GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil {
|
||||
log.Error("checkCitationFile: GetBlobContent: %v", err)
|
||||
} else {
|
||||
ctx.Data["CitiationExist"] = true
|
||||
ctx.Data["CitationExist"] = true
|
||||
ctx.Data["CitationFile"] = entry.Name()
|
||||
ctx.PageData["citationFileContent"] = content
|
||||
break
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="ui stackable secondary menu">
|
||||
<div class="ui action input" id="citation-panel">
|
||||
{{template "repo/cite/cite_buttons" .}}
|
||||
<a id="goto-citation-btn" class="ui basic jump icon button" href="{{$.RepoLink}}/src/{{$.BranchName}}/CITATION.cff" data-tooltip-content="{{ctx.Locale.Tr "repo.find_file.go_to_file"}}">
|
||||
<a id="goto-citation-btn" class="ui basic jump icon button" href="{{$.RepoLink}}/src/{{$.BranchName}}/{{$.CitationFile}}" data-tooltip-content="{{ctx.Locale.Tr "repo.find_file.go_to_file"}}">
|
||||
{{svg "octicon-file-moved"}}
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
@ -133,7 +133,7 @@
|
|||
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.download_tar"}}</a>
|
||||
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.RefName}}.bundle" rel="nofollow">{{svg "octicon-package" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.download_bundle"}}</a>
|
||||
{{end}}
|
||||
{{if .CitiationExist}}
|
||||
{{if .CitationExist}}
|
||||
<a class="item" id="cite-repo-button">{{svg "octicon-cross-reference" 16 "tw-mr-2"}}{{ctx.Locale.Tr "repo.cite_this_repo"}}</a>
|
||||
{{end}}
|
||||
{{range .OpenWithEditorApps}}
|
||||
|
|
81
tests/integration/repo_citation_test.go
Normal file
81
tests/integration/repo_citation_test.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
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"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCitation(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||
|
||||
session := loginUser(t, user.LoginName)
|
||||
|
||||
t.Run("No citation", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
repo, _, f := CreateDeclarativeRepo(t, user, "citation-no-citation", []unit_model.Type{unit_model.TypeCode}, nil, nil)
|
||||
defer f()
|
||||
|
||||
testCitationButtonExists(t, session, repo, "", false)
|
||||
})
|
||||
|
||||
t.Run("cff citation", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
repo, f := createRepoWithEmptyFile(t, user, "citation-cff", "CITATION.cff")
|
||||
defer f()
|
||||
|
||||
testCitationButtonExists(t, session, repo, "CITATION.cff", true)
|
||||
})
|
||||
|
||||
t.Run("bib citation", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
repo, f := createRepoWithEmptyFile(t, user, "citation-bib", "CITATION.bib")
|
||||
defer f()
|
||||
|
||||
testCitationButtonExists(t, session, repo, "CITATION.bib", true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func testCitationButtonExists(t *testing.T, session *TestSession, repo *repo_model.Repository, file string, exists bool) {
|
||||
req := NewRequest(t, "GET", repo.HTMLURL())
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
doc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
doc.AssertElement(t, "#cite-repo-button", exists)
|
||||
|
||||
if exists {
|
||||
href, exists := doc.doc.Find("#goto-citation-btn").Attr("href")
|
||||
assert.True(t, exists)
|
||||
|
||||
assert.True(t, strings.HasSuffix(href, file))
|
||||
}
|
||||
}
|
||||
|
||||
func createRepoWithEmptyFile(t *testing.T, user *user_model.User, repoName, fileName string) (*repo_model.Repository, func()) {
|
||||
repo, _, f := CreateDeclarativeRepo(t, user, repoName, []unit_model.Type{unit_model.TypeCode}, nil, []*files_service.ChangeRepoFile{
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: fileName,
|
||||
},
|
||||
})
|
||||
|
||||
return repo, f
|
||||
}
|
Loading…
Reference in a new issue