選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

home_test.go 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 user
  5. import (
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/setting"
  10. "code.gitea.io/gitea/modules/test"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestIssues(t *testing.T) {
  14. setting.UI.IssuePagingNum = 1
  15. assert.NoError(t, models.LoadFixtures())
  16. ctx := test.MockContext(t, "issues")
  17. test.LoadUser(t, ctx, 2)
  18. ctx.SetParams(":type", "issues")
  19. ctx.Req.Form.Set("state", "closed")
  20. Issues(ctx)
  21. assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
  22. assert.EqualValues(t, map[int64]int64{1: 1, 2: 1}, ctx.Data["Counts"])
  23. assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
  24. assert.Len(t, ctx.Data["Issues"], 1)
  25. assert.Len(t, ctx.Data["Repos"], 2)
  26. }
  27. func TestMilestones(t *testing.T) {
  28. setting.UI.IssuePagingNum = 1
  29. assert.NoError(t, models.LoadFixtures())
  30. ctx := test.MockContext(t, "milestones")
  31. test.LoadUser(t, ctx, 2)
  32. ctx.SetParams("sort", "issues")
  33. ctx.Req.Form.Set("state", "closed")
  34. ctx.Req.Form.Set("sort", "furthestduedate")
  35. Milestones(ctx)
  36. assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
  37. assert.EqualValues(t, map[int64]int64{1: 1}, ctx.Data["Counts"])
  38. assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
  39. assert.EqualValues(t, "furthestduedate", ctx.Data["SortType"])
  40. assert.EqualValues(t, 1, ctx.Data["Total"])
  41. assert.Len(t, ctx.Data["Milestones"], 1)
  42. assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
  43. }
  44. func TestMilestonesForSpecificRepo(t *testing.T) {
  45. setting.UI.IssuePagingNum = 1
  46. assert.NoError(t, models.LoadFixtures())
  47. ctx := test.MockContext(t, "milestones")
  48. test.LoadUser(t, ctx, 2)
  49. ctx.SetParams("sort", "issues")
  50. ctx.SetParams("repo", "1")
  51. ctx.Req.Form.Set("state", "closed")
  52. ctx.Req.Form.Set("sort", "furthestduedate")
  53. Milestones(ctx)
  54. assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
  55. assert.EqualValues(t, map[int64]int64{1: 1}, ctx.Data["Counts"])
  56. assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
  57. assert.EqualValues(t, "furthestduedate", ctx.Data["SortType"])
  58. assert.EqualValues(t, 1, ctx.Data["Total"])
  59. assert.Len(t, ctx.Data["Milestones"], 1)
  60. assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
  61. }