summaryrefslogtreecommitdiffstats
path: root/tests/integration/user_profile_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
commitdd136858f1ea40ad3c94191d647487fa4f31926c (patch)
tree58fec94a7b2a12510c9664b21793f1ed560c6518 /tests/integration/user_profile_test.go
parentInitial commit. (diff)
downloadforgejo-debian.tar.xz
forgejo-debian.zip
Adding upstream version 9.0.0.upstream/9.0.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to '')
-rw-r--r--tests/integration/user_profile_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/integration/user_profile_test.go b/tests/integration/user_profile_test.go
new file mode 100644
index 0000000..5532403
--- /dev/null
+++ b/tests/integration/user_profile_test.go
@@ -0,0 +1,67 @@
+// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package integration
+
+import (
+ "net/http"
+ "net/url"
+ "strings"
+ "testing"
+
+ "code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
+ files_service "code.gitea.io/gitea/services/repository/files"
+ "code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestUserProfile(t *testing.T) {
+ onGiteaRun(t, func(t *testing.T, u *url.URL) {
+ checkReadme := func(t *testing.T, title, readmeFilename string, expectedCount int) {
+ t.Run(title, func(t *testing.T) {
+ defer tests.PrintCurrentTest(t)()
+
+ // Prepare the test repository
+ user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
+
+ var ops []*files_service.ChangeRepoFile
+ op := "create"
+ if readmeFilename != "README.md" {
+ ops = append(ops, &files_service.ChangeRepoFile{
+ Operation: "delete",
+ TreePath: "README.md",
+ })
+ } else {
+ op = "update"
+ }
+ if readmeFilename != "" {
+ ops = append(ops, &files_service.ChangeRepoFile{
+ Operation: op,
+ TreePath: readmeFilename,
+ ContentReader: strings.NewReader("# Hi!\n"),
+ })
+ }
+
+ _, _, f := tests.CreateDeclarativeRepo(t, user2, ".profile", nil, nil, ops)
+ defer f()
+
+ // Perform the test
+ req := NewRequest(t, "GET", "/user2")
+ resp := MakeRequest(t, req, http.StatusOK)
+
+ doc := NewHTMLParser(t, resp.Body)
+ readmeCount := doc.Find("#readme_profile").Length()
+
+ assert.Equal(t, expectedCount, readmeCount)
+ })
+ }
+
+ checkReadme(t, "No readme", "", 0)
+ checkReadme(t, "README.md", "README.md", 1)
+ checkReadme(t, "readme.md", "readme.md", 1)
+ checkReadme(t, "ReadMe.mD", "ReadMe.mD", 1)
+ checkReadme(t, "readme.org does not render", "README.org", 0)
+ })
+}