2018-08-07 22:45:41 +05:30
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2018-08-07 22:45:41 +05:30
|
|
|
|
2021-01-26 21:06:53 +05:30
|
|
|
package forms
|
2018-08-07 22:45:41 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-02-19 02:25:04 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2019-08-23 22:10:30 +05:30
|
|
|
|
2018-08-07 22:45:41 +05:30
|
|
|
"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())
|
|
|
|
}
|
|
|
|
}
|
2019-02-19 02:25:04 +05:30
|
|
|
|
|
|
|
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())
|
|
|
|
}
|
|
|
|
}
|