mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09:00
test: add e2e tests for comments, file tree, actions and branch protection (#40313)
Add e2e tests for flows that had no browser coverage: editing and quote-replying an issue with an uploaded image, file tree and go-to-file navigation, the Actions run view and workflow dispatch, and branch protection rules with their priority. The tests exposed bugs that are fixed here: - Quote reply into an empty comment box left the Comment button disabled - Removing an uploaded attachment did not update the comment buttons - Going back from a file opened via the file tree to the initially loaded page kept showing the other file Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
c4fb82858e
commit
9f93e8d808
10 files changed
+174
-19
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import {env} from 'node:process';
|
||||
import {expect, test} from '@playwright/test';
|
||||
import {apiCreateFiles, apiCreateRepo, apiHeaders, randomString} from './utils.ts';
|
||||
import {apiCreateFiles, apiCreateRepo, apiHeaders, login, randomString} from './utils.ts';
|
||||
|
||||
test('job queue refreshes with filter open', async ({page, request}) => {
|
||||
const owner = env.GITEA_TEST_E2E_USER;
|
||||
@@ -28,7 +28,45 @@ test('job queue refreshes with filter open', async ({page, request}) => {
|
||||
await expect(waitingFilter).toBeVisible();
|
||||
});
|
||||
|
||||
test('job log line permalink expands its step', async ({page}) => {
|
||||
test('workflow graph opens a job and steps expand by click or log permalink', async ({page}) => {
|
||||
await page.goto('/devtest/repo-action-view/runs/10');
|
||||
await page.locator('.workflow-graph .job-name').getByText('job-100', {exact: true}).click();
|
||||
await page.waitForURL('**/devtest/repo-action-view/runs/10/jobs/10000');
|
||||
await page.getByText('step 1 (mock fast)', {exact: true}).click();
|
||||
await expect(page.getByText('message for: step=1, cursor=23', {exact: true})).toBeVisible();
|
||||
|
||||
await page.goto('/devtest/repo-action-view/runs/10/jobs/1#jobstep-1-23');
|
||||
await expect(page.getByRole('link', {name: '23', exact: true})).toBeInViewport();
|
||||
});
|
||||
|
||||
test('run workflow dispatches a queued run with an input', async ({page, request}) => {
|
||||
const owner = env.GITEA_TEST_E2E_USER;
|
||||
const repo = `e2e-dispatch-${randomString(8)}`;
|
||||
await Promise.all([
|
||||
(async () => {
|
||||
await apiCreateRepo(request, {name: repo, autoInit: false});
|
||||
await apiCreateFiles(request, owner, repo, [{
|
||||
path: '.gitea/workflows/dispatch.yml',
|
||||
content: `run-name: Dispatch \${{ inputs.message }}
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
message:
|
||||
description: Run message
|
||||
jobs:
|
||||
queued:
|
||||
runs-on: no-runner
|
||||
steps:
|
||||
- run: exit 0
|
||||
`,
|
||||
}]);
|
||||
})(),
|
||||
login(page),
|
||||
]);
|
||||
await page.goto(`/${owner}/${repo}/actions?workflow=dispatch.yml`);
|
||||
await page.getByRole('button', {name: 'Run Workflow', exact: true}).click();
|
||||
const dispatchDialog = page.getByRole('dialog');
|
||||
await dispatchDialog.getByLabel('Run message').fill('from UI');
|
||||
await dispatchDialog.getByRole('button', {name: 'Run Workflow', exact: true}).click();
|
||||
await expect(page.getByRole('link', {name: 'Dispatch from UI', exact: true})).toBeVisible();
|
||||
});
|
||||
@@ -2,25 +2,47 @@ import {env} from 'node:process';
|
||||
import {test, expect} from '@playwright/test';
|
||||
import {login, apiCreateRepo, apiCreateIssue, apiEditIssue, randomString} from './utils.ts';
|
||||
|
||||
test('comment on and close an issue', async ({page, request}) => {
|
||||
test('edit an issue, quote-reply it with an uploaded image and close it', async ({page, request}) => {
|
||||
const repoName = `e2e-issue-comment-${randomString(8)}`;
|
||||
const owner = env.GITEA_TEST_E2E_USER;
|
||||
await apiCreateRepo(request, {name: repoName, autoInit: false});
|
||||
await Promise.all([
|
||||
apiCreateIssue(request, {owner, repo: repoName, title: 'Comment test'}),
|
||||
(async () => {
|
||||
await apiCreateRepo(request, {name: repoName, autoInit: false});
|
||||
await apiCreateIssue(request, {owner, repo: repoName, title: 'Comment test', body: 'Original body'});
|
||||
})(),
|
||||
login(page),
|
||||
]);
|
||||
await page.goto(`/${owner}/${repoName}/issues/1`);
|
||||
const commentButton = page.getByRole('button', {name: 'Comment', exact: true});
|
||||
await expect(commentButton).toBeDisabled();
|
||||
|
||||
const body = `e2e-comment-${randomString(8)}`;
|
||||
await page.getByPlaceholder('Leave a comment').fill(body);
|
||||
// exact match: the status button reads "Close with Comment" while the box has content, which substring-matches "Comment"
|
||||
await page.getByRole('button', {name: 'Comment', exact: true}).click();
|
||||
await expect(page.locator('.comment-body').filter({hasText: body})).toBeVisible();
|
||||
const contextMenu = page.getByRole('heading', {level: 3}).getByRole('menu');
|
||||
await contextMenu.click();
|
||||
await page.getByRole('menuitem', {name: 'Edit', exact: true}).click();
|
||||
const issueBody = page.getByRole('article');
|
||||
await expect(issueBody.getByRole('textbox')).toHaveValue('Original body');
|
||||
await issueBody.getByRole('textbox').fill('Updated **body**');
|
||||
await issueBody.getByRole('button', {name: 'Save', exact: true}).click();
|
||||
await expect(issueBody.getByText('Updated body', {exact: true})).toBeVisible();
|
||||
|
||||
// wait for the form to re-initialize (the empty box disables the comment button); a close click
|
||||
// before that does a native submit which lands on a raw JSON page instead of reloading the issue
|
||||
await expect(page.getByRole('button', {name: 'Comment', exact: true})).toBeDisabled();
|
||||
await contextMenu.click();
|
||||
await page.getByRole('menuitem', {name: 'Quote reply', exact: true}).click();
|
||||
await expect(commentButton).toBeEnabled();
|
||||
const editor = page.getByRole('textbox', {name: 'Leave a comment'});
|
||||
await editor.evaluate((textarea) => {
|
||||
const dataTransfer = new DataTransfer();
|
||||
dataTransfer.items.add(new File([
|
||||
Uint8Array.from(atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII='), (character) => character.charCodeAt(0)),
|
||||
], 'pixel.png', {type: 'image/png'}));
|
||||
textarea.dispatchEvent(new DragEvent('drop', {bubbles: true, cancelable: true, dataTransfer}));
|
||||
});
|
||||
await expect(editor).toHaveValue(/^> Updated \*\*body\*\*\n\n!\[pixel\.png\]\(attachments\/[\da-f-]+\)$/);
|
||||
await commentButton.click();
|
||||
await page.waitForURL(/#issuecomment-\d+$/);
|
||||
await expect(page.getByRole('article').getByRole('blockquote')).toHaveText('Updated body');
|
||||
await expect(page.getByRole('article').getByRole('img', {name: 'pixel.png', exact: true})).toHaveJSProperty('naturalWidth', 1);
|
||||
|
||||
await expect(commentButton).toBeDisabled();
|
||||
await page.getByRole('button', {name: 'Close Issue'}).click();
|
||||
await expect(page.getByRole('button', {name: 'Reopen Issue'})).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import {env} from 'node:process';
|
||||
import {expect, test} from '@playwright/test';
|
||||
import {apiCreateBranchProtection, apiCreateRepo, login, randomString} from './utils.ts';
|
||||
|
||||
test('branch protection rule keeps its push allowlist and dragged priority', async ({page, request}) => {
|
||||
const owner = env.GITEA_TEST_E2E_USER;
|
||||
const repo = `e2e-protection-${randomString(8)}`;
|
||||
await Promise.all([
|
||||
(async () => {
|
||||
await apiCreateRepo(request, {name: repo, autoInit: false});
|
||||
await apiCreateBranchProtection(request, owner, repo, 'release/stable');
|
||||
})(),
|
||||
login(page),
|
||||
]);
|
||||
await page.goto(`/${owner}/${repo}/settings/branches/edit`);
|
||||
const ruleNameInput = page.getByRole('textbox', {name: /^Protected Branch Name Pattern/});
|
||||
const allowlistRadio = page.getByRole('radio', {name: 'Allowlist Restricted Push', exact: true});
|
||||
await ruleNameInput.fill('release/**');
|
||||
await allowlistRadio.check();
|
||||
await page.locator('#whitelist_box').getByRole('combobox').click();
|
||||
await page.getByRole('option', {name: owner}).click();
|
||||
await page.getByRole('button', {name: 'Save Rule', exact: true}).click();
|
||||
await page.waitForURL(`/${owner}/${repo}/settings/branches`);
|
||||
|
||||
const rules = page.locator('#protected-branches-list > .item');
|
||||
await expect(rules).toHaveText([/release\/stable/, /release\/\*\*/]);
|
||||
const rule = rules.filter({hasText: 'release/**'});
|
||||
const handle = rule.locator('.drag-handle');
|
||||
const saved = page.waitForResponse('**/settings/branches/priority');
|
||||
await handle.hover();
|
||||
await page.mouse.down();
|
||||
await handle.hover({position: {x: 2, y: 2}});
|
||||
await expect(rule).toHaveClass(/card-ghost/);
|
||||
await rules.first().hover({position: {x: 10, y: 10}});
|
||||
await expect(rules.first()).toContainText('release/**');
|
||||
await page.mouse.up();
|
||||
await saved;
|
||||
await page.reload();
|
||||
await expect(rules).toHaveText([/release\/\*\*/, /release\/stable/]);
|
||||
|
||||
await rule.getByRole('link', {name: 'Edit', exact: true}).click();
|
||||
await expect(ruleNameInput).toHaveValue('release/**');
|
||||
await expect(allowlistRadio).toBeChecked();
|
||||
await expect(page.locator('#whitelist_box .dropdown > .label')).toHaveText(owner);
|
||||
});
|
||||
+29
-1
@@ -1,6 +1,6 @@
|
||||
import {env} from 'node:process';
|
||||
import {test, expect} from '@playwright/test';
|
||||
import {login, apiCreateBranch, apiCreateRepo, randomString} from './utils.ts';
|
||||
import {login, apiCreateBranch, apiCreateFiles, apiCreateRepo, randomString} from './utils.ts';
|
||||
|
||||
test('create a repository', async ({page}) => {
|
||||
const repoName = `e2e-repo-${randomString(8)}`;
|
||||
@@ -28,3 +28,31 @@ test('delete a branch via its modal', async ({page, request}) => {
|
||||
await modal.getByRole('button', {name: 'Yes'}).click();
|
||||
await expect(page.locator('.flash-message')).toContainText('Branch "feature" has been deleted.');
|
||||
});
|
||||
|
||||
test('file tree, history and go to file navigate between nested files', async ({page, request}) => {
|
||||
const repoName = `e2e-file-nav-${randomString(8)}`;
|
||||
const owner = env.GITEA_TEST_E2E_USER;
|
||||
await Promise.all([
|
||||
(async () => {
|
||||
await apiCreateRepo(request, {name: repoName, autoInit: false});
|
||||
await apiCreateFiles(request, owner, repoName, [
|
||||
{path: 'start.txt', content: 'Starting file content\n'},
|
||||
{path: 'docs/guide.txt', content: 'Nested guide content\n'},
|
||||
]);
|
||||
})(),
|
||||
login(page),
|
||||
]);
|
||||
await page.goto(`/${owner}/${repoName}/src/branch/main/start.txt`);
|
||||
const tree = page.locator('#view-file-tree');
|
||||
await tree.getByRole('link', {name: 'docs', exact: true}).locator('.item-toggle svg').click();
|
||||
await tree.getByRole('link', {name: 'guide.txt', exact: true}).click();
|
||||
await expect(page.getByText('Nested guide content', {exact: true})).toBeVisible();
|
||||
await page.goBack();
|
||||
await expect(page.getByText('Starting file content', {exact: true})).toBeVisible();
|
||||
|
||||
const search = page.getByRole('combobox', {name: 'Go to file'});
|
||||
await search.fill('docs/gu');
|
||||
await expect(page.getByRole('option')).toHaveText(['docs/guide.txt']);
|
||||
await search.press('Enter');
|
||||
await expect(page.getByText('Nested guide content', {exact: true})).toBeVisible();
|
||||
});
|
||||
@@ -105,6 +105,13 @@ export async function apiCreateBranch(requestContext: APIRequestContext, owner:
|
||||
}), 'apiCreateBranch');
|
||||
}
|
||||
|
||||
export async function apiCreateBranchProtection(requestContext: APIRequestContext, owner: string, repo: string, ruleName: string) {
|
||||
await apiRetry(() => requestContext.post(`${baseUrl()}/api/v1/repos/${owner}/${repo}/branch_protections`, {
|
||||
headers: apiHeaders(),
|
||||
data: {rule_name: ruleName},
|
||||
}), 'apiCreateBranchProtection');
|
||||
}
|
||||
|
||||
/** Create a PR via API. Returns the PR index for subsequent operations. */
|
||||
export async function apiCreatePR(requestContext: APIRequestContext, owner: string, repo: string, head: string, base: string, title: string, {headers}: {headers?: Record<string, string>} = {}): Promise<number> {
|
||||
const response = await apiRetry(() => requestContext.post(`${baseUrl()}/api/v1/repos/${owner}/${repo}/pulls`, {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import ViewFileTreeItem from './ViewFileTreeItem.vue';
|
||||
import {onMounted, useTemplateRef, type ShallowRef} from 'vue';
|
||||
import {createViewFileTreeStore} from './ViewFileTreeStore.ts';
|
||||
import {pathWithQuery} from '../utils/url.ts';
|
||||
|
||||
const elRoot = useTemplateRef('elRoot') as Readonly<ShallowRef<HTMLDivElement>>;
|
||||
|
||||
@@ -16,8 +17,13 @@ onMounted(async () => {
|
||||
store.rootFiles = await store.loadChildren('', props.treePath);
|
||||
elRoot.value.closest('.is-loading')?.classList?.remove('is-loading');
|
||||
window.addEventListener('popstate', (e) => {
|
||||
store.selectedItem = e.state?.treePath || '';
|
||||
if (e.state?.url) store.loadViewContent(e.state.url);
|
||||
if (pathWithQuery(window.location) === store.viewContentUrl) return;
|
||||
if (e.state?.url) {
|
||||
store.selectedItem = e.state.treePath;
|
||||
store.loadViewContent(e.state.url);
|
||||
} else {
|
||||
window.location.reload(); // not pushed by the tree, e.g. the initial page or an editor page
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {reactive} from 'vue';
|
||||
import {GET} from '../modules/fetch.ts';
|
||||
import {pathEscapeSegments} from '../utils/url.ts';
|
||||
import {pathEscapeSegments, pathWithQuery} from '../utils/url.ts';
|
||||
import {createElementFromHTML} from '../utils/dom.ts';
|
||||
import {html} from '../utils/html.ts';
|
||||
|
||||
@@ -18,6 +18,7 @@ export function createViewFileTreeStore(props: {repoLink: string, treePath: stri
|
||||
const store = reactive({
|
||||
rootFiles: [] as Array<FileTreeItem>,
|
||||
selectedItem: props.treePath,
|
||||
viewContentUrl: pathWithQuery(window.location),
|
||||
|
||||
async loadChildren(treePath: string, subPath: string = '') {
|
||||
// there is no git ref if no commits were made yet (an empty repo)
|
||||
@@ -39,6 +40,7 @@ export function createViewFileTreeStore(props: {repoLink: string, treePath: stri
|
||||
|
||||
async loadViewContent(url: string) {
|
||||
const u = new URL(url, window.origin);
|
||||
store.viewContentUrl = pathWithQuery(u);
|
||||
u.searchParams.set('only_content', 'true');
|
||||
const response = await GET(u.href);
|
||||
const elViewContent = document.querySelector('.repo-view-content')!;
|
||||
|
||||
@@ -256,7 +256,6 @@ export class ComboMarkdownEditor {
|
||||
return;
|
||||
}
|
||||
this.value(newContent);
|
||||
triggerEditorContentChanged(this.container);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -411,6 +410,7 @@ export class ComboMarkdownEditor {
|
||||
this.easyMDE.value(v);
|
||||
} else {
|
||||
this.textarea.value = v;
|
||||
triggerEditorContentChanged(this.container);
|
||||
}
|
||||
this.textareaAutosize?.resizeToFit();
|
||||
}
|
||||
|
||||
@@ -166,6 +166,9 @@ export function initTextareaEvents(textarea: HTMLTextAreaElement, dropzoneEl: HT
|
||||
});
|
||||
dropzoneEl?.dropzone.on(DropzoneCustomEventRemovedFile, ({fileUuid}: {fileUuid: string}) => {
|
||||
const newText = removeAttachmentLinksFromMarkdown(textarea.value, fileUuid);
|
||||
if (textarea.value !== newText) textarea.value = newText;
|
||||
if (textarea.value !== newText) {
|
||||
textarea.value = newText;
|
||||
triggerEditorContentChanged(textarea);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -44,3 +44,7 @@ export function pathEscapeSegments(s: string): string {
|
||||
// The same as backend's PathEscapeSegments
|
||||
return s.split('/').map(pathEscape).join('/');
|
||||
}
|
||||
|
||||
export function pathWithQuery(url: URL | Location) {
|
||||
return url.pathname + url.search;
|
||||
}
|
||||
Reference in new issue
Block a user