mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-04-21 01:36:57 -04:00
Some checks failed
/ release (push) Has been cancelled
testing-integration / test-unit (push) Has been cancelled
testing-integration / test-sqlite (push) Has been cancelled
testing-integration / test-mariadb (v10.6) (push) Has been cancelled
testing-integration / test-mariadb (v11.8) (push) Has been cancelled
testing / backend-checks (push) Has been cancelled
testing / frontend-checks (push) Has been cancelled
testing / test-unit (push) Has been cancelled
testing / test-e2e (push) Has been cancelled
testing / test-remote-cacher (redis) (push) Has been cancelled
testing / test-remote-cacher (valkey) (push) Has been cancelled
testing / test-remote-cacher (garnet) (push) Has been cancelled
testing / test-remote-cacher (redict) (push) Has been cancelled
testing / test-mysql (push) Has been cancelled
testing / test-pgsql (push) Has been cancelled
testing / test-sqlite (push) Has been cancelled
testing / security-check (push) Has been cancelled
Closes: #10153  Co-authored-by: 0ko <0ko@noreply.codeberg.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10227 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: nachtjasmin <nachtjasmin@posteo.de> Co-committed-by: nachtjasmin <nachtjasmin@posteo.de>
66 lines
2.2 KiB
Go
66 lines
2.2 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)
|
|
|
|
// Verify that correct icons are used
|
|
assert.True(t, repoListEntry.Find("a[href$='/stars'] > svg").HasClass("octicon-star"))
|
|
assert.True(t, repoListEntry.Find("a[href$='/forks'] > svg").HasClass("octicon-repo-forked"))
|
|
}
|
|
|
|
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"))
|
|
})
|
|
}
|