-
-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathITableColumnExtensionsTest.cs
More file actions
246 lines (229 loc) · 9.38 KB
/
ITableColumnExtensionsTest.cs
File metadata and controls
246 lines (229 loc) · 9.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
namespace UnitTest.Extensions;
public class ITableColumnExtensionsTest
{
[Fact]
public void InheritValue_Ok()
{
var col = new InternalTableColumn("Name", typeof(string));
var attr = new AutoGenerateClassAttribute()
{
Align = Alignment.Center,
TextWrap = true,
Ignore = true,
Filterable = true,
Readonly = true,
Searchable = true,
ShowTips = true,
Sortable = true,
TextEllipsis = true,
ShowCopyColumn = true,
Visible = false
};
col.InheritValue(attr);
Assert.Equal(Alignment.Center, col.Align);
Assert.True(col.TextWrap);
Assert.True(col.Ignore);
Assert.True(col.Filterable);
Assert.True(col.Readonly);
Assert.True(col.Searchable);
Assert.True(col.ShowTips);
Assert.True(col.Sortable);
Assert.True(col.TextEllipsis);
Assert.True(col.ShowCopyColumn);
Assert.False(col.Visible);
}
[Fact]
public void CopyValue_Ok()
{
var col = new InternalTableColumn("Name", typeof(string));
var attr = new InternalTableColumn("Name", typeof(string))
{
ComponentType = typeof(NullSwitch),
ComponentParameters = [],
Ignore = true,
EditTemplate = obj => builder => builder.AddContent(0, "test"),
Items = new List<SelectedItem>(),
Lookup = new List<SelectedItem>(),
LookupStringComparison = StringComparison.Ordinal,
LookupServiceKey = "test-key",
LookupService = new LookupService(),
LookupServiceData = true,
IsReadonlyWhenAdd = true,
IsReadonlyWhenEdit = true,
Readonly = true,
Rows = 3,
Cols = 6,
SkipValidate = true,
Text = "Test",
ValidateRules = [new RequiredValidator()],
ShowLabelTooltip = true,
GroupName = "test-group",
GroupOrder = 1,
PlaceHolder = "enter placeholder",
Align = Alignment.Center,
TextWrap = true,
CssClass = "test-css",
DefaultSort = true,
DefaultSortOrder = SortOrder.Desc,
Filter = new TableColumnFilter(),
Filterable = true,
FilterTemplate = builder => builder.AddContent(0, "test-filter"),
Fixed = true,
FormatString = "test-format",
Formatter = obj =>
{
var ret = "test-formatter";
return Task.FromResult<string?>(ret);
},
HeaderTemplate = col => builder => builder.AddContent(0, "test-header"),
ToolboxTemplate = col => builder => builder.AddContent(0, "test-toolbox"),
OnCellRender = args => { },
Searchable = true,
SearchTemplate = obj => builder => builder.AddContent(0, "test-search"),
ShownWithBreakPoint = BreakPoint.Large,
ShowTips = true,
Sortable = true,
Template = obj => builder => builder.AddContent(0, "test-template"),
TextEllipsis = true,
Visible = false,
IsVisibleWhenAdd = false,
IsVisibleWhenEdit = false,
Width = 100,
ShowHeaderTooltip = true,
HeaderTextEllipsis = true,
HeaderTextWrap = true,
HeaderTextTooltip = "test tooltip",
ShowSearchWhenSelect = true,
IsPopover = true,
ShowCopyColumn = true,
Step = "0.01",
Order = -1,
IsMarkupString = true,
GetTooltipTextCallback = _ => Task.FromResult<string?>(null),
CustomSearch = (_, _) => new SearchFilterAction("test", "test"),
Required = true,
RequiredErrorMessage = "test",
IsRequiredWhenAdd = true,
IsRequiredWhenEdit = true,
SearchFormItemMetaData = new StringSearchMetaData()
};
col.CopyValue(attr);
Assert.NotNull(col.ComponentType);
Assert.NotNull(col.ComponentParameters);
Assert.True(col.Ignore);
Assert.NotNull(col.EditTemplate);
Assert.NotNull(col.Items);
Assert.NotNull(col.Lookup);
Assert.Equal(StringComparison.Ordinal, col.LookupStringComparison);
Assert.Equal("test-key", col.LookupServiceKey);
Assert.Equal(true, col.LookupServiceData);
Assert.True(col.IsReadonlyWhenAdd);
Assert.True(col.IsReadonlyWhenEdit);
Assert.False(col.IsVisibleWhenAdd);
Assert.False(col.IsVisibleWhenEdit);
Assert.True(col.Readonly);
Assert.Equal(3, col.Rows);
Assert.Equal(6, col.Cols);
Assert.True(col.SkipValidate);
Assert.Equal("Test", col.Text);
Assert.NotNull(col.ValidateRules);
Assert.True(col.ShowLabelTooltip);
Assert.Equal("test-group", col.GroupName);
Assert.Equal(1, col.GroupOrder);
Assert.Equal(Alignment.Center, col.Align);
Assert.True(col.TextWrap);
Assert.Equal("test-css", col.CssClass);
Assert.True(col.DefaultSort);
Assert.Equal(SortOrder.Desc, col.DefaultSortOrder);
Assert.NotNull(col.Filter);
Assert.True(col.Filterable);
Assert.NotNull(col.FilterTemplate);
Assert.True(col.Fixed);
Assert.Equal("test-format", col.FormatString);
Assert.NotNull(col.Formatter);
Assert.NotNull(col.HeaderTemplate);
Assert.NotNull(attr.ToolboxTemplate);
Assert.NotNull(col.OnCellRender);
Assert.True(col.Searchable);
Assert.NotNull(col.SearchTemplate);
Assert.Equal(BreakPoint.Large, col.ShownWithBreakPoint);
Assert.True(col.ShowTips);
Assert.True(col.Sortable);
Assert.NotNull(col.Template);
Assert.True(col.TextEllipsis);
Assert.False(col.Visible);
Assert.Equal(100, col.Width);
Assert.True(col.ShowHeaderTooltip);
Assert.True(col.HeaderTextEllipsis);
Assert.True(col.HeaderTextWrap);
Assert.Equal("test tooltip", col.HeaderTextTooltip);
Assert.True(col.ShowSearchWhenSelect);
Assert.True(col.IsPopover);
Assert.True(col.ShowCopyColumn);
Assert.Equal("0.01", col.Step);
Assert.Equal(-1, col.Order);
Assert.NotNull(col.GetTooltipTextCallback);
Assert.True(col.IsMarkupString);
Assert.NotNull(col.CustomSearch);
Assert.True(col.Required);
Assert.True(col.IsRequiredWhenEdit);
Assert.True(col.IsRequiredWhenAdd);
Assert.Equal("test", col.RequiredErrorMessage);
Assert.NotNull(col.LookupService);
Assert.Equal("test-key", col.LookupServiceKey);
Assert.Equal(true, col.LookupServiceData);
Assert.NotNull(col.SearchFormItemMetaData);
}
[Fact]
public void ToSearches_Ok()
{
var cols = new InternalTableColumn[]
{
new("Test_Name", typeof(string)),
new("Test_Bool", typeof(bool)),
new("Test_NullBool", typeof(bool?)),
new("Test_Enum", typeof(SortOrder)),
new("Test_NullEnum", typeof(SortOrder?)),
new("Test_Int", typeof(int)),
new("Test_NullInt", typeof(int?)),
new("Test_Long", typeof(long)),
new("Test_NullLong", typeof(long?)),
new("Test_Short", typeof(short)),
new("Test_NullShort", typeof(short?)),
new("Test_Float", typeof(float)),
new("Test_NullFloat", typeof(float?)),
new("Test_Double", typeof(double)),
new("Test_NullDouble", typeof(double?)),
new("Test_Decimal", typeof(decimal)),
new("Test_Decimal", typeof(decimal?)),
};
// NullOrEmpty
var filters = cols.ToSearches(null);
Assert.Empty(filters);
filters = cols.ToSearches("");
Assert.Empty(filters);
// bool
filters = cols.ToSearches("true");
Assert.Equal(2, filters.Count(f => f.GetFilterConditions().FieldValue is bool));
// Enum
filters = cols.ToSearches("Asc");
Assert.Equal(2, filters.Count(f => f.GetFilterConditions().FieldValue is SortOrder));
// Number
filters = cols.ToSearches("1");
Assert.Equal(2, filters.Count(f => f.GetFilterConditions().FieldValue?.GetType() == typeof(int)));
Assert.Equal(2, filters.Count(f => f.GetFilterConditions().FieldValue?.GetType() == typeof(short)));
Assert.Equal(2, filters.Count(f => f.GetFilterConditions().FieldValue?.GetType() == typeof(long)));
filters = cols.ToSearches("2.1");
Assert.Equal(2, filters.Count(f => f.GetFilterConditions().FieldValue?.GetType() == typeof(float)));
Assert.Equal(2, filters.Count(f => f.GetFilterConditions().FieldValue?.GetType() == typeof(double)));
Assert.Equal(2, filters.Count(f => f.GetFilterConditions().FieldValue?.GetType() == typeof(decimal)));
}
class LookupService : LookupServiceBase
{
public override IEnumerable<SelectedItem>? GetItemsByKey(string? key, object? data) => null;
}
}