loading up the forgejo repo on tangled to test page performance

Merge pull request 'Highlight user mention in comments and commit messages' (#5899) from 0ko/forgejo:mention-highlight into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5899
Reviewed-by: Otto <otto@codeberg.org>

Otto d1ad4dd5 b92863b0

Changed files
+141 -23
.forgejo
workflows
templates
tests
+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
··· 26 26 .ui.secondary.menu .dropdown.item > .menu { margin-top: 0; } 27 27 </style> 28 28 </noscript> 29 + {{template "shared/user/mention_highlight" .}} 29 30 {{template "base/head_opengraph" .}} 30 31 {{template "base/head_style" .}} 31 32 {{template "custom/header" .}}
+14
templates/shared/user/mention_highlight.tmpl
··· 1 + {{if .IsSigned}} 2 + <style> 3 + .comment, 4 + .commit-summary, 5 + .commit-body { 6 + .mention[href="{{AppSubUrl}}/{{.SignedUser.Name}}" i] { 7 + background-color: var(--color-primary-alpha-30); 8 + color: var(--color-primary-dark-2); 9 + border-radius: 5px; 10 + padding: 1px 4px; 11 + } 12 + } 13 + </style> 14 + {{end}}
+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
··· 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 + });
+35
tests/e2e/shared/accessibility.ts
··· 1 + import {expect, type Page} from '@playwright/test'; 2 + import {AxeBuilder} from '@axe-core/playwright'; 3 + 4 + export async function accessibilityCheck({page}: {page: Page}, includes: string[], excludes: string[], disabledRules: string[]) { 5 + // contrast of inline links is still a global issue in Forgejo 6 + disabledRules += 'link-in-text-block'; 7 + 8 + let accessibilityScanner = await new AxeBuilder({page}) 9 + .disableRules(disabledRules); 10 + // passing the whole array seems to be not supported, 11 + // iterating has the nice side-effectof skipping this if the array is empty 12 + for (const incl of includes) { 13 + // passing the whole array seems to be not supported 14 + accessibilityScanner = accessibilityScanner.include(incl); 15 + } 16 + for (const excl of excludes) { 17 + accessibilityScanner = accessibilityScanner.exclude(excl); 18 + } 19 + 20 + // scan the page both in dark and light theme 21 + let accessibilityScanResults = await accessibilityScanner.analyze(); 22 + expect(accessibilityScanResults.violations).toEqual([]); 23 + await page.emulateMedia({colorScheme: 'dark'}); 24 + // in https://codeberg.org/forgejo/forgejo/pulls/5899 there have been 25 + // some weird failures related to contrast scanning, 26 + // reporting for colours that haven't been used and no trace in the 27 + // screenshots. 28 + // Since this was only happening with some browsers and not always, 29 + // my bet is on a transition effect on dark/light mode switch. 30 + // Waiting a little seems to work around this. 31 + await page.waitForTimeout(100); // eslint-disable-line playwright/no-wait-for-timeout 32 + accessibilityScanResults = await accessibilityScanner.analyze(); 33 + expect(accessibilityScanResults.violations).toEqual([]); 34 + await page.emulateMedia({colorScheme: 'light'}); 35 + }
+6 -9
tests/e2e/shared/forms.ts
··· 1 1 import {expect, type Page} from '@playwright/test'; 2 - import {AxeBuilder} from '@axe-core/playwright'; 2 + import {accessibilityCheck} from './accessibility.ts'; 3 3 4 4 export async function validate_form({page}: {page: Page}, scope: 'form' | 'fieldset' = 'form') { 5 - const accessibilityScanResults = await new AxeBuilder({page}) 6 - // disable checking for link style - should be fixed, but not now 7 - .disableRules('link-in-text-block') 8 - .include(scope) 5 + const excludedElements = [ 9 6 // exclude automated tooltips from accessibility scan, remove when fixed 10 - .exclude('span[data-tooltip-content') 7 + 'span[data-tooltip-content', 11 8 // exclude weird non-semantic HTML disabled content 12 - .exclude('.disabled') 13 - .analyze(); 14 - expect(accessibilityScanResults.violations).toEqual([]); 9 + '.disabled', 10 + ]; 11 + await accessibilityCheck({page}, [scope], excludedElements, []); 15 12 16 13 // assert CSS properties that needed to be overriden for forms (ensure they remain active) 17 14 const boxes = page.getByRole('checkbox').or(page.getByRole('radio'));
+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 + }