From 858fbbaafd984c5706089235e1b5397fd4a3d169 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 3 Apr 2024 15:37:12 +0200 Subject: [PATCH] [BUG] Disable 'View at this point in history' for wikis - Don't show the 'View at this point in history' button for wikis as wikis don't have this feature. - Adds integration test - Resolves https://codeberg.org/forgejo/forgejo/issues/2995 (cherry picked from commit 8df9100994bb1ddf849b75bdf5e98c848c31f769) --- templates/repo/commits_list.tmpl | 2 ++ tests/integration/view_test.go | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index bae9924141..7b8f51ee87 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -78,12 +78,14 @@ {{end}} + {{if not $.PageIsWiki}} {{svg "octicon-file-code"}} + {{end}} {{end}} diff --git a/tests/integration/view_test.go b/tests/integration/view_test.go index cd63304a91..e77cc382e9 100644 --- a/tests/integration/view_test.go +++ b/tests/integration/view_test.go @@ -4,6 +4,7 @@ package integration import ( + "fmt" "net/http" "net/url" "strings" @@ -129,3 +130,58 @@ func TestAmbiguousCharacterDetection(t *testing.T) { }) }) } + +func TestInHistoryButton(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, commitID, f := CreateDeclarativeRepo(t, user2, "", + []unit_model.Type{unit_model.TypeCode, unit_model.TypeWiki}, nil, + []*files_service.ChangeRepoFile{ + { + Operation: "create", + TreePath: "test.sh", + ContentReader: strings.NewReader("Hello there!"), + }, + }, + ) + defer f() + + req := NewRequestWithValues(t, "POST", repo.Link()+"/wiki?action=new", map[string]string{ + "_csrf": GetCSRF(t, session, repo.Link()+"/wiki?action=new"), + "title": "Normal", + "content": "Hello world!", + }) + session.MakeRequest(t, req, http.StatusSeeOther) + + t.Run("Wiki revision", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", repo.Link()+"/wiki/Normal?action=_revision") + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + htmlDoc.AssertElement(t, fmt.Sprintf(".commit-list a[href^='/%s/src/commit/']", repo.FullName()), false) + }) + + t.Run("Commit list", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", repo.Link()+"/commits/branch/main") + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + htmlDoc.AssertElement(t, fmt.Sprintf(".commit-list a[href='/%s/src/commit/%s']", repo.FullName(), commitID), true) + }) + + t.Run("File history", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "GET", repo.Link()+"/commits/branch/main/test.sh") + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + htmlDoc.AssertElement(t, fmt.Sprintf(".commit-list a[href='/%s/src/commit/%s/test.sh']", repo.FullName(), commitID), true) + }) + }) +}