summaryrefslogtreecommitdiffstats
path: root/tests/integration/repo_wiki_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
commitdd136858f1ea40ad3c94191d647487fa4f31926c (patch)
tree58fec94a7b2a12510c9664b21793f1ed560c6518 /tests/integration/repo_wiki_test.go
parentInitial commit. (diff)
downloadforgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.tar.xz
forgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.zip
Adding upstream version 9.0.0.upstream/9.0.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'tests/integration/repo_wiki_test.go')
-rw-r--r--tests/integration/repo_wiki_test.go91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/integration/repo_wiki_test.go b/tests/integration/repo_wiki_test.go
new file mode 100644
index 0000000..316c045
--- /dev/null
+++ b/tests/integration/repo_wiki_test.go
@@ -0,0 +1,91 @@
+// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package integration
+
+import (
+ "fmt"
+ "net/http"
+ "testing"
+
+ auth_model "code.gitea.io/gitea/models/auth"
+ repo_model "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/modules/setting"
+ api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/PuerkitoBio/goquery"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestWikiSearchContent(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ req := NewRequest(t, "GET", "/user2/repo1/wiki/search?q=This")
+ resp := MakeRequest(t, req, http.StatusOK)
+ doc := NewHTMLParser(t, resp.Body)
+ res := doc.Find(".item > b").Map(func(_ int, el *goquery.Selection) string {
+ return el.Text()
+ })
+ assert.Equal(t, []string{
+ "Home.md",
+ "Page-With-Spaced-Name.md",
+ "Unescaped File.md",
+ }, res)
+}
+
+func TestWikiBranchNormalize(t *testing.T) {
+ defer tests.PrepareTestEnv(t)()
+
+ username := "user2"
+ session := loginUser(t, username)
+ settingsURLStr := "/user2/repo1/settings"
+
+ assertNormalizeButton := func(present bool) string {
+ req := NewRequest(t, "GET", settingsURLStr) //.AddTokenAuth(token)
+ resp := session.MakeRequest(t, req, http.StatusOK)
+ htmlDoc := NewHTMLParser(t, resp.Body)
+ htmlDoc.AssertElement(t, "button[data-modal='#rename-wiki-branch-modal']", present)
+
+ return htmlDoc.GetCSRF()
+ }
+
+ // By default the repo wiki branch is empty
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ assert.Empty(t, repo.WikiBranch)
+
+ // This means we default to setting.Repository.DefaultBranch
+ assert.Equal(t, setting.Repository.DefaultBranch, repo.GetWikiBranchName())
+
+ // Which further means that the "Normalize wiki branch" parts do not appear on settings
+ assertNormalizeButton(false)
+
+ // Lets rename the branch!
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
+ repoURLStr := fmt.Sprintf("/api/v1/repos/%s/%s", username, repo.Name)
+ wikiBranch := "wiki"
+ req := NewRequestWithJSON(t, "PATCH", repoURLStr, &api.EditRepoOption{
+ WikiBranch: &wikiBranch,
+ }).AddTokenAuth(token)
+ MakeRequest(t, req, http.StatusOK)
+
+ // The wiki branch should now be changed
+ repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ assert.Equal(t, wikiBranch, repo.GetWikiBranchName())
+
+ // And as such, the button appears!
+ csrf := assertNormalizeButton(true)
+
+ // Invoking the normalization renames the wiki branch back to the default
+ req = NewRequestWithValues(t, "POST", settingsURLStr, map[string]string{
+ "_csrf": csrf,
+ "action": "rename-wiki-branch",
+ "repo_name": repo.FullName(),
+ })
+ session.MakeRequest(t, req, http.StatusSeeOther)
+
+ repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
+ assert.Equal(t, setting.Repository.DefaultBranch, repo.GetWikiBranchName())
+ assertNormalizeButton(false)
+}