Add integration test for downloading a patch/diff file in compare page

This commit is contained in:
mirko 2024-09-24 16:03:51 +02:00
parent a302506095
commit 4b69aa5c10

View file

@ -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