forgejo/tests/e2e/git-notes.test.e2e.ts
Robert Wolff 296e6a284e fix(ui): improve Git notes editing (#11365)
Closes #11355, namely:

1. bug: editing the note does not edit the orginal content, but the rendered content
    - 16368c4ccb
    - edit raw notes instead of rendered notes
2. bug: editing existing note on single-commit PR page leads to 404 page because it sends a POST request to `/OWNER/REPO/pulls/ID/commits/COMMIT_HASH/notes`
    - f036fc55db
    - add new paths for the actions on pull request pages for `/OWNER/REPO/pulls/ID/commits/COMMIT_HASH/notes` and `/OWNER/REPO/pulls/ID/commits/COMMIT_HASH/notes/remove`
3. feat: both for adding and editing there is no `Cancel` button
    - 58d8c7cc87
    - moved both the `Cancel` and the `Save`/`Edit` button to the right for better consistency how, e.g., issue comments are edited/created.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11365
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Robert Wolff <mahlzahn@posteo.de>
Co-committed-by: Robert Wolff <mahlzahn@posteo.de>
2026-03-10 23:49:18 +01:00

57 lines
2.3 KiB
TypeScript

// @ts-check
import {expect} from '@playwright/test';
import {test} from './utils_e2e.ts';
import {screenshot} from './shared/screenshots.ts';
test.use({user: 'user2'});
test('Change git note', async ({page}) => {
const text = 'This is a new note <script>alert("xss")</script>.\nSee https://frogejo.org.';
let response = await page.goto('/user2/repo1/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d');
expect(response?.status()).toBe(200);
// An add button should not be present, because the commit already has a commit note
await expect(page.locator('#commit-notes-add-button')).toHaveCount(0);
let renderedarea = page.locator('#commit-notes-display-area pre.commit-body');
await expect(renderedarea).toBeVisible();
let textarea = page.locator('textarea[name="notes"]');
await expect(textarea).toBeHidden();
await page.locator('#commit-notes-edit-button').click();
await expect(renderedarea).toBeHidden();
await expect(textarea).toBeVisible();
await textarea.fill(text);
await screenshot(page, page.locator('.ui.container.fluid.padded'));
await page.locator('#commit-notes-save-button').click();
await expect(renderedarea).toBeVisible();
await expect(textarea).toBeHidden();
await expect(renderedarea).toHaveText(text);
await expect(renderedarea.locator('a')).toHaveAttribute('href', 'https://frogejo.org');
await screenshot(page, page.locator('.ui.container.fluid.padded'));
// Check edited note
response = await page.goto('/user2/repo1/commit/65f1bf27bc3bf70f64657658635e66094edbcb4d');
expect(response?.status()).toBe(200);
renderedarea = page.locator('#commit-notes-display-area pre.commit-body');
await expect(renderedarea).toHaveText(text);
await expect(renderedarea.locator('a')).toHaveAttribute('href', 'https://frogejo.org');
textarea = page.locator('textarea[name="notes"]');
await expect(textarea).toHaveText(text);
await expect(textarea.locator('a')).toHaveCount(0);
await screenshot(page, page.locator('.ui.container.fluid.padded'));
// Cancel note editing
await page.locator('#commit-notes-edit-button').click();
await textarea.fill('Edited note');
await page.locator('#commit-notes-cancel-button').click();
await expect(renderedarea).toBeVisible();
await expect(renderedarea).toHaveText(text);
await expect(textarea).toBeHidden();
await expect(textarea).toHaveText(text);
});