You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.0 KiB
77 lines
2.0 KiB
7 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
2 years ago
|
package integration
|
||
7 years ago
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/modules/translation"
|
||
2 years ago
|
"code.gitea.io/gitea/tests"
|
||
3 years ago
|
|
||
7 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestViewBranches(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
7 years ago
|
|
||
|
req := NewRequest(t, "GET", "/user2/repo1/branches")
|
||
|
resp := MakeRequest(t, req, http.StatusOK)
|
||
|
|
||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||
|
_, exists := htmlDoc.doc.Find(".delete-branch-button").Attr("data-url")
|
||
|
assert.False(t, exists, "The template has changed")
|
||
|
}
|
||
|
|
||
|
func TestDeleteBranch(t *testing.T) {
|
||
2 years ago
|
defer tests.PrepareTestEnv(t)()
|
||
7 years ago
|
|
||
|
deleteBranch(t)
|
||
|
}
|
||
|
|
||
|
func TestUndoDeleteBranch(t *testing.T) {
|
||
5 years ago
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||
|
deleteBranch(t)
|
||
|
htmlDoc, name := branchAction(t, ".undo-button")
|
||
|
assert.Contains(t,
|
||
|
htmlDoc.doc.Find(".ui.positive.message").Text(),
|
||
3 years ago
|
translation.NewLocale("en-US").Tr("repo.branch.restore_success", name),
|
||
5 years ago
|
)
|
||
|
})
|
||
7 years ago
|
}
|
||
|
|
||
|
func deleteBranch(t *testing.T) {
|
||
|
htmlDoc, name := branchAction(t, ".delete-branch-button")
|
||
|
assert.Contains(t,
|
||
|
htmlDoc.doc.Find(".ui.positive.message").Text(),
|
||
3 years ago
|
translation.NewLocale("en-US").Tr("repo.branch.deletion_success", name),
|
||
7 years ago
|
)
|
||
|
}
|
||
|
|
||
|
func branchAction(t *testing.T, button 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("data-url")
|
||
4 years ago
|
if !assert.True(t, exists, "The template has changed") {
|
||
|
t.Skip()
|
||
|
}
|
||
7 years ago
|
|
||
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||
3 years ago
|
"_csrf": htmlDoc.GetCSRF(),
|
||
7 years ago
|
})
|
||
6 years ago
|
session.MakeRequest(t, req, http.StatusOK)
|
||
7 years ago
|
|
||
|
url, err := url.Parse(link)
|
||
|
assert.NoError(t, err)
|
||
|
req = NewRequest(t, "GET", "/user2/repo1/branches")
|
||
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
||
|
|
||
4 years ago
|
return NewHTMLParser(t, resp.Body), url.Query().Get("name")
|
||
7 years ago
|
}
|