Skip to content

Commit c47763c

Browse files
authored
Merge pull request #660 from junler/fix/filter-operator-like-form-display
fix: 修复FilterOperatorLike导致页面显示不必要form-group的问题
2 parents cd8748f + 3398af8 commit c47763c

2 files changed

Lines changed: 87 additions & 1 deletion

File tree

template/types/operators.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (o FilterOperator) Label() template.HTML {
7373
}
7474

7575
func (o FilterOperator) AddOrNot() bool {
76-
return string(o) != "" && o != FilterOperatorFree
76+
return string(o) != "" && o != FilterOperatorFree && o != FilterOperatorLike
7777
}
7878

7979
func (o FilterOperator) Valid() bool {

template/types/operators_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package types
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestFilterOperatorAddOrNot(t *testing.T) {
8+
tests := []struct {
9+
name string
10+
operator FilterOperator
11+
expected bool
12+
}{
13+
{
14+
name: "FilterOperatorLike should not add operator field",
15+
operator: FilterOperatorLike,
16+
expected: false,
17+
},
18+
{
19+
name: "FilterOperatorFree should not add operator field",
20+
operator: FilterOperatorFree,
21+
expected: false,
22+
},
23+
{
24+
name: "Empty operator should not add operator field",
25+
operator: FilterOperator(""),
26+
expected: false,
27+
},
28+
{
29+
name: "FilterOperatorGreater should add operator field",
30+
operator: FilterOperatorGreater,
31+
expected: true,
32+
},
33+
{
34+
name: "FilterOperatorEqual should add operator field",
35+
operator: FilterOperatorEqual,
36+
expected: true,
37+
},
38+
{
39+
name: "FilterOperatorNotEqual should add operator field",
40+
operator: FilterOperatorNotEqual,
41+
expected: true,
42+
},
43+
}
44+
45+
for _, tt := range tests {
46+
t.Run(tt.name, func(t *testing.T) {
47+
result := tt.operator.AddOrNot()
48+
if result != tt.expected {
49+
t.Errorf("FilterOperator.AddOrNot() = %v, expected %v for operator %s", result, tt.expected, string(tt.operator))
50+
}
51+
})
52+
}
53+
}
54+
55+
func TestFilterOperatorLabel(t *testing.T) {
56+
tests := []struct {
57+
name string
58+
operator FilterOperator
59+
expected string
60+
}{
61+
{
62+
name: "FilterOperatorLike should return empty label",
63+
operator: FilterOperatorLike,
64+
expected: "",
65+
},
66+
{
67+
name: "FilterOperatorGreater should return > label",
68+
operator: FilterOperatorGreater,
69+
expected: ">",
70+
},
71+
{
72+
name: "FilterOperatorEqual should return = label",
73+
operator: FilterOperatorEqual,
74+
expected: "=",
75+
},
76+
}
77+
78+
for _, tt := range tests {
79+
t.Run(tt.name, func(t *testing.T) {
80+
result := string(tt.operator.Label())
81+
if result != tt.expected {
82+
t.Errorf("FilterOperator.Label() = %v, expected %v for operator %s", result, tt.expected, string(tt.operator))
83+
}
84+
})
85+
}
86+
}

0 commit comments

Comments
 (0)