forgejo/tests/integration/pull_editable_test.go
Minecon724 5016926d01
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Just merg
2025-03-29 20:14:01 +01:00

54 lines
1.5 KiB
Go

// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package integration
import (
"net/http"
"net/url"
"testing"
auth_model "forgejo.org/models/auth"
api "forgejo.org/modules/structs"
"forgejo.org/tests"
)
func TestPullEditable_ShowEditableLabel(t *testing.T) {
onGiteaRun(t, func(t *testing.T, forgejoURL *url.URL) {
t.Run("Show editable label if PR is editable", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
editable := true
setPREditable(t, editable)
testEditableLabelShown(t, editable)
})
t.Run("Don't show editable label if PR is not editable", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
editable := false
setPREditable(t, editable)
testEditableLabelShown(t, editable)
})
})
}
func setPREditable(t *testing.T, editable bool) {
t.Helper()
session := loginUser(t, "user1")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestWithJSON(t, "PATCH", "/api/v1/repos/user2/repo1/pulls/3", &api.EditPullRequestOption{
AllowMaintainerEdit: &editable,
}).AddTokenAuth(token)
session.MakeRequest(t, req, http.StatusCreated)
}
func testEditableLabelShown(t *testing.T, expectLabel bool) {
t.Helper()
session := loginUser(t, "user2")
req := NewRequest(t, "GET", "/user2/repo1/pulls/3")
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, "#editable-label", expectLabel)
}