code.gitea.io/gitea@v1.21.7/services/forms/repo_form_test.go (about)

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