1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-24 08:57:03 -05:00

tests(e2e): mention highlights in commit messages

This commit is contained in:
Otto Richter 2024-11-10 20:09:53 +01:00
parent c17b4bdaeb
commit 1f7a648057
2 changed files with 57 additions and 14 deletions

View file

@ -5,7 +5,6 @@ package e2e
import (
"fmt"
"strconv"
"strings"
"testing"
"time"
@ -23,14 +22,31 @@ import (
// first entry represents filename
// the following entries define the full file content over time
type FileChanges [][]string
type FileChanges struct {
Filename string
CommitMsg string
Versions []string
}
// put your Git repo declarations in here
// feel free to amend the helper function below or use the raw variant directly
func DeclareGitRepos(t *testing.T) func() {
cleanupFunctions := []func(){
newRepo(t, 2, "diff-test", FileChanges{
{"testfile", "hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"},
newRepo(t, 2, "diff-test", []FileChanges{{
Filename: "testfile",
Versions: []string{"hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"},
}}),
newRepo(t, 2, "mentions-highlighted", []FileChanges{
{
Filename: "history1.md",
Versions: []string{""},
CommitMsg: "A commit message which mentions @user2 in the title\nand has some additional text which mentions @user1",
},
{
Filename: "history2.md",
Versions: []string{""},
CommitMsg: "Another commit which mentions @user1 in the title\nand @user2 in the text",
},
}),
// add your repo declarations here
}
@ -42,7 +58,7 @@ func DeclareGitRepos(t *testing.T) func() {
}
}
func newRepo(t *testing.T, userID int64, repoName string, fileChanges FileChanges) func() {
func newRepo(t *testing.T, userID int64, repoName string, fileChanges []FileChanges) func() {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID})
somerepo, _, cleanupFunc := tests.CreateDeclarativeRepo(t, user, repoName,
[]unit_model.Type{unit_model.TypeCode, unit_model.TypeIssues}, nil,
@ -50,19 +66,25 @@ func newRepo(t *testing.T, userID int64, repoName string, fileChanges FileChange
)
for _, file := range fileChanges {
changeLen := len(file)
for i := 1; i < changeLen; i++ {
operation := "create"
if i != 1 {
operation = "update"
for i, version := range file.Versions {
operation := "update"
if i == 0 {
operation = "create"
}
// default to unique commit messages
commitMsg := file.CommitMsg
if commitMsg == "" {
commitMsg = fmt.Sprintf("Patch: %s-%d", file.Filename, i+1)
}
resp, err := files_service.ChangeRepoFiles(git.DefaultContext, somerepo, user, &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{{
Operation: operation,
TreePath: file[0],
ContentReader: strings.NewReader(file[i]),
TreePath: file.Filename,
ContentReader: strings.NewReader(version),
}},
Message: fmt.Sprintf("Patch: %s-%s", file[0], strconv.Itoa(i)),
Message: commitMsg,
OldBranch: "main",
NewBranch: "main",
Author: &files_service.IdentityOptions{

View file

@ -5,7 +5,12 @@
// @watch end
import {expect} from '@playwright/test';
import {test} from './utils_e2e.ts';
import {test, login_user, login} from './utils_e2e.ts';
import {accessibilityCheck} from './shared/accessibility.ts';
test.beforeAll(async ({browser}, workerInfo) => {
await login_user(browser, workerInfo, 'user2');
});
async function assertSelectedLines(page, nums) {
const pageAssertions = async () => {
@ -75,3 +80,19 @@ test('Readable diff', async ({page}, workerInfo) => {
}
}
});
test('Username highlighted in commits', async ({browser}, workerInfo) => {
const page = await login({browser}, workerInfo);
await page.goto('/user2/mentions-highlighted/commits/branch/main');
// check first commit
await page.getByRole('link', {name: 'A commit message which'}).click();
await expect(page.getByRole('link', {name: '@user2'})).toHaveCSS('background-color', /(.*)/);
await expect(page.getByRole('link', {name: '@user1'})).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
await accessibilityCheck({page}, ['.commit-header'], [], []);
// check second commit
await page.goto('/user2/mentions-highlighted/commits/branch/main');
await page.locator('tbody').getByRole('link', {name: 'Another commit which mentions'}).click();
await expect(page.getByRole('link', {name: '@user2'})).toHaveCSS('background-color', /(.*)/);
await expect(page.getByRole('link', {name: '@user1'})).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
await accessibilityCheck({page}, ['.commit-header'], [], []);
});