diff options
author | Daniel Baumann <daniel@debian.org> | 2024-10-18 20:33:49 +0200 |
---|---|---|
committer | Daniel Baumann <daniel@debian.org> | 2024-12-12 23:57:56 +0100 |
commit | e68b9d00a6e05b3a941f63ffb696f91e554ac5ec (patch) | |
tree | 97775d6c13b0f416af55314eb6a89ef792474615 /tests/integration/repo_citation_test.go | |
parent | Initial commit. (diff) | |
download | forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.tar.xz forgejo-e68b9d00a6e05b3a941f63ffb696f91e554ac5ec.zip |
Adding upstream version 9.0.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to '')
-rw-r--r-- | tests/integration/repo_citation_test.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/integration/repo_citation_test.go b/tests/integration/repo_citation_test.go new file mode 100644 index 0000000..4f7e24e --- /dev/null +++ b/tests/integration/repo_citation_test.go @@ -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 := tests.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 := tests.CreateDeclarativeRepo(t, user, repoName, []unit_model.Type{unit_model.TypeCode}, nil, []*files_service.ChangeRepoFile{ + { + Operation: "create", + TreePath: fileName, + }, + }) + + return repo, f +} |