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.

173 lines
4.7 KiB

[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
  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. "/user2/repo1",
  31. "/user2/repo1/projects",
  32. "/user2/repo1/projects/1",
  33. }
  34. for _, link := range links {
  35. req := NewRequest(t, "GET", link)
  36. MakeRequest(t, req, http.StatusOK)
  37. }
  38. }
  39. func TestRedirectsNoLogin(t *testing.T) {
  40. defer prepareTestEnv(t)()
  41. var redirects = map[string]string{
  42. "/user2/repo1/commits/master": "/user2/repo1/commits/branch/master",
  43. "/user2/repo1/src/master": "/user2/repo1/src/branch/master",
  44. "/user2/repo1/src/master/file.txt": "/user2/repo1/src/branch/master/file.txt",
  45. "/user2/repo1/src/master/directory/file.txt": "/user2/repo1/src/branch/master/directory/file.txt",
  46. "/user/avatar/Ghost/-1": "/img/avatar_default.png",
  47. }
  48. for link, redirectLink := range redirects {
  49. req := NewRequest(t, "GET", link)
  50. resp := MakeRequest(t, req, http.StatusFound)
  51. assert.EqualValues(t, path.Join(setting.AppSubURL, redirectLink), test.RedirectURL(resp))
  52. }
  53. }
  54. func TestNoLoginNotExist(t *testing.T) {
  55. defer prepareTestEnv(t)()
  56. var links = []string{
  57. "/user5/repo4/projects",
  58. "/user5/repo4/projects/3",
  59. }
  60. for _, link := range links {
  61. req := NewRequest(t, "GET", link)
  62. MakeRequest(t, req, http.StatusNotFound)
  63. }
  64. }
  65. func testLinksAsUser(userName string, t *testing.T) {
  66. var links = []string{
  67. "/explore/repos",
  68. "/explore/repos?q=test&tab=",
  69. "/explore/users",
  70. "/explore/users?q=test&tab=",
  71. "/explore/organizations",
  72. "/explore/organizations?q=test&tab=",
  73. "/",
  74. "/user/forgot_password",
  75. "/api/swagger",
  76. "/api/v1/swagger",
  77. "/issues",
  78. "/issues?type=your_repositories&repos=[0]&sort=&state=open",
  79. "/issues?type=assigned&repos=[0]&sort=&state=open",
  80. "/issues?type=your_repositories&repos=[0]&sort=&state=closed",
  81. "/issues?type=assigned&repos=[]&sort=&state=closed",
  82. "/issues?type=assigned&sort=&state=open",
  83. "/issues?type=created_by&repos=[1,2]&sort=&state=closed",
  84. "/issues?type=created_by&repos=[1,2]&sort=&state=open",
  85. "/pulls",
  86. "/pulls?type=your_repositories&repos=[2]&sort=&state=open",
  87. "/pulls?type=assigned&repos=[]&sort=&state=open",
  88. "/pulls?type=created_by&repos=[0]&sort=&state=open",
  89. "/pulls?type=your_repositories&repos=[0]&sort=&state=closed",
  90. "/pulls?type=assigned&repos=[0]&sort=&state=closed",
  91. "/pulls?type=created_by&repos=[0]&sort=&state=closed",
  92. "/milestones",
  93. "/milestones?sort=mostcomplete&state=closed",
  94. "/milestones?type=your_repositories&sort=mostcomplete&state=closed",
  95. "/milestones?sort=&repos=[1]&state=closed",
  96. "/milestones?sort=&repos=[1]&state=open",
  97. "/milestones?repos=[0]&sort=mostissues&state=open",
  98. "/notifications",
  99. "/repo/create",
  100. "/repo/migrate",
  101. "/org/create",
  102. "/user2",
  103. "/user2?tab=stars",
  104. "/user2?tab=activity",
  105. "/user/settings",
  106. "/user/settings/account",
  107. "/user/settings/security",
  108. "/user/settings/security/two_factor/enroll",
  109. "/user/settings/keys",
  110. "/user/settings/organization",
  111. "/user/settings/repos",
  112. }
  113. session := loginUser(t, userName)
  114. for _, link := range links {
  115. req := NewRequest(t, "GET", link)
  116. session.MakeRequest(t, req, http.StatusOK)
  117. }
  118. reqAPI := NewRequestf(t, "GET", "/api/v1/users/%s/repos", userName)
  119. respAPI := MakeRequest(t, reqAPI, http.StatusOK)
  120. var apiRepos []*api.Repository
  121. DecodeJSON(t, respAPI, &apiRepos)
  122. var repoLinks = []string{
  123. "",
  124. "/issues",
  125. "/pulls",
  126. "/commits/branch/master",
  127. "/graph",
  128. "/settings",
  129. "/settings/collaboration",
  130. "/settings/branches",
  131. "/settings/hooks",
  132. // FIXME: below links should return 200 but 404 ??
  133. //"/settings/hooks/git",
  134. //"/settings/hooks/git/pre-receive",
  135. //"/settings/hooks/git/update",
  136. //"/settings/hooks/git/post-receive",
  137. "/settings/keys",
  138. "/releases",
  139. "/releases/new",
  140. //"/wiki/_pages",
  141. "/wiki/_new",
  142. }
  143. for _, repo := range apiRepos {
  144. for _, link := range repoLinks {
  145. req := NewRequest(t, "GET", fmt.Sprintf("/%s/%s%s", userName, repo.Name, link))
  146. session.MakeRequest(t, req, http.StatusOK)
  147. }
  148. }
  149. }
  150. func TestLinksLogin(t *testing.T) {
  151. defer prepareTestEnv(t)()
  152. testLinksAsUser("user2", t)
  153. }