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.

repo_form_test.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. }