2017-04-29 11:22:25 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-04-29 11:22:25 +05:30
|
|
|
|
2022-09-03 00:48:23 +05:30
|
|
|
package integration
|
2017-04-29 11:22:25 +05:30
|
|
|
|
|
|
|
import (
|
2019-09-20 11:15:38 +05:30
|
|
|
"fmt"
|
2017-04-29 11:22:25 +05:30
|
|
|
"net/http"
|
2022-04-08 00:29:56 +05:30
|
|
|
"net/url"
|
2017-06-18 18:55:58 +05:30
|
|
|
"path"
|
2017-06-15 08:39:03 +05:30
|
|
|
"strconv"
|
|
|
|
"strings"
|
2017-04-29 11:22:25 +05:30
|
|
|
"testing"
|
2020-01-07 16:53:09 +05:30
|
|
|
"time"
|
2017-04-29 11:22:25 +05:30
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
2021-12-10 06:57:50 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 14:23:21 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-24 15:19:20 +05:30
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2020-01-07 16:53:09 +05:30
|
|
|
"code.gitea.io/gitea/modules/indexer/issues"
|
2019-10-14 03:59:10 +05:30
|
|
|
"code.gitea.io/gitea/modules/references"
|
2017-06-15 08:39:03 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2022-04-08 00:29:56 +05:30
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2017-12-16 02:41:02 +05:30
|
|
|
"code.gitea.io/gitea/modules/test"
|
2022-09-03 00:48:23 +05:30
|
|
|
"code.gitea.io/gitea/tests"
|
2017-06-15 08:39:03 +05:30
|
|
|
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
2017-04-29 11:22:25 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-09-17 01:46:21 +05:30
|
|
|
func getIssuesSelection(t testing.TB, htmlDoc *HTMLDoc) *goquery.Selection {
|
|
|
|
issueList := htmlDoc.doc.Find(".issue.list")
|
|
|
|
assert.EqualValues(t, 1, issueList.Length())
|
|
|
|
return issueList.Find("li").Find(".title")
|
2017-06-15 08:39:03 +05:30
|
|
|
}
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *issues_model.Issue {
|
2017-06-15 08:39:03 +05:30
|
|
|
href, exists := issueSelection.Attr("href")
|
|
|
|
assert.True(t, exists)
|
|
|
|
indexStr := href[strings.LastIndexByte(href, '/')+1:]
|
|
|
|
index, err := strconv.Atoi(indexStr)
|
|
|
|
assert.NoError(t, err, "Invalid issue href: %s", href)
|
2022-08-16 07:52:25 +05:30
|
|
|
return unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repoID, Index: int64(index)})
|
2017-06-15 08:39:03 +05:30
|
|
|
}
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
func assertMatch(t testing.TB, issue *issues_model.Issue, keyword string) {
|
2017-09-17 01:46:21 +05:30
|
|
|
matches := strings.Contains(strings.ToLower(issue.Title), keyword) ||
|
|
|
|
strings.Contains(strings.ToLower(issue.Content), keyword)
|
|
|
|
for _, comment := range issue.Comments {
|
|
|
|
matches = matches || strings.Contains(
|
|
|
|
strings.ToLower(comment.Content),
|
|
|
|
keyword,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
assert.True(t, matches)
|
|
|
|
}
|
|
|
|
|
2017-05-27 09:04:11 +05:30
|
|
|
func TestNoLoginViewIssues(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-05-27 09:04:11 +05:30
|
|
|
|
2017-06-10 06:11:36 +05:30
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/issues")
|
2017-07-08 01:06:47 +05:30
|
|
|
MakeRequest(t, req, http.StatusOK)
|
2017-05-27 09:04:11 +05:30
|
|
|
}
|
|
|
|
|
2017-09-17 01:46:21 +05:30
|
|
|
func TestViewIssuesSortByType(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-06-15 08:39:03 +05:30
|
|
|
|
2022-08-16 07:52:25 +05:30
|
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
2017-06-15 08:39:03 +05:30
|
|
|
|
2017-06-17 10:19:45 +05:30
|
|
|
session := loginUser(t, user.Name)
|
2021-11-16 23:48:25 +05:30
|
|
|
req := NewRequest(t, "GET", repo.Link()+"/issues?type=created_by")
|
2017-07-08 01:06:47 +05:30
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-15 08:39:03 +05:30
|
|
|
|
2017-06-17 21:59:59 +05:30
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
2017-09-17 01:46:21 +05:30
|
|
|
issuesSelection := getIssuesSelection(t, htmlDoc)
|
2021-11-16 14:23:21 +05:30
|
|
|
expectedNumIssues := unittest.GetCount(t,
|
2022-06-13 15:07:59 +05:30
|
|
|
&issues_model.Issue{RepoID: repo.ID, PosterID: user.ID},
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.Cond("is_closed=?", false),
|
|
|
|
unittest.Cond("is_pull=?", false),
|
2017-06-15 08:39:03 +05:30
|
|
|
)
|
|
|
|
if expectedNumIssues > setting.UI.IssuePagingNum {
|
|
|
|
expectedNumIssues = setting.UI.IssuePagingNum
|
|
|
|
}
|
|
|
|
assert.EqualValues(t, expectedNumIssues, issuesSelection.Length())
|
|
|
|
|
|
|
|
issuesSelection.Each(func(_ int, selection *goquery.Selection) {
|
|
|
|
issue := getIssue(t, repo.ID, selection)
|
|
|
|
assert.EqualValues(t, user.ID, issue.PosterID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-09-17 01:46:21 +05:30
|
|
|
func TestViewIssuesKeyword(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-09-17 01:46:21 +05:30
|
|
|
|
2022-08-16 07:52:25 +05:30
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
2022-06-13 15:07:59 +05:30
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{
|
2020-01-07 16:53:09 +05:30
|
|
|
RepoID: repo.ID,
|
|
|
|
Index: 1,
|
2022-08-16 07:52:25 +05:30
|
|
|
})
|
2020-01-07 16:53:09 +05:30
|
|
|
issues.UpdateIssueIndexer(issue)
|
|
|
|
time.Sleep(time.Second * 1)
|
2017-09-17 01:46:21 +05:30
|
|
|
const keyword = "first"
|
2021-11-16 23:48:25 +05:30
|
|
|
req := NewRequestf(t, "GET", "%s/issues?q=%s", repo.Link(), keyword)
|
2017-09-17 01:46:21 +05:30
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
issuesSelection := getIssuesSelection(t, htmlDoc)
|
|
|
|
assert.EqualValues(t, 1, issuesSelection.Length())
|
|
|
|
issuesSelection.Each(func(_ int, selection *goquery.Selection) {
|
|
|
|
issue := getIssue(t, repo.ID, selection)
|
|
|
|
assert.False(t, issue.IsClosed)
|
|
|
|
assert.False(t, issue.IsPull)
|
|
|
|
assertMatch(t, issue, keyword)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-29 11:22:25 +05:30
|
|
|
func TestNoLoginViewIssue(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-04-29 11:22:25 +05:30
|
|
|
|
2017-06-10 06:11:36 +05:30
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/issues/1")
|
2017-07-08 01:06:47 +05:30
|
|
|
MakeRequest(t, req, http.StatusOK)
|
2017-04-29 11:22:25 +05:30
|
|
|
}
|
2017-06-18 18:55:58 +05:30
|
|
|
|
2017-11-03 14:53:17 +05:30
|
|
|
func testNewIssue(t *testing.T, session *TestSession, user, repo, title, content string) string {
|
2017-06-18 18:55:58 +05:30
|
|
|
req := NewRequest(t, "GET", path.Join(user, repo, "issues", "new"))
|
2017-07-08 01:06:47 +05:30
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-18 18:55:58 +05:30
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
|
|
|
|
assert.True(t, exists, "The template has changed")
|
|
|
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
2017-11-03 14:53:17 +05:30
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"title": title,
|
|
|
|
"content": content,
|
|
|
|
})
|
2023-06-16 12:02:43 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
2017-11-03 14:53:17 +05:30
|
|
|
|
2017-12-16 02:41:02 +05:30
|
|
|
issueURL := test.RedirectURL(resp)
|
2017-11-03 14:53:17 +05:30
|
|
|
req = NewRequest(t, "GET", issueURL)
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
|
|
|
val := htmlDoc.doc.Find("#issue-title").Text()
|
2023-05-04 03:28:59 +05:30
|
|
|
assert.Contains(t, val, title)
|
2020-04-11 03:31:41 +05:30
|
|
|
val = htmlDoc.doc.Find(".comment .render-content p").First().Text()
|
2017-11-03 14:53:17 +05:30
|
|
|
assert.Equal(t, content, val)
|
|
|
|
|
|
|
|
return issueURL
|
|
|
|
}
|
|
|
|
|
2019-09-20 11:15:38 +05:30
|
|
|
func testIssueAddComment(t *testing.T, session *TestSession, issueURL, content, status string) int64 {
|
2017-11-03 14:53:17 +05:30
|
|
|
req := NewRequest(t, "GET", issueURL)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
link, exists := htmlDoc.doc.Find("#comment-form").Attr("action")
|
|
|
|
assert.True(t, exists, "The template has changed")
|
|
|
|
|
2020-04-11 03:31:41 +05:30
|
|
|
commentCount := htmlDoc.doc.Find(".comment-list .comment .render-content").Length()
|
2017-11-03 14:53:17 +05:30
|
|
|
|
|
|
|
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"content": content,
|
|
|
|
"status": status,
|
2017-06-18 18:55:58 +05:30
|
|
|
})
|
2023-06-16 12:02:43 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
2017-07-08 01:06:47 +05:30
|
|
|
|
2017-12-16 02:41:02 +05:30
|
|
|
req = NewRequest(t, "GET", test.RedirectURL(resp))
|
2017-07-08 01:06:47 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
2017-11-03 14:53:17 +05:30
|
|
|
|
|
|
|
htmlDoc = NewHTMLParser(t, resp.Body)
|
|
|
|
|
2020-04-11 03:31:41 +05:30
|
|
|
val := htmlDoc.doc.Find(".comment-list .comment .render-content p").Eq(commentCount).Text()
|
2017-11-03 14:53:17 +05:30
|
|
|
assert.Equal(t, content, val)
|
2019-09-20 11:15:38 +05:30
|
|
|
|
2020-04-11 03:31:41 +05:30
|
|
|
idAttr, has := htmlDoc.doc.Find(".comment-list .comment").Eq(commentCount).Attr("id")
|
2019-09-20 11:15:38 +05:30
|
|
|
idStr := idAttr[strings.LastIndexByte(idAttr, '-')+1:]
|
|
|
|
assert.True(t, has)
|
|
|
|
id, err := strconv.Atoi(idStr)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
return int64(id)
|
2017-06-18 18:55:58 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewIssue(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-06-18 18:55:58 +05:30
|
|
|
session := loginUser(t, "user2")
|
2017-11-03 14:53:17 +05:30
|
|
|
testNewIssue(t, session, "user2", "repo1", "Title", "Description")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIssueCommentClose(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2017-11-03 14:53:17 +05:30
|
|
|
session := loginUser(t, "user2")
|
|
|
|
issueURL := testNewIssue(t, session, "user2", "repo1", "Title", "Description")
|
|
|
|
testIssueAddComment(t, session, issueURL, "Test comment 1", "")
|
|
|
|
testIssueAddComment(t, session, issueURL, "Test comment 2", "")
|
|
|
|
testIssueAddComment(t, session, issueURL, "Test comment 3", "close")
|
|
|
|
|
|
|
|
// Validate that issue content has not been updated
|
|
|
|
req := NewRequest(t, "GET", issueURL)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
2020-04-11 03:31:41 +05:30
|
|
|
val := htmlDoc.doc.Find(".comment-list .comment .render-content p").First().Text()
|
2017-11-03 14:53:17 +05:30
|
|
|
assert.Equal(t, "Description", val)
|
2017-06-18 18:55:58 +05:30
|
|
|
}
|
2019-09-20 11:15:38 +05:30
|
|
|
|
2019-12-02 04:27:24 +05:30
|
|
|
func TestIssueReaction(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2019-12-02 04:27:24 +05:30
|
|
|
session := loginUser(t, "user2")
|
|
|
|
issueURL := testNewIssue(t, session, "user2", "repo1", "Title", "Description")
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", issueURL)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
|
|
|
|
req = NewRequestWithValues(t, "POST", path.Join(issueURL, "/reactions/react"), map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"content": "8ball",
|
|
|
|
})
|
|
|
|
session.MakeRequest(t, req, http.StatusInternalServerError)
|
|
|
|
req = NewRequestWithValues(t, "POST", path.Join(issueURL, "/reactions/react"), map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"content": "eyes",
|
|
|
|
})
|
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
req = NewRequestWithValues(t, "POST", path.Join(issueURL, "/reactions/unreact"), map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"content": "eyes",
|
|
|
|
})
|
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2019-09-20 11:15:38 +05:30
|
|
|
func TestIssueCrossReference(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2019-09-20 11:15:38 +05:30
|
|
|
|
|
|
|
// Issue that will be referenced
|
|
|
|
_, issueBase := testIssueWithBean(t, "user2", 1, "Title", "Description")
|
|
|
|
|
|
|
|
// Ref from issue title
|
|
|
|
issueRefURL, issueRef := testIssueWithBean(t, "user2", 1, fmt.Sprintf("Title ref #%d", issueBase.Index), "Description")
|
2022-06-13 15:07:59 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{
|
2019-09-20 11:15:38 +05:30
|
|
|
IssueID: issueBase.ID,
|
|
|
|
RefRepoID: 1,
|
|
|
|
RefIssueID: issueRef.ID,
|
|
|
|
RefCommentID: 0,
|
|
|
|
RefIsPull: false,
|
2022-01-20 23:16:10 +05:30
|
|
|
RefAction: references.XRefActionNone,
|
|
|
|
})
|
2019-09-20 11:15:38 +05:30
|
|
|
|
|
|
|
// Edit title, neuter ref
|
|
|
|
testIssueChangeInfo(t, "user2", issueRefURL, "title", "Title no ref")
|
2022-06-13 15:07:59 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{
|
2019-09-20 11:15:38 +05:30
|
|
|
IssueID: issueBase.ID,
|
|
|
|
RefRepoID: 1,
|
|
|
|
RefIssueID: issueRef.ID,
|
|
|
|
RefCommentID: 0,
|
|
|
|
RefIsPull: false,
|
2022-01-20 23:16:10 +05:30
|
|
|
RefAction: references.XRefActionNeutered,
|
|
|
|
})
|
2019-09-20 11:15:38 +05:30
|
|
|
|
|
|
|
// Ref from issue content
|
|
|
|
issueRefURL, issueRef = testIssueWithBean(t, "user2", 1, "TitleXRef", fmt.Sprintf("Description ref #%d", issueBase.Index))
|
2022-06-13 15:07:59 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{
|
2019-09-20 11:15:38 +05:30
|
|
|
IssueID: issueBase.ID,
|
|
|
|
RefRepoID: 1,
|
|
|
|
RefIssueID: issueRef.ID,
|
|
|
|
RefCommentID: 0,
|
|
|
|
RefIsPull: false,
|
2022-01-20 23:16:10 +05:30
|
|
|
RefAction: references.XRefActionNone,
|
|
|
|
})
|
2019-09-20 11:15:38 +05:30
|
|
|
|
|
|
|
// Edit content, neuter ref
|
|
|
|
testIssueChangeInfo(t, "user2", issueRefURL, "content", "Description no ref")
|
2022-06-13 15:07:59 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{
|
2019-09-20 11:15:38 +05:30
|
|
|
IssueID: issueBase.ID,
|
|
|
|
RefRepoID: 1,
|
|
|
|
RefIssueID: issueRef.ID,
|
|
|
|
RefCommentID: 0,
|
|
|
|
RefIsPull: false,
|
2022-01-20 23:16:10 +05:30
|
|
|
RefAction: references.XRefActionNeutered,
|
|
|
|
})
|
2019-09-20 11:15:38 +05:30
|
|
|
|
|
|
|
// Ref from a comment
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
commentID := testIssueAddComment(t, session, issueRefURL, fmt.Sprintf("Adding ref from comment #%d", issueBase.Index), "")
|
2022-06-13 15:07:59 +05:30
|
|
|
comment := &issues_model.Comment{
|
2019-09-20 11:15:38 +05:30
|
|
|
IssueID: issueBase.ID,
|
|
|
|
RefRepoID: 1,
|
|
|
|
RefIssueID: issueRef.ID,
|
|
|
|
RefCommentID: commentID,
|
|
|
|
RefIsPull: false,
|
2022-01-20 23:16:10 +05:30
|
|
|
RefAction: references.XRefActionNone,
|
|
|
|
}
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, comment)
|
2019-09-20 11:15:38 +05:30
|
|
|
|
|
|
|
// Ref from a different repository
|
2021-11-18 07:03:06 +05:30
|
|
|
_, issueRef = testIssueWithBean(t, "user12", 10, "TitleXRef", fmt.Sprintf("Description ref user2/repo1#%d", issueBase.Index))
|
2022-06-13 15:07:59 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{
|
2019-09-20 11:15:38 +05:30
|
|
|
IssueID: issueBase.ID,
|
|
|
|
RefRepoID: 10,
|
|
|
|
RefIssueID: issueRef.ID,
|
|
|
|
RefCommentID: 0,
|
|
|
|
RefIsPull: false,
|
2022-01-20 23:16:10 +05:30
|
|
|
RefAction: references.XRefActionNone,
|
|
|
|
})
|
2019-09-20 11:15:38 +05:30
|
|
|
}
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
func testIssueWithBean(t *testing.T, user string, repoID int64, title, content string) (string, *issues_model.Issue) {
|
2019-09-20 11:15:38 +05:30
|
|
|
session := loginUser(t, user)
|
|
|
|
issueURL := testNewIssue(t, session, user, fmt.Sprintf("repo%d", repoID), title, content)
|
|
|
|
indexStr := issueURL[strings.LastIndexByte(issueURL, '/')+1:]
|
|
|
|
index, err := strconv.Atoi(indexStr)
|
|
|
|
assert.NoError(t, err, "Invalid issue href: %s", issueURL)
|
2022-06-13 15:07:59 +05:30
|
|
|
issue := &issues_model.Issue{RepoID: repoID, Index: int64(index)}
|
2021-11-16 14:23:21 +05:30
|
|
|
unittest.AssertExistsAndLoadBean(t, issue)
|
2019-09-20 11:15:38 +05:30
|
|
|
return issueURL, issue
|
|
|
|
}
|
|
|
|
|
2021-12-20 10:11:31 +05:30
|
|
|
func testIssueChangeInfo(t *testing.T, user, issueURL, info, value string) {
|
2019-09-20 11:15:38 +05:30
|
|
|
session := loginUser(t, user)
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", issueURL)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
|
|
|
|
req = NewRequestWithValues(t, "POST", path.Join(issueURL, info), map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
info: value,
|
|
|
|
})
|
|
|
|
_ = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
}
|
2019-12-07 09:51:18 +05:30
|
|
|
|
|
|
|
func TestIssueRedirect(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2019-12-07 09:51:18 +05:30
|
|
|
session := loginUser(t, "user2")
|
|
|
|
|
|
|
|
// Test external tracker where style not set (shall default numeric)
|
|
|
|
req := NewRequest(t, "GET", path.Join("org26", "repo_external_tracker", "issues", "1"))
|
2022-03-23 10:24:07 +05:30
|
|
|
resp := session.MakeRequest(t, req, http.StatusSeeOther)
|
2019-12-07 09:51:18 +05:30
|
|
|
assert.Equal(t, "https://tracker.com/org26/repo_external_tracker/issues/1", test.RedirectURL(resp))
|
|
|
|
|
|
|
|
// Test external tracker with numeric style
|
|
|
|
req = NewRequest(t, "GET", path.Join("org26", "repo_external_tracker_numeric", "issues", "1"))
|
2022-03-23 10:24:07 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
2019-12-07 09:51:18 +05:30
|
|
|
assert.Equal(t, "https://tracker.com/org26/repo_external_tracker_numeric/issues/1", test.RedirectURL(resp))
|
|
|
|
|
|
|
|
// Test external tracker with alphanumeric style (for a pull request)
|
|
|
|
req = NewRequest(t, "GET", path.Join("org26", "repo_external_tracker_alpha", "issues", "1"))
|
2022-03-23 10:24:07 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
2019-12-07 09:51:18 +05:30
|
|
|
assert.Equal(t, "/"+path.Join("org26", "repo_external_tracker_alpha", "pulls", "1"), test.RedirectURL(resp))
|
|
|
|
}
|
2022-04-08 00:29:56 +05:30
|
|
|
|
|
|
|
func TestSearchIssues(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-04-08 00:29:56 +05:30
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
|
Scoped labels (#22585)
Add a new "exclusive" option per label. This makes it so that when the
label is named `scope/name`, no other label with the same `scope/`
prefix can be set on an issue.
The scope is determined by the last occurence of `/`, so for example
`scope/alpha/name` and `scope/beta/name` are considered to be in
different scopes and can coexist.
Exclusive scopes are not enforced by any database rules, however they
are enforced when editing labels at the models level, automatically
removing any existing labels in the same scope when either attaching a
new label or replacing all labels.
In menus use a circle instead of checkbox to indicate they function as
radio buttons per scope. Issue filtering by label ensures that only a
single scoped label is selected at a time. Clicking with alt key can be
used to remove a scoped label, both when editing individual issues and
batch editing.
Label rendering refactor for consistency and code simplification:
* Labels now consistently have the same shape, emojis and tooltips
everywhere. This includes the label list and label assignment menus.
* In label list, show description below label same as label menus.
* Don't use exactly black/white text colors to look a bit nicer.
* Simplify text color computation. There is no point computing luminance
in linear color space, as this is a perceptual problem and sRGB is
closer to perceptually linear.
* Increase height of label assignment menus to show more labels. Showing
only 3-4 labels at a time leads to a lot of scrolling.
* Render all labels with a new RenderLabel template helper function.
Label creation and editing in multiline modal menu:
* Change label creation to open a modal menu like label editing.
* Change menu layout to place name, description and colors on separate
lines.
* Don't color cancel button red in label editing modal menu.
* Align text to the left in model menu for better readability and
consistent with settings layout elsewhere.
Custom exclusive scoped label rendering:
* Display scoped label prefix and suffix with slightly darker and
lighter background color respectively, and a slanted edge between them
similar to the `/` symbol.
* In menus exclusive labels are grouped with a divider line.
---------
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
2023-02-19 00:47:39 +05:30
|
|
|
expectedIssueCount := 16 // from the fixtures
|
2022-08-06 16:13:40 +05:30
|
|
|
if expectedIssueCount > setting.UI.IssuePagingNum {
|
|
|
|
expectedIssueCount = setting.UI.IssuePagingNum
|
|
|
|
}
|
|
|
|
|
2022-04-08 00:29:56 +05:30
|
|
|
link, _ := url.Parse("/issues/search")
|
|
|
|
req := NewRequest(t, "GET", link.String())
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var apiIssues []*api.Issue
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2022-08-06 16:13:40 +05:30
|
|
|
assert.Len(t, apiIssues, expectedIssueCount)
|
2022-04-08 00:29:56 +05:30
|
|
|
|
|
|
|
since := "2000-01-01T00%3A50%3A01%2B00%3A00" // 946687801
|
|
|
|
before := time.Unix(999307200, 0).Format(time.RFC3339)
|
|
|
|
query := url.Values{}
|
|
|
|
query.Add("since", since)
|
|
|
|
query.Add("before", before)
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
Scoped labels (#22585)
Add a new "exclusive" option per label. This makes it so that when the
label is named `scope/name`, no other label with the same `scope/`
prefix can be set on an issue.
The scope is determined by the last occurence of `/`, so for example
`scope/alpha/name` and `scope/beta/name` are considered to be in
different scopes and can coexist.
Exclusive scopes are not enforced by any database rules, however they
are enforced when editing labels at the models level, automatically
removing any existing labels in the same scope when either attaching a
new label or replacing all labels.
In menus use a circle instead of checkbox to indicate they function as
radio buttons per scope. Issue filtering by label ensures that only a
single scoped label is selected at a time. Clicking with alt key can be
used to remove a scoped label, both when editing individual issues and
batch editing.
Label rendering refactor for consistency and code simplification:
* Labels now consistently have the same shape, emojis and tooltips
everywhere. This includes the label list and label assignment menus.
* In label list, show description below label same as label menus.
* Don't use exactly black/white text colors to look a bit nicer.
* Simplify text color computation. There is no point computing luminance
in linear color space, as this is a perceptual problem and sRGB is
closer to perceptually linear.
* Increase height of label assignment menus to show more labels. Showing
only 3-4 labels at a time leads to a lot of scrolling.
* Render all labels with a new RenderLabel template helper function.
Label creation and editing in multiline modal menu:
* Change label creation to open a modal menu like label editing.
* Change menu layout to place name, description and colors on separate
lines.
* Don't color cancel button red in label editing modal menu.
* Align text to the left in model menu for better readability and
consistent with settings layout elsewhere.
Custom exclusive scoped label rendering:
* Display scoped label prefix and suffix with slightly darker and
lighter background color respectively, and a slanted edge between them
similar to the `/` symbol.
* In menus exclusive labels are grouped with a divider line.
---------
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
2023-02-19 00:47:39 +05:30
|
|
|
assert.Len(t, apiIssues, 9)
|
2022-04-08 00:29:56 +05:30
|
|
|
query.Del("since")
|
|
|
|
query.Del("before")
|
|
|
|
|
|
|
|
query.Add("state", "closed")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
query.Set("state", "all")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
Scoped labels (#22585)
Add a new "exclusive" option per label. This makes it so that when the
label is named `scope/name`, no other label with the same `scope/`
prefix can be set on an issue.
The scope is determined by the last occurence of `/`, so for example
`scope/alpha/name` and `scope/beta/name` are considered to be in
different scopes and can coexist.
Exclusive scopes are not enforced by any database rules, however they
are enforced when editing labels at the models level, automatically
removing any existing labels in the same scope when either attaching a
new label or replacing all labels.
In menus use a circle instead of checkbox to indicate they function as
radio buttons per scope. Issue filtering by label ensures that only a
single scoped label is selected at a time. Clicking with alt key can be
used to remove a scoped label, both when editing individual issues and
batch editing.
Label rendering refactor for consistency and code simplification:
* Labels now consistently have the same shape, emojis and tooltips
everywhere. This includes the label list and label assignment menus.
* In label list, show description below label same as label menus.
* Don't use exactly black/white text colors to look a bit nicer.
* Simplify text color computation. There is no point computing luminance
in linear color space, as this is a perceptual problem and sRGB is
closer to perceptually linear.
* Increase height of label assignment menus to show more labels. Showing
only 3-4 labels at a time leads to a lot of scrolling.
* Render all labels with a new RenderLabel template helper function.
Label creation and editing in multiline modal menu:
* Change label creation to open a modal menu like label editing.
* Change menu layout to place name, description and colors on separate
lines.
* Don't color cancel button red in label editing modal menu.
* Align text to the left in model menu for better readability and
consistent with settings layout elsewhere.
Custom exclusive scoped label rendering:
* Display scoped label prefix and suffix with slightly darker and
lighter background color respectively, and a slanted edge between them
similar to the `/` symbol.
* In menus exclusive labels are grouped with a divider line.
---------
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
2023-02-19 00:47:39 +05:30
|
|
|
assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count"))
|
|
|
|
assert.Len(t, apiIssues, 18)
|
2022-04-08 00:29:56 +05:30
|
|
|
|
2022-08-06 16:13:40 +05:30
|
|
|
query.Add("limit", "5")
|
2022-04-08 00:29:56 +05:30
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
Scoped labels (#22585)
Add a new "exclusive" option per label. This makes it so that when the
label is named `scope/name`, no other label with the same `scope/`
prefix can be set on an issue.
The scope is determined by the last occurence of `/`, so for example
`scope/alpha/name` and `scope/beta/name` are considered to be in
different scopes and can coexist.
Exclusive scopes are not enforced by any database rules, however they
are enforced when editing labels at the models level, automatically
removing any existing labels in the same scope when either attaching a
new label or replacing all labels.
In menus use a circle instead of checkbox to indicate they function as
radio buttons per scope. Issue filtering by label ensures that only a
single scoped label is selected at a time. Clicking with alt key can be
used to remove a scoped label, both when editing individual issues and
batch editing.
Label rendering refactor for consistency and code simplification:
* Labels now consistently have the same shape, emojis and tooltips
everywhere. This includes the label list and label assignment menus.
* In label list, show description below label same as label menus.
* Don't use exactly black/white text colors to look a bit nicer.
* Simplify text color computation. There is no point computing luminance
in linear color space, as this is a perceptual problem and sRGB is
closer to perceptually linear.
* Increase height of label assignment menus to show more labels. Showing
only 3-4 labels at a time leads to a lot of scrolling.
* Render all labels with a new RenderLabel template helper function.
Label creation and editing in multiline modal menu:
* Change label creation to open a modal menu like label editing.
* Change menu layout to place name, description and colors on separate
lines.
* Don't color cancel button red in label editing modal menu.
* Align text to the left in model menu for better readability and
consistent with settings layout elsewhere.
Custom exclusive scoped label rendering:
* Display scoped label prefix and suffix with slightly darker and
lighter background color respectively, and a slanted edge between them
similar to the `/` symbol.
* In menus exclusive labels are grouped with a divider line.
---------
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
2023-02-19 00:47:39 +05:30
|
|
|
assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count"))
|
2022-08-06 16:13:40 +05:30
|
|
|
assert.Len(t, apiIssues, 5)
|
2022-04-08 00:29:56 +05:30
|
|
|
|
|
|
|
query = url.Values{"assigned": {"true"}, "state": {"all"}}
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2022-05-16 15:19:17 +05:30
|
|
|
assert.Len(t, apiIssues, 2)
|
2022-04-08 00:29:56 +05:30
|
|
|
|
|
|
|
query = url.Values{"milestones": {"milestone1"}, "state": {"all"}}
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 1)
|
|
|
|
|
|
|
|
query = url.Values{"milestones": {"milestone1,milestone3"}, "state": {"all"}}
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
query = url.Values{"owner": {"user2"}} // user
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
Scoped labels (#22585)
Add a new "exclusive" option per label. This makes it so that when the
label is named `scope/name`, no other label with the same `scope/`
prefix can be set on an issue.
The scope is determined by the last occurence of `/`, so for example
`scope/alpha/name` and `scope/beta/name` are considered to be in
different scopes and can coexist.
Exclusive scopes are not enforced by any database rules, however they
are enforced when editing labels at the models level, automatically
removing any existing labels in the same scope when either attaching a
new label or replacing all labels.
In menus use a circle instead of checkbox to indicate they function as
radio buttons per scope. Issue filtering by label ensures that only a
single scoped label is selected at a time. Clicking with alt key can be
used to remove a scoped label, both when editing individual issues and
batch editing.
Label rendering refactor for consistency and code simplification:
* Labels now consistently have the same shape, emojis and tooltips
everywhere. This includes the label list and label assignment menus.
* In label list, show description below label same as label menus.
* Don't use exactly black/white text colors to look a bit nicer.
* Simplify text color computation. There is no point computing luminance
in linear color space, as this is a perceptual problem and sRGB is
closer to perceptually linear.
* Increase height of label assignment menus to show more labels. Showing
only 3-4 labels at a time leads to a lot of scrolling.
* Render all labels with a new RenderLabel template helper function.
Label creation and editing in multiline modal menu:
* Change label creation to open a modal menu like label editing.
* Change menu layout to place name, description and colors on separate
lines.
* Don't color cancel button red in label editing modal menu.
* Align text to the left in model menu for better readability and
consistent with settings layout elsewhere.
Custom exclusive scoped label rendering:
* Display scoped label prefix and suffix with slightly darker and
lighter background color respectively, and a slanted edge between them
similar to the `/` symbol.
* In menus exclusive labels are grouped with a divider line.
---------
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
2023-02-19 00:47:39 +05:30
|
|
|
assert.Len(t, apiIssues, 7)
|
2022-04-08 00:29:56 +05:30
|
|
|
|
|
|
|
query = url.Values{"owner": {"user3"}} // organization
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2022-05-16 15:19:17 +05:30
|
|
|
assert.Len(t, apiIssues, 5)
|
2022-04-08 00:29:56 +05:30
|
|
|
|
|
|
|
query = url.Values{"owner": {"user3"}, "team": {"team1"}} // organization + team
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSearchIssuesWithLabels(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-04-08 00:29:56 +05:30
|
|
|
|
Scoped labels (#22585)
Add a new "exclusive" option per label. This makes it so that when the
label is named `scope/name`, no other label with the same `scope/`
prefix can be set on an issue.
The scope is determined by the last occurence of `/`, so for example
`scope/alpha/name` and `scope/beta/name` are considered to be in
different scopes and can coexist.
Exclusive scopes are not enforced by any database rules, however they
are enforced when editing labels at the models level, automatically
removing any existing labels in the same scope when either attaching a
new label or replacing all labels.
In menus use a circle instead of checkbox to indicate they function as
radio buttons per scope. Issue filtering by label ensures that only a
single scoped label is selected at a time. Clicking with alt key can be
used to remove a scoped label, both when editing individual issues and
batch editing.
Label rendering refactor for consistency and code simplification:
* Labels now consistently have the same shape, emojis and tooltips
everywhere. This includes the label list and label assignment menus.
* In label list, show description below label same as label menus.
* Don't use exactly black/white text colors to look a bit nicer.
* Simplify text color computation. There is no point computing luminance
in linear color space, as this is a perceptual problem and sRGB is
closer to perceptually linear.
* Increase height of label assignment menus to show more labels. Showing
only 3-4 labels at a time leads to a lot of scrolling.
* Render all labels with a new RenderLabel template helper function.
Label creation and editing in multiline modal menu:
* Change label creation to open a modal menu like label editing.
* Change menu layout to place name, description and colors on separate
lines.
* Don't color cancel button red in label editing modal menu.
* Align text to the left in model menu for better readability and
consistent with settings layout elsewhere.
Custom exclusive scoped label rendering:
* Display scoped label prefix and suffix with slightly darker and
lighter background color respectively, and a slanted edge between them
similar to the `/` symbol.
* In menus exclusive labels are grouped with a divider line.
---------
Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
2023-02-19 00:47:39 +05:30
|
|
|
expectedIssueCount := 16 // from the fixtures
|
2022-08-06 16:13:40 +05:30
|
|
|
if expectedIssueCount > setting.UI.IssuePagingNum {
|
|
|
|
expectedIssueCount = setting.UI.IssuePagingNum
|
|
|
|
}
|
2022-04-08 00:29:56 +05:30
|
|
|
|
2022-08-06 16:13:40 +05:30
|
|
|
session := loginUser(t, "user1")
|
|
|
|
link, _ := url.Parse("/issues/search")
|
|
|
|
query := url.Values{}
|
2022-04-08 00:29:56 +05:30
|
|
|
var apiIssues []*api.Issue
|
|
|
|
|
|
|
|
link.RawQuery = query.Encode()
|
2022-08-06 16:13:40 +05:30
|
|
|
req := NewRequest(t, "GET", link.String())
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2022-04-08 00:29:56 +05:30
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
2022-08-06 16:13:40 +05:30
|
|
|
assert.Len(t, apiIssues, expectedIssueCount)
|
2022-04-08 00:29:56 +05:30
|
|
|
|
|
|
|
query.Add("labels", "label1")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
2022-08-06 16:13:40 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
2022-04-08 00:29:56 +05:30
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
// multiple labels
|
|
|
|
query.Set("labels", "label1,label2")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
2022-08-06 16:13:40 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
2022-04-08 00:29:56 +05:30
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
// an org label
|
|
|
|
query.Set("labels", "orglabel4")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
2022-08-06 16:13:40 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
2022-04-08 00:29:56 +05:30
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 1)
|
|
|
|
|
|
|
|
// org and repo label
|
|
|
|
query.Set("labels", "label2,orglabel4")
|
|
|
|
query.Add("state", "all")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
2022-08-06 16:13:40 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
2022-04-08 00:29:56 +05:30
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
|
|
|
|
// org and repo label which share the same issue
|
|
|
|
query.Set("labels", "label1,orglabel4")
|
|
|
|
link.RawQuery = query.Encode()
|
|
|
|
req = NewRequest(t, "GET", link.String())
|
2022-08-06 16:13:40 +05:30
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK)
|
2022-04-08 00:29:56 +05:30
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetIssueInfo(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-04-08 00:29:56 +05:30
|
|
|
|
2022-08-16 07:52:25 +05:30
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 10})
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, issue.LoadAttributes(db.DefaultContext))
|
2022-04-08 00:29:56 +05:30
|
|
|
assert.Equal(t, int64(1019307200), int64(issue.DeadlineUnix))
|
|
|
|
assert.Equal(t, api.StateOpen, issue.State())
|
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
|
|
|
|
|
|
|
urlStr := fmt.Sprintf("/%s/%s/issues/%d/info", owner.Name, repo.Name, issue.Index)
|
|
|
|
req := NewRequest(t, "GET", urlStr)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var apiIssue api.Issue
|
|
|
|
DecodeJSON(t, resp, &apiIssue)
|
|
|
|
|
|
|
|
assert.EqualValues(t, issue.ID, apiIssue.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateIssueDeadline(t *testing.T) {
|
2022-09-03 00:48:23 +05:30
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-04-08 00:29:56 +05:30
|
|
|
|
2022-08-16 07:52:25 +05:30
|
|
|
issueBefore := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 10})
|
|
|
|
repoBefore := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issueBefore.RepoID})
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repoBefore.OwnerID})
|
2022-06-13 15:07:59 +05:30
|
|
|
assert.NoError(t, issueBefore.LoadAttributes(db.DefaultContext))
|
2022-04-08 00:29:56 +05:30
|
|
|
assert.Equal(t, int64(1019307200), int64(issueBefore.DeadlineUnix))
|
|
|
|
assert.Equal(t, api.StateOpen, issueBefore.State())
|
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
|
|
|
|
|
|
|
issueURL := fmt.Sprintf("%s/%s/issues/%d", owner.Name, repoBefore.Name, issueBefore.Index)
|
|
|
|
req := NewRequest(t, "GET", issueURL)
|
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
|
|
|
|
urlStr := issueURL + "/deadline?_csrf=" + htmlDoc.GetCSRF()
|
|
|
|
req = NewRequestWithJSON(t, "POST", urlStr, map[string]string{
|
|
|
|
"due_date": "2022-04-06T00:00:00.000Z",
|
|
|
|
})
|
|
|
|
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusCreated)
|
|
|
|
var apiIssue api.IssueDeadline
|
|
|
|
DecodeJSON(t, resp, &apiIssue)
|
|
|
|
|
|
|
|
assert.EqualValues(t, "2022-04-06", apiIssue.Deadline.Format("2006-01-02"))
|
|
|
|
}
|