Files
gitocean/tests/integration/explore_repos_test.go
T
0koandGusted a51a8d5701 chore(test): cleanup NewRequest which no longer supply CSRF values (#10119)
Followup to https://codeberg.org/forgejo/forgejo/pulls/9830, which greatly simplified the tests that previously had to supply a csrf token in values map, but left behind the more complex funcs with empty maps.

Also fixed a few typos which popped up in the diff.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10119
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: 0ko <0ko@noreply.codeberg.org>
Co-committed-by: 0ko <0ko@noreply.codeberg.org>
2025-11-14 23:21:10 +01:00

63 lines
2.0 KiB
Go

// Copyright 2017 The Gitea Authors. All rights reserved.
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"fmt"
"net/http"
"testing"
"forgejo.org/modules/setting"
"forgejo.org/tests"
"github.com/stretchr/testify/assert"
)
func testExploreStarForkCounters(t *testing.T, repoQuery, expectedStars, expectedForks string) {
resp := MakeRequest(t, NewRequest(t, "GET", fmt.Sprintf("/explore/repos?search=%s", repoQuery)), http.StatusOK)
repoListEntry := NewHTMLParser(t, resp.Body).Find(fmt.Sprintf(".flex-list > .flex-item:has(a[href='/%s'])", repoQuery))
starsAriaLabel, _ := repoListEntry.Find("a[href$='/stars']").Attr("aria-label")
forksAriaLabel, _ := repoListEntry.Find("a[href$='/forks']").Attr("aria-label")
assert.Equal(t, expectedStars, starsAriaLabel)
assert.Equal(t, expectedForks, forksAriaLabel)
}
func TestExploreRepos(t *testing.T) {
defer tests.PrepareTestEnv(t)()
req := NewRequest(t, "GET", "/explore/repos")
MakeRequest(t, req, http.StatusOK)
t.Run("Counters", func(t *testing.T) {
if setting.Database.Type.IsPostgreSQL() {
t.Skip("PGSQL is unable to find user2/repo1")
}
repo := "user2/repo1"
// Initial state: zeroes in the counters
testExploreStarForkCounters(t, repo, "0 stars", "0 forks")
// Star the repo
session := loginUser(t, "user5")
session.MakeRequest(t, NewRequest(t, "POST", fmt.Sprintf("/%s/action/star", repo)), http.StatusOK)
// Stars counter should have incremented
testExploreStarForkCounters(t, repo, "1 star", "0 forks")
})
t.Run("Persistent parameters", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
req := NewRequest(t, "GET", "/explore/repos?topic=1&language=Go")
resp := MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body).Find("#repo-search-form")
assert.Equal(t, "Go", htmlDoc.Find("input[name='language']").AttrOr("value", "not found"))
assert.Equal(t, "true", htmlDoc.Find("input[name='topic']").AttrOr("value", "not found"))
})
}