diff --git a/tests/e2e/declare_repos_test.go b/tests/e2e/declare_repos_test.go index 7057b26b6f..c55a42ac66 100644 --- a/tests/e2e/declare_repos_test.go +++ b/tests/e2e/declare_repos_test.go @@ -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{ diff --git a/tests/e2e/repo-code.test.e2e.ts b/tests/e2e/repo-code.test.e2e.ts index b22670ab76..d114a9b9c0 100644 --- a/tests/e2e/repo-code.test.e2e.ts +++ b/tests/e2e/repo-code.test.e2e.ts @@ -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'], [], []); +});