jojo/routers/web/repo/commit_test.go
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
    - https://codeberg.org/forgejo/forgejo/pulls/11365/commits/16368c4ccb7c5e4711599abe5a607d0a9da81f9b
    - 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`
    - https://codeberg.org/forgejo/forgejo/pulls/11365/commits/f036fc55db6b32975f6b0d78d0a7b0e34cd5e866
    - 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
    - https://codeberg.org/forgejo/forgejo/pulls/11365/commits/58d8c7cc872f34ddb092fe2c28d757580d16a320
    - 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

58 lines
1.7 KiB
Go

// Copyright 2026 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package repo
import (
"net/http"
"testing"
"forgejo.org/models/unittest"
"forgejo.org/modules/git"
"forgejo.org/modules/test"
"forgejo.org/modules/web"
"forgejo.org/services/contexttest"
"forgejo.org/services/forms"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSetCommitNotes(t *testing.T) {
unittest.PrepareTestEnv(t)
commitID := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
path := "/user2/repo1/commit/" + commitID
ctx, _ := contexttest.MockContext(t, path)
ctx.SetParams(":sha", commitID)
contexttest.LoadUser(t, ctx, 2)
contexttest.LoadRepo(t, ctx, 1)
contexttest.LoadGitRepo(t, ctx)
notes := `This is a new note.\nSee https://frogejo.org.`
web.SetForm(ctx, &forms.CommitNotesForm{
Notes: notes,
})
SetCommitNotes(ctx)
assert.Equal(t, http.StatusSeeOther, ctx.Resp.Status())
assert.Equal(t, path, test.RedirectURL(ctx.Resp))
note, err := git.GetNote(ctx, ctx.Repo.GitRepo, commitID)
require.NoError(t, err)
assert.Equal(t, []byte(notes+"\n"), note.Message)
}
func TestRemoveCommitNotes(t *testing.T) {
unittest.PrepareTestEnv(t)
commitID := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
path := "/user2/repo1/commit/" + commitID
ctx, _ := contexttest.MockContext(t, path)
ctx.SetParams(":sha", commitID)
contexttest.LoadUser(t, ctx, 2)
contexttest.LoadRepo(t, ctx, 1)
contexttest.LoadGitRepo(t, ctx)
RemoveCommitNotes(ctx)
assert.Equal(t, http.StatusSeeOther, ctx.Resp.Status())
assert.Equal(t, path, test.RedirectURL(ctx.Resp))
note, err := git.GetNote(ctx, ctx.Repo.GitRepo, commitID)
require.Error(t, err)
assert.True(t, git.IsErrNotExist(err))
assert.Nil(t, note)
}