mirror of
https://github.com/go-gitea/gitea.git
synced 2026-06-22 19:19:57 +00:00
Removes the legacy `delete-button` handler (`initGlobalDeleteButton`) and migrates all remaining usages to `link-action` and `show-modal` / `form-fetch-action`. Two handlers are adjusted for the new request shape: webauthn key delete reads `id` from the query, and account deletion returns `JSONError` on validation failure. A E2E test ist added to cover one of the use cases. Suggested in https://github.com/go-gitea/gitea/pull/38046#discussion_r3414936737. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: bircni <bircni@icloud.com>
73 lines
2.5 KiB
Go
73 lines
2.5 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"gitea.dev/models/db"
|
|
repo_model "gitea.dev/models/repo"
|
|
"gitea.dev/models/unittest"
|
|
"gitea.dev/modules/translation"
|
|
"gitea.dev/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestViewBranches(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
req := NewRequest(t, "GET", "/user2/repo1/branches")
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
AssertHTMLElement(t, htmlDoc, "[data-testid=branches-default-branch-list]", 1)
|
|
AssertHTMLElement(t, htmlDoc, "[data-testid=branches-default-branch-not-exist]", 0)
|
|
|
|
repo1.DefaultBranch = "non-existent-branch"
|
|
_, _ = db.GetEngine(t.Context()).ID(repo1.ID).Cols("default_branch").Update(repo1)
|
|
req = NewRequest(t, "GET", "/user2/repo1/branches")
|
|
resp = MakeRequest(t, req, http.StatusOK)
|
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
|
AssertHTMLElement(t, htmlDoc, "[data-testid=branches-default-branch-list]", 0)
|
|
AssertHTMLElement(t, htmlDoc, "[data-testid=branches-default-branch-not-exist]", 1)
|
|
}
|
|
|
|
func TestUndoDeleteBranch(t *testing.T) {
|
|
branchAction := func(t *testing.T, button, attr string) (*HTMLDoc, string) {
|
|
session := loginUser(t, "user2")
|
|
req := NewRequest(t, "GET", "/user2/repo1/branches")
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
link, exists := htmlDoc.doc.Find(button).Attr(attr)
|
|
require.True(t, exists, "The template has changed")
|
|
linkURL, err := url.Parse(link)
|
|
require.NoError(t, err)
|
|
|
|
req = NewRequest(t, "POST", link)
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
req = NewRequest(t, "GET", "/user2/repo1/branches")
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
return NewHTMLParser(t, resp.Body), linkURL.Query().Get("name")
|
|
}
|
|
|
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
|
htmlDoc, name := branchAction(t, ".delete-branch-button", "data-modal-form.action")
|
|
assert.Contains(t,
|
|
htmlDoc.doc.Find(".ui.positive.message").Text(),
|
|
translation.NewLocale("en-US").TrString("repo.branch.deletion_success", name),
|
|
)
|
|
htmlDoc, name = branchAction(t, ".restore-branch-button", "data-url")
|
|
assert.Contains(t,
|
|
htmlDoc.doc.Find(".ui.positive.message").Text(),
|
|
translation.NewLocale("en-US").TrString("repo.branch.restore_success", name),
|
|
)
|
|
})
|
|
}
|