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.

67 lines
2.5 KiB

  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. "net/url"
  8. "strings"
  9. "testing"
  10. "code.gitea.io/gitea/models"
  11. "code.gitea.io/gitea/modules/test"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestRepoActivity(t *testing.T) {
  15. onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
  16. session := loginUser(t, "user1")
  17. // Create PRs (1 merged & 2 proposed)
  18. testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
  19. testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n")
  20. resp := testPullCreate(t, session, "user1", "repo1", "master", "This is a pull title")
  21. elem := strings.Split(test.RedirectURL(resp), "/")
  22. assert.EqualValues(t, "pulls", elem[3])
  23. testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleMerge)
  24. testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feat/better_readme", "README.md", "Hello, World (Edited Again)\n")
  25. testPullCreate(t, session, "user1", "repo1", "feat/better_readme", "This is a pull title")
  26. testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feat/much_better_readme", "README.md", "Hello, World (Edited More)\n")
  27. testPullCreate(t, session, "user1", "repo1", "feat/much_better_readme", "This is a pull title")
  28. // Create issues (3 new issues)
  29. testNewIssue(t, session, "user2", "repo1", "Issue 1", "Description 1")
  30. testNewIssue(t, session, "user2", "repo1", "Issue 2", "Description 2")
  31. testNewIssue(t, session, "user2", "repo1", "Issue 3", "Description 3")
  32. // Create releases (1 new release)
  33. createNewRelease(t, session, "/user2/repo1", "v1.0.0", "v1.0.0", false, false)
  34. // Open Activity page and check stats
  35. req := NewRequest(t, "GET", "/user2/repo1/activity")
  36. resp = session.MakeRequest(t, req, http.StatusOK)
  37. htmlDoc := NewHTMLParser(t, resp.Body)
  38. // Should be 1 published release
  39. list := htmlDoc.doc.Find("#published-releases").Next().Find("p.desc")
  40. assert.Len(t, list.Nodes, 1)
  41. // Should be 1 merged pull request
  42. list = htmlDoc.doc.Find("#merged-pull-requests").Next().Find("p.desc")
  43. assert.Len(t, list.Nodes, 1)
  44. // Should be 2 proposed pull requests
  45. list = htmlDoc.doc.Find("#proposed-pull-requests").Next().Find("p.desc")
  46. assert.Len(t, list.Nodes, 2)
  47. // Should be 3 new issues
  48. list = htmlDoc.doc.Find("#new-issues").Next().Find("p.desc")
  49. assert.Len(t, list.Nodes, 3)
  50. })
  51. }