+7
.forgejo/workflows/testing.yml
+7
.forgejo/workflows/testing.yml
···
122
122
USE_REPO_TEST_DIR: 1
123
123
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
124
124
CHANGED_FILES: ${{steps.changed-files.outputs.all_changed_files}}
125
+
- name: Upload screenshots on failure
126
+
if: failure()
127
+
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
128
+
with:
129
+
name: screenshots.zip
130
+
path: /workspace/forgejo/forgejo/tests/e2e/test-artifacts/*/*.png
131
+
retention-days: 3
125
132
test-remote-cacher:
126
133
if: vars.ROLE == 'forgejo-coding' || vars.ROLE == 'forgejo-testing'
127
134
runs-on: docker
+1
templates/base/head.tmpl
+1
templates/base/head.tmpl
+35
-13
tests/e2e/declare_repos_test.go
+35
-13
tests/e2e/declare_repos_test.go
···
5
5
6
6
import (
7
7
"fmt"
8
-
"strconv"
9
8
"strings"
10
9
"testing"
11
10
"time"
···
23
22
24
23
// first entry represents filename
25
24
// the following entries define the full file content over time
26
-
type FileChanges [][]string
25
+
type FileChanges struct {
26
+
Filename string
27
+
CommitMsg string
28
+
Versions []string
29
+
}
27
30
28
31
// put your Git repo declarations in here
29
32
// feel free to amend the helper function below or use the raw variant directly
30
33
func DeclareGitRepos(t *testing.T) func() {
31
34
cleanupFunctions := []func(){
32
-
newRepo(t, 2, "diff-test", FileChanges{
33
-
{"testfile", "hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"},
35
+
newRepo(t, 2, "diff-test", []FileChanges{{
36
+
Filename: "testfile",
37
+
Versions: []string{"hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"},
38
+
}}),
39
+
newRepo(t, 2, "mentions-highlighted", []FileChanges{
40
+
{
41
+
Filename: "history1.md",
42
+
Versions: []string{""},
43
+
CommitMsg: "A commit message which mentions @user2 in the title\nand has some additional text which mentions @user1",
44
+
},
45
+
{
46
+
Filename: "history2.md",
47
+
Versions: []string{""},
48
+
CommitMsg: "Another commit which mentions @user1 in the title\nand @user2 in the text",
49
+
},
34
50
}),
35
51
// add your repo declarations here
36
52
}
···
42
58
}
43
59
}
44
60
45
-
func newRepo(t *testing.T, userID int64, repoName string, fileChanges FileChanges) func() {
61
+
func newRepo(t *testing.T, userID int64, repoName string, fileChanges []FileChanges) func() {
46
62
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID})
47
63
somerepo, _, cleanupFunc := tests.CreateDeclarativeRepo(t, user, repoName,
48
64
[]unit_model.Type{unit_model.TypeCode, unit_model.TypeIssues}, nil,
···
50
66
)
51
67
52
68
for _, file := range fileChanges {
53
-
changeLen := len(file)
54
-
for i := 1; i < changeLen; i++ {
55
-
operation := "create"
56
-
if i != 1 {
57
-
operation = "update"
69
+
for i, version := range file.Versions {
70
+
operation := "update"
71
+
if i == 0 {
72
+
operation = "create"
58
73
}
74
+
75
+
// default to unique commit messages
76
+
commitMsg := file.CommitMsg
77
+
if commitMsg == "" {
78
+
commitMsg = fmt.Sprintf("Patch: %s-%d", file.Filename, i+1)
79
+
}
80
+
59
81
resp, err := files_service.ChangeRepoFiles(git.DefaultContext, somerepo, user, &files_service.ChangeRepoFilesOptions{
60
82
Files: []*files_service.ChangeRepoFile{{
61
83
Operation: operation,
62
-
TreePath: file[0],
63
-
ContentReader: strings.NewReader(file[i]),
84
+
TreePath: file.Filename,
85
+
ContentReader: strings.NewReader(version),
64
86
}},
65
-
Message: fmt.Sprintf("Patch: %s-%s", file[0], strconv.Itoa(i)),
87
+
Message: commitMsg,
66
88
OldBranch: "main",
67
89
NewBranch: "main",
68
90
Author: &files_service.IdentityOptions{
+22
-1
tests/e2e/repo-code.test.e2e.ts
+22
-1
tests/e2e/repo-code.test.e2e.ts
···
5
5
// @watch end
6
6
7
7
import {expect} from '@playwright/test';
8
-
import {test} from './utils_e2e.ts';
8
+
import {test, login_user, login} from './utils_e2e.ts';
9
+
import {accessibilityCheck} from './shared/accessibility.ts';
10
+
11
+
test.beforeAll(async ({browser}, workerInfo) => {
12
+
await login_user(browser, workerInfo, 'user2');
13
+
});
9
14
10
15
async function assertSelectedLines(page, nums) {
11
16
const pageAssertions = async () => {
···
75
80
}
76
81
}
77
82
});
83
+
84
+
test('Username highlighted in commits', async ({browser}, workerInfo) => {
85
+
const page = await login({browser}, workerInfo);
86
+
await page.goto('/user2/mentions-highlighted/commits/branch/main');
87
+
// check first commit
88
+
await page.getByRole('link', {name: 'A commit message which'}).click();
89
+
await expect(page.getByRole('link', {name: '@user2'})).toHaveCSS('background-color', /(.*)/);
90
+
await expect(page.getByRole('link', {name: '@user1'})).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
91
+
await accessibilityCheck({page}, ['.commit-header'], [], []);
92
+
// check second commit
93
+
await page.goto('/user2/mentions-highlighted/commits/branch/main');
94
+
await page.locator('tbody').getByRole('link', {name: 'Another commit which mentions'}).click();
95
+
await expect(page.getByRole('link', {name: '@user2'})).toHaveCSS('background-color', /(.*)/);
96
+
await expect(page.getByRole('link', {name: '@user1'})).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
97
+
await accessibilityCheck({page}, ['.commit-header'], [], []);
98
+
});
+21
tests/integration/mention_test.go
+21
tests/integration/mention_test.go
···
1
+
// Copyright 2024 The Forgejo Authors. All rights reserved.
2
+
// SPDX-License-Identifier: GPL-3.0-or-later
3
+
4
+
package integration
5
+
6
+
import (
7
+
"net/http"
8
+
"testing"
9
+
10
+
"github.com/stretchr/testify/assert"
11
+
)
12
+
13
+
func TestHeadMentionCSS(t *testing.T) {
14
+
userSession := loginUser(t, "user2")
15
+
resp := userSession.MakeRequest(t, NewRequest(t, "GET", "/"), http.StatusOK)
16
+
assert.Contains(t, resp.Body.String(), `.mention[href="/user2" i]`)
17
+
18
+
guestSession := emptyTestSession(t)
19
+
resp = guestSession.MakeRequest(t, NewRequest(t, "GET", "/"), http.StatusOK)
20
+
assert.NotContains(t, resp.Body.String(), `.mention[href="`)
21
+
}