Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

issue_test.go 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "net/http"
  7. "strconv"
  8. "strings"
  9. "testing"
  10. "code.gitea.io/gitea/models"
  11. "code.gitea.io/gitea/modules/setting"
  12. "github.com/PuerkitoBio/goquery"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func getIssuesSelection(htmlDoc *HTMLDoc) *goquery.Selection {
  16. return htmlDoc.doc.Find(".issue.list").Find("li").Find(".title")
  17. }
  18. func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *models.Issue {
  19. href, exists := issueSelection.Attr("href")
  20. assert.True(t, exists)
  21. indexStr := href[strings.LastIndexByte(href, '/')+1:]
  22. index, err := strconv.Atoi(indexStr)
  23. assert.NoError(t, err, "Invalid issue href: %s", href)
  24. return models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repoID, Index: int64(index)}).(*models.Issue)
  25. }
  26. func TestNoLoginViewIssues(t *testing.T) {
  27. prepareTestEnv(t)
  28. req := NewRequest(t, "GET", "/user2/repo1/issues")
  29. resp := MakeRequest(req)
  30. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  31. }
  32. func TestNoLoginViewIssuesSortByType(t *testing.T) {
  33. prepareTestEnv(t)
  34. user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
  35. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  36. repo.Owner = models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  37. session := loginUser(t, user.Name)
  38. req := NewRequest(t, "GET", repo.RelLink()+"/issues?type=created_by")
  39. resp := session.MakeRequest(t, req)
  40. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  41. htmlDoc := NewHTMLParser(t, resp.Body)
  42. issuesSelection := getIssuesSelection(htmlDoc)
  43. expectedNumIssues := models.GetCount(t,
  44. &models.Issue{RepoID: repo.ID, PosterID: user.ID},
  45. models.Cond("is_closed=?", false),
  46. models.Cond("is_pull=?", false),
  47. )
  48. if expectedNumIssues > setting.UI.IssuePagingNum {
  49. expectedNumIssues = setting.UI.IssuePagingNum
  50. }
  51. assert.EqualValues(t, expectedNumIssues, issuesSelection.Length())
  52. issuesSelection.Each(func(_ int, selection *goquery.Selection) {
  53. issue := getIssue(t, repo.ID, selection)
  54. assert.EqualValues(t, user.ID, issue.PosterID)
  55. })
  56. }
  57. func TestNoLoginViewIssue(t *testing.T) {
  58. prepareTestEnv(t)
  59. req := NewRequest(t, "GET", "/user2/repo1/issues/1")
  60. resp := MakeRequest(req)
  61. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  62. }