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

68 行
1.7KB

  1. // Copyright 2018 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 auth
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/modules/setting"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestSubmitReviewForm_IsEmpty(t *testing.T) {
  11. cases := []struct {
  12. form SubmitReviewForm
  13. expected bool
  14. }{
  15. // Approved PR with a comment shouldn't count as empty
  16. {SubmitReviewForm{Type: "approve", Content: "Awesome"}, false},
  17. // Approved PR without a comment shouldn't count as empty
  18. {SubmitReviewForm{Type: "approve", Content: ""}, false},
  19. // Rejected PR without a comment should count as empty
  20. {SubmitReviewForm{Type: "reject", Content: ""}, true},
  21. // Rejected PR with a comment shouldn't count as empty
  22. {SubmitReviewForm{Type: "reject", Content: "Awesome"}, false},
  23. // Comment review on a PR with a comment shouldn't count as empty
  24. {SubmitReviewForm{Type: "comment", Content: "Awesome"}, false},
  25. // Comment review on a PR without a comment should count as empty
  26. {SubmitReviewForm{Type: "comment", Content: ""}, true},
  27. }
  28. for _, v := range cases {
  29. assert.Equal(t, v.expected, v.form.HasEmptyContent())
  30. }
  31. }
  32. func TestIssueLock_HasValidReason(t *testing.T) {
  33. // Init settings
  34. _ = setting.Repository
  35. cases := []struct {
  36. form IssueLockForm
  37. expected bool
  38. }{
  39. {IssueLockForm{""}, true}, // an empty reason is accepted
  40. {IssueLockForm{"Off-topic"}, true},
  41. {IssueLockForm{"Too heated"}, true},
  42. {IssueLockForm{"Spam"}, true},
  43. {IssueLockForm{"Resolved"}, true},
  44. {IssueLockForm{"ZZZZ"}, false},
  45. {IssueLockForm{"I want to lock this issue"}, false},
  46. }
  47. for _, v := range cases {
  48. assert.Equal(t, v.expected, v.form.HasValidReason())
  49. }
  50. }
上海开阖软件有限公司 沪ICP备12045867号-1