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.

links_test.go 4.4KB

[UI] IssuePage multi repo select (#8741) * Make repository list @ issues/PR page persist Will partially fix #6355 * Enable multiple selections in repo list @ issues/PR page Part of issue #6355 * Add RepoIDs to UserIssueStatsOptions to make "type" count correct when selecting one/multiple repos. * Replace variable "repo" with list "repos[]" and enable multiple selections of repositories from list by including/excluding RepoIDs in list. * * Remove redundant code * Add 'All' button Improves functionality of the page, so that backtracking is not necessary to reset the page * Remove redundant variable Completely replace 'RepoID' with 'RepoIDs' and remove redundant code * Add RepoIDs to label link * Revert part of code to previous version to troubleshoot build failure * Implement old and new pieces of code whilst adhering to multi select * Attempt to join the two versions Last commit passed tests but doesn't work in practice, this works in practice and hopefully passes the tests. * Update tests to desired state * Fix pagination implementation and tests * Pass repoIDs as `repos=[1,2,3...]` instead of several `repos[]=..` * Update tests file to reflect new functionality * Update template with new `repos` format * Implement new solution to show constant "total issues" count for "All" button * Correct behavior when passing zero to array * Comment out test url returning 404 This keeps returning 404 in the test despite working in practice, for the sake of running more tests I am commenting it out * Comment out another test url returning 404 Last attempt, if more tests crash I will uncomment the urls and request assistance. * Reenable tests and test fix * Re-enable tests * Make selecting "In your repositories" reset selection as passing IDs of repos belonging to other profiles causes breakage * Remove unnecessary (with multi-selection enable) code * Drop repo from repo map and total count if permission denied * Remove extra parenthesis * make template work again * find bug! * forgot the '#' at bugfixing * delete unused RepoID * compile regex only one time * make fmt * local variable = capital letter lower * check if repos query pattern is correct * pagination remove last , - make regex work again * use Replace instead of ReplaceAll; del delete * fix test * how did this test binary got in?!? dont forgot the "-p" at git add * ! * dont replace -> cut fisrt & last string Co-Authored-By: zeripath <art27@cantab.net> * jet another regex dont mind as long as it has the same result and is performatn ... Co-Authored-By: zeripath <art27@cantab.net> * dont use nonexisting repo for test * exclude /issues?type=created_by from test * add table to querys use same syntax in each query (table.colum) * add new issue for test * dont make a workaround or something else this need a refactor itself and is out of scope for this PR * fix misspell * CI.redo() * englisch txt update Co-Authored-By: zeripath <art27@cantab.net> * add sugestions * Tweak & Fix * CI.restart()
4 years ago
[UI] IssuePage multi repo select (#8741) * Make repository list @ issues/PR page persist Will partially fix #6355 * Enable multiple selections in repo list @ issues/PR page Part of issue #6355 * Add RepoIDs to UserIssueStatsOptions to make "type" count correct when selecting one/multiple repos. * Replace variable "repo" with list "repos[]" and enable multiple selections of repositories from list by including/excluding RepoIDs in list. * * Remove redundant code * Add 'All' button Improves functionality of the page, so that backtracking is not necessary to reset the page * Remove redundant variable Completely replace 'RepoID' with 'RepoIDs' and remove redundant code * Add RepoIDs to label link * Revert part of code to previous version to troubleshoot build failure * Implement old and new pieces of code whilst adhering to multi select * Attempt to join the two versions Last commit passed tests but doesn't work in practice, this works in practice and hopefully passes the tests. * Update tests to desired state * Fix pagination implementation and tests * Pass repoIDs as `repos=[1,2,3...]` instead of several `repos[]=..` * Update tests file to reflect new functionality * Update template with new `repos` format * Implement new solution to show constant "total issues" count for "All" button * Correct behavior when passing zero to array * Comment out test url returning 404 This keeps returning 404 in the test despite working in practice, for the sake of running more tests I am commenting it out * Comment out another test url returning 404 Last attempt, if more tests crash I will uncomment the urls and request assistance. * Reenable tests and test fix * Re-enable tests * Make selecting "In your repositories" reset selection as passing IDs of repos belonging to other profiles causes breakage * Remove unnecessary (with multi-selection enable) code * Drop repo from repo map and total count if permission denied * Remove extra parenthesis * make template work again * find bug! * forgot the '#' at bugfixing * delete unused RepoID * compile regex only one time * make fmt * local variable = capital letter lower * check if repos query pattern is correct * pagination remove last , - make regex work again * use Replace instead of ReplaceAll; del delete * fix test * how did this test binary got in?!? dont forgot the "-p" at git add * ! * dont replace -> cut fisrt & last string Co-Authored-By: zeripath <art27@cantab.net> * jet another regex dont mind as long as it has the same result and is performatn ... Co-Authored-By: zeripath <art27@cantab.net> * dont use nonexisting repo for test * exclude /issues?type=created_by from test * add table to querys use same syntax in each query (table.colum) * add new issue for test * dont make a workaround or something else this need a refactor itself and is out of scope for this PR * fix misspell * CI.redo() * englisch txt update Co-Authored-By: zeripath <art27@cantab.net> * add sugestions * Tweak & Fix * CI.restart()
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. "fmt"
  7. "net/http"
  8. "path"
  9. "testing"
  10. "code.gitea.io/gitea/modules/setting"
  11. api "code.gitea.io/gitea/modules/structs"
  12. "code.gitea.io/gitea/modules/test"
  13. "github.com/stretchr/testify/assert"
  14. )
  15. func TestLinksNoLogin(t *testing.T) {
  16. defer prepareTestEnv(t)()
  17. var links = []string{
  18. "/explore/repos",
  19. "/explore/repos?q=test&tab=",
  20. "/explore/users",
  21. "/explore/users?q=test&tab=",
  22. "/explore/organizations",
  23. "/explore/organizations?q=test&tab=",
  24. "/",
  25. "/user/sign_up",
  26. "/user/login",
  27. "/user/forgot_password",
  28. "/api/swagger",
  29. "/api/v1/swagger",
  30. // TODO: follow this page and test every link
  31. "/vendor/librejs.html",
  32. }
  33. for _, link := range links {
  34. req := NewRequest(t, "GET", link)
  35. MakeRequest(t, req, http.StatusOK)
  36. }
  37. }
  38. func TestRedirectsNoLogin(t *testing.T) {
  39. defer prepareTestEnv(t)()
  40. var redirects = map[string]string{
  41. "/user2/repo1/commits/master": "/user2/repo1/commits/branch/master",
  42. "/user2/repo1/src/master": "/user2/repo1/src/branch/master",
  43. "/user2/repo1/src/master/file.txt": "/user2/repo1/src/branch/master/file.txt",
  44. "/user2/repo1/src/master/directory/file.txt": "/user2/repo1/src/branch/master/directory/file.txt",
  45. "/user/avatar/Ghost/-1": "/img/avatar_default.png",
  46. }
  47. for link, redirectLink := range redirects {
  48. req := NewRequest(t, "GET", link)
  49. resp := MakeRequest(t, req, http.StatusFound)
  50. assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), test.RedirectURL(resp))
  51. }
  52. }
  53. func testLinksAsUser(userName string, t *testing.T) {
  54. var links = []string{
  55. "/explore/repos",
  56. "/explore/repos?q=test&tab=",
  57. "/explore/users",
  58. "/explore/users?q=test&tab=",
  59. "/explore/organizations",
  60. "/explore/organizations?q=test&tab=",
  61. "/",
  62. "/user/forgot_password",
  63. "/api/swagger",
  64. "/api/v1/swagger",
  65. "/issues",
  66. "/issues?type=your_repositories&repos=[0]&sort=&state=open",
  67. "/issues?type=assigned&repos=[0]&sort=&state=open",
  68. "/issues?type=your_repositories&repos=[0]&sort=&state=closed",
  69. "/issues?type=assigned&repos=[]&sort=&state=closed",
  70. "/issues?type=assigned&sort=&state=open",
  71. "/issues?type=created_by&repos=[1,2]&sort=&state=closed",
  72. "/issues?type=created_by&repos=[1,2]&sort=&state=open",
  73. "/pulls",
  74. "/pulls?type=your_repositories&repos=[2]&sort=&state=open",
  75. "/pulls?type=assigned&repos=[]&sort=&state=open",
  76. "/pulls?type=created_by&repos=[0]&sort=&state=open",
  77. "/pulls?type=your_repositories&repos=[0]&sort=&state=closed",
  78. "/pulls?type=assigned&repos=[0]&sort=&state=closed",
  79. "/pulls?type=created_by&repos=[0]&sort=&state=closed",
  80. "/milestones",
  81. "/milestones?sort=mostcomplete&state=closed",
  82. "/milestones?type=your_repositories&sort=mostcomplete&state=closed",
  83. "/milestones?sort=&repos=[1]&state=closed",
  84. "/milestones?sort=&repos=[1]&state=open",
  85. "/milestones?repos=[0]&sort=mostissues&state=open",
  86. "/notifications",
  87. "/repo/create",
  88. "/repo/migrate",
  89. "/org/create",
  90. "/user2",
  91. "/user2?tab=stars",
  92. "/user2?tab=activity",
  93. "/user/settings",
  94. "/user/settings/account",
  95. "/user/settings/security",
  96. "/user/settings/security/two_factor/enroll",
  97. "/user/settings/keys",
  98. "/user/settings/organization",
  99. "/user/settings/repos",
  100. }
  101. session := loginUser(t, userName)
  102. for _, link := range links {
  103. req := NewRequest(t, "GET", link)
  104. session.MakeRequest(t, req, http.StatusOK)
  105. }
  106. reqAPI := NewRequestf(t, "GET", "/api/v1/users/%s/repos", userName)
  107. respAPI := MakeRequest(t, reqAPI, http.StatusOK)
  108. var apiRepos []*api.Repository
  109. DecodeJSON(t, respAPI, &apiRepos)
  110. var repoLinks = []string{
  111. "",
  112. "/issues",
  113. "/pulls",
  114. "/commits/branch/master",
  115. "/graph",
  116. "/settings",
  117. "/settings/collaboration",
  118. "/settings/branches",
  119. "/settings/hooks",
  120. // FIXME: below links should return 200 but 404 ??
  121. //"/settings/hooks/git",
  122. //"/settings/hooks/git/pre-receive",
  123. //"/settings/hooks/git/update",
  124. //"/settings/hooks/git/post-receive",
  125. "/settings/keys",
  126. "/releases",
  127. "/releases/new",
  128. //"/wiki/_pages",
  129. "/wiki/_new",
  130. }
  131. for _, repo := range apiRepos {
  132. for _, link := range repoLinks {
  133. req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s%s", userName, repo.Name, link))
  134. session.MakeRequest(t, req, http.StatusOK)
  135. }
  136. }
  137. }
  138. func TestLinksLogin(t *testing.T) {
  139. defer prepareTestEnv(t)()
  140. testLinksAsUser("user2", t)
  141. }