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 ( import (
"fmt" "fmt"
"strconv"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -23,14 +22,31 @@ import (
// first entry represents filename // first entry represents filename
// the following entries define the full file content over time // 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 // put your Git repo declarations in here
// feel free to amend the helper function below or use the raw variant directly // feel free to amend the helper function below or use the raw variant directly
func DeclareGitRepos(t *testing.T) func() { func DeclareGitRepos(t *testing.T) func() {
cleanupFunctions := []func(){ cleanupFunctions := []func(){
newRepo(t, 2, "diff-test", FileChanges{ newRepo(t, 2, "diff-test", []FileChanges{{
{"testfile", "hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"}, 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 // 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}) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID})
somerepo, _, cleanupFunc := tests.CreateDeclarativeRepo(t, user, repoName, somerepo, _, cleanupFunc := tests.CreateDeclarativeRepo(t, user, repoName,
[]unit_model.Type{unit_model.TypeCode, unit_model.TypeIssues}, nil, []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 { for _, file := range fileChanges {
changeLen := len(file) for i, version := range file.Versions {
for i := 1; i < changeLen; i++ { operation := "update"
operation := "create" if i == 0 {
if i != 1 { operation = "create"
operation = "update"
} }
// 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{ resp, err := files_service.ChangeRepoFiles(git.DefaultContext, somerepo, user, &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{{ Files: []*files_service.ChangeRepoFile{{
Operation: operation, Operation: operation,
TreePath: file[0], TreePath: file.Filename,
ContentReader: strings.NewReader(file[i]), ContentReader: strings.NewReader(version),
}}, }},
Message: fmt.Sprintf("Patch: %s-%s", file[0], strconv.Itoa(i)), Message: commitMsg,
OldBranch: "main", OldBranch: "main",
NewBranch: "main", NewBranch: "main",
Author: &files_service.IdentityOptions{ Author: &files_service.IdentityOptions{

View File

@ -5,7 +5,12 @@
// @watch end // @watch end
import {expect} from '@playwright/test'; 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) { async function assertSelectedLines(page, nums) {
const pageAssertions = async () => { 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'], [], []);
});