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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package forms
  4. import (
  5. "testing"
  6. "code.gitea.io/gitea/modules/setting"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestSubmitReviewForm_IsEmpty(t *testing.T) {
  10. cases := []struct {
  11. form SubmitReviewForm
  12. expected bool
  13. }{
  14. // Approved PR with a comment shouldn't count as empty
  15. {SubmitReviewForm{Type: "approve", Content: "Awesome"}, false},
  16. // Approved PR without a comment shouldn't count as empty
  17. {SubmitReviewForm{Type: "approve", Content: ""}, false},
  18. // Rejected PR without a comment should count as empty
  19. {SubmitReviewForm{Type: "reject", Content: ""}, true},
  20. // Rejected PR with a comment shouldn't count as empty
  21. {SubmitReviewForm{Type: "reject", Content: "Awesome"}, false},
  22. // Comment review on a PR with a comment shouldn't count as empty
  23. {SubmitReviewForm{Type: "comment", Content: "Awesome"}, false},
  24. // Comment review on a PR without a comment should count as empty
  25. {SubmitReviewForm{Type: "comment", Content: ""}, true},
  26. }
  27. for _, v := range cases {
  28. assert.Equal(t, v.expected, v.form.HasEmptyContent())
  29. }
  30. }
  31. func TestIssueLock_HasValidReason(t *testing.T) {
  32. // Init settings
  33. _ = setting.Repository
  34. cases := []struct {
  35. form IssueLockForm
  36. expected bool
  37. }{
  38. {IssueLockForm{""}, true}, // an empty reason is accepted
  39. {IssueLockForm{"Off-topic"}, true},
  40. {IssueLockForm{"Too heated"}, true},
  41. {IssueLockForm{"Spam"}, true},
  42. {IssueLockForm{"Resolved"}, true},
  43. {IssueLockForm{"ZZZZ"}, false},
  44. {IssueLockForm{"I want to lock this issue"}, false},
  45. }
  46. for _, v := range cases {
  47. assert.Equal(t, v.expected, v.form.HasValidReason())
  48. }
  49. }