summaryrefslogtreecommitdiffstats
path: root/services/forms/repo_form_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
committerDaniel Baumann <daniel@debian.org>2024-10-18 20:33:49 +0200
commitdd136858f1ea40ad3c94191d647487fa4f31926c (patch)
tree58fec94a7b2a12510c9664b21793f1ed560c6518 /services/forms/repo_form_test.go
parentInitial commit. (diff)
downloadforgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.tar.xz
forgejo-dd136858f1ea40ad3c94191d647487fa4f31926c.zip
Adding upstream version 9.0.0.upstream/9.0.0upstreamdebian
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'services/forms/repo_form_test.go')
-rw-r--r--services/forms/repo_form_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/services/forms/repo_form_test.go b/services/forms/repo_form_test.go
new file mode 100644
index 0000000..2c5a8e2
--- /dev/null
+++ b/services/forms/repo_form_test.go
@@ -0,0 +1,64 @@
+// Copyright 2018 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package forms
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/modules/setting"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestSubmitReviewForm_IsEmpty(t *testing.T) {
+ cases := []struct {
+ form SubmitReviewForm
+ expected bool
+ }{
+ // Approved PR with a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "approve", Content: "Awesome"}, false},
+
+ // Approved PR without a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "approve", Content: ""}, false},
+
+ // Rejected PR without a comment should count as empty
+ {SubmitReviewForm{Type: "reject", Content: ""}, true},
+
+ // Rejected PR with a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "reject", Content: "Awesome"}, false},
+
+ // Comment review on a PR with a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "comment", Content: "Awesome"}, false},
+
+ // Comment review on a PR without a comment should count as empty
+ {SubmitReviewForm{Type: "comment", Content: ""}, true},
+ }
+
+ for _, v := range cases {
+ assert.Equal(t, v.expected, v.form.HasEmptyContent())
+ }
+}
+
+func TestIssueLock_HasValidReason(t *testing.T) {
+ // Init settings
+ _ = setting.Repository
+
+ cases := []struct {
+ form IssueLockForm
+ expected bool
+ }{
+ {IssueLockForm{""}, true}, // an empty reason is accepted
+ {IssueLockForm{"Off-topic"}, true},
+ {IssueLockForm{"Too heated"}, true},
+ {IssueLockForm{"Spam"}, true},
+ {IssueLockForm{"Resolved"}, true},
+
+ {IssueLockForm{"ZZZZ"}, false},
+ {IssueLockForm{"I want to lock this issue"}, false},
+ }
+
+ for _, v := range cases {
+ assert.Equal(t, v.expected, v.form.HasValidReason())
+ }
+}