-
-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathStepTest.cs
More file actions
197 lines (175 loc) · 6.3 KB
/
StepTest.cs
File metadata and controls
197 lines (175 loc) · 6.3 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
// 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.Components;
public class StepTest : BootstrapBlazorTestBase
{
[Fact]
public void Step_Items()
{
var cut = Context.Render<Step>(pb =>
{
pb.Add(a => a.Items, GetStepItems);
});
cut.Contains("class=\"step\"");
cut.Contains("step-header");
cut.Contains("step-body");
var headers = cut.FindAll(".step-item");
Assert.Equal(3, headers.Count);
var body = cut.FindAll(".step-body-item");
Assert.Equal(3, body.Count);
cut.Render(pb =>
{
pb.Add(a => a.Items, null);
});
cut.Contains("class=\"step\"");
cut.Contains("step-header");
cut.Contains("step-body");
headers = cut.FindAll(".step-item");
Assert.Empty(headers);
body = cut.FindAll(".step-body-item");
Assert.Empty(body);
Assert.Equal(0, cut.Instance.CurrentStepIndex);
}
[Fact]
public void Step_IsVertical()
{
var cut = Context.Render<Step>(pb =>
{
pb.Add(a => a.Items, GetStepItems);
pb.Add(a => a.IsVertical, true);
});
cut.Contains("class=\"step step-vertical\"");
}
[Fact]
public void Step_ChildContent()
{
var cut = Context.Render<Step>(pb =>
{
pb.Add(a => a.StepIndex, 1);
pb.Add(a => a.ChildContent, builder =>
{
builder.OpenComponent<StepItem>(0);
builder.AddAttribute(3, nameof(StepItem.FinishedIcon), "test-item-finish-icon1");
builder.AddAttribute(4, nameof(StepItem.Title), "test-item-title");
builder.AddAttribute(5, nameof(StepItem.Description), "test-item-desc");
builder.AddAttribute(6, nameof(StepItem.ChildContent), new RenderFragment(b =>
{
b.AddContent(7, "test-item-content");
}));
builder.CloseComponent();
builder.OpenComponent<StepItem>(10);
builder.AddAttribute(11, nameof(StepItem.HeaderTemplate), new RenderFragment<StepOption>(option => b =>
{
b.AddContent(12, "test-item-header-template");
}));
builder.AddAttribute(13, nameof(StepItem.TitleTemplate), new RenderFragment<StepOption>(option => b =>
{
b.AddContent(14, "test-item-title-template");
}));
builder.AddAttribute(15, nameof(StepItem.FinishedIcon), "test-item-finish-icon1");
builder.CloseComponent();
builder.OpenComponent<StepItem>(20);
builder.AddAttribute(21, nameof(StepItem.Text), "Text1");
builder.AddAttribute(22, nameof(StepItem.Icon), "test-item-icon1");
builder.CloseComponent();
});
});
var headers = cut.FindAll(".step-item");
Assert.True(headers[1].ClassList.Contains("active"));
cut.Contains("Text1");
cut.Contains("test-item-icon1");
cut.Contains("test-item-finish-icon1");
cut.Contains("test-item-title");
cut.Contains("test-item-desc");
cut.Contains("test-item-content");
cut.Contains("test-item-header-template");
cut.Contains("test-item-title-template");
}
[Fact]
public void Step_Method()
{
var cut = Context.Render<Step>(pb =>
{
pb.Add(a => a.Items, GetStepItems);
pb.Add(a => a.StepIndex, 1);
});
var step = cut.Instance;
cut.InvokeAsync(() => step.Next());
var headers = cut.FindAll(".step-item");
Assert.True(headers[2].ClassList.Contains("active"));
cut.InvokeAsync(() => step.Prev());
headers = cut.FindAll(".step-item");
Assert.True(headers[1].ClassList.Contains("active"));
cut.InvokeAsync(() => step.Reset());
headers = cut.FindAll(".step-item");
Assert.True(headers[0].ClassList.Contains("active"));
cut.InvokeAsync(() => step.Insert(1, new StepOption() { Text = "test1" }));
Assert.Equal(4, cut.Instance.Items.Count);
}
[Fact]
public async Task FinishedTemplate_Ok()
{
bool finished = false;
var cut = Context.Render<Step>(pb =>
{
pb.Add(a => a.Items, GetStepItems);
pb.Add(a => a.StepIndex, 3);
pb.Add(a => a.FinishedTemplate, new RenderFragment(builder => builder.AddContent(0, "Finished-Template")));
pb.Add(a => a.OnFinishedCallback, () =>
{
finished = true;
return Task.CompletedTask;
});
});
var step = cut.Instance;
await cut.InvokeAsync(() => step.Next());
cut.Contains("Finished-Template");
Assert.True(finished);
}
[Fact]
public async Task SetStepIndex()
{
bool finished = false;
var cut = Context.Render<Step>(pb =>
{
pb.Add(a => a.Items, GetStepItems);
pb.Add(a => a.StepIndex, 2);
pb.Add(a => a.OnFinishedCallback, () =>
{
finished = true;
return Task.CompletedTask;
});
});
var step = cut.Instance;
await cut.InvokeAsync(() => step.SetStepIndex(1));
Assert.False(finished);
await cut.InvokeAsync(() => step.SetStepIndex(3));
Assert.True(finished);
}
[Fact]
public void StepItem_Ok()
{
var cut = Context.Render<StepItem>(pb =>
{
pb.Add(a => a.Text, "test1");
});
Assert.Equal("test1", cut.Instance.Text);
}
private static List<StepOption> GetStepItems => new()
{
new StepOption()
{
Template = builder => builder.AddContent(0, "SteItem1")
},
new StepOption()
{
Template = builder => builder.AddContent(0, "SteItem2")
},
new StepOption()
{
Template = builder => builder.AddContent(0, "SteItem3")
}
};
}