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.

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