From 4b69aa5c1067495532b2cce8a42703dc63a256cc Mon Sep 17 00:00:00 2001 From: mirko Date: Tue, 24 Sep 2024 16:03:51 +0200 Subject: [PATCH] Add integration test for downloading a patch/diff file in compare page --- tests/integration/compare_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index 2d27a430ac..36c4d03e90 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -23,6 +23,7 @@ import ( files_service "code.gitea.io/gitea/services/repository/files" "code.gitea.io/gitea/tests" + "github.com/PuerkitoBio/goquery" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -67,6 +68,32 @@ func inspectCompare(t *testing.T, htmlDoc *HTMLDoc, diffCount int, diffChanges [ } } +func TestComparePatchAndDiffMenuEntries(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + session := loginUser(t, "user2") + req := NewRequest(t, "GET", "/user2/repo-release/compare/v1.0...v2.0") + resp := session.MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + diffOptions := htmlDoc.doc.Find("[data-tooltip-content=\"Diff options\"]") + + var patchDownloadEntryPresent bool + var diffDownloadEntryPresent bool + diffOptions.Children().Each(func (idx int, c *goquery.Selection) { + value, exists := c.Attr("download") + if exists && strings.HasSuffix(value, ".patch") { + patchDownloadEntryPresent = true + } + + if exists && strings.HasSuffix(value, ".diff") { + diffDownloadEntryPresent = true + } + }) + + assert.True(t, patchDownloadEntryPresent, "Patch file download entry should be present") + assert.True(t, diffDownloadEntryPresent, "Diff file download entry should be present") +} + // Git commit graph for repo20 // * 8babce9 (origin/remove-files-b) Add a dummy file // * b67e43a Delete test.csv and link_hi