-
-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathModalDialogTest.cs
More file actions
207 lines (189 loc) · 6.42 KB
/
ModalDialogTest.cs
File metadata and controls
207 lines (189 loc) · 6.42 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
// 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
using System.Web;
namespace UnitTest.Components;
public class ModalDialogTest : BootstrapBlazorTestBase
{
[Fact]
public void ShowPrintButton_Ok()
{
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Modal>(pb =>
{
pb.AddChildContent<ModalDialog>(pb =>
{
pb.Add(d => d.ShowPrintButton, true);
pb.Add(d => d.PrintButtonColor, Color.Danger);
});
});
});
// 显示在 Footer
Assert.NotNull(cut.FindComponent<PrintButton>());
var dialog = cut.FindComponent<ModalDialog>();
dialog.SetParametersAndRender(pb =>
{
pb.Add(d => d.ShowPrintButtonInHeader, true);
});
// 显示在 Header
Assert.NotNull(cut.FindComponent<PrintButton>());
}
[Fact]
public void ShowExportPdfButton_Ok()
{
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Modal>(pb =>
{
pb.AddChildContent<ModalDialog>(pb =>
{
pb.Add(d => d.ShowExportPdfButton, true);
});
});
});
// 显示在 Footer
Assert.NotNull(cut.FindComponent<ExportPdfButton>());
var dialog = cut.FindComponent<ModalDialog>();
dialog.SetParametersAndRender(pb =>
{
pb.Add(d => d.ShowExportPdfButtonInHeader, true);
});
// 显示在 Header
Assert.NotNull(cut.FindComponent<ExportPdfButton>());
}
[Fact]
public void IsDraggable_Ok()
{
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Modal>(pb =>
{
pb.AddChildContent<ModalDialog>(pb =>
{
pb.Add(d => d.IsDraggable, true);
pb.Add(d => d.Class, "test_class");
});
});
});
Assert.Contains("is-draggable", cut.Markup);
Assert.Contains("is-draggable-center", cut.Markup);
Assert.Contains("test_class", cut.Markup);
var dialog = cut.FindComponent<ModalDialog>();
dialog.SetParametersAndRender(pb =>
{
pb.Add(a => a.IsCentered, false);
});
Assert.DoesNotContain("is-draggable-center", cut.Markup);
}
[Fact]
public void ShowResize_Ok()
{
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Modal>(pb =>
{
pb.AddChildContent<ModalDialog>(pb =>
{
pb.Add(d => d.ShowResize, true);
});
});
});
Assert.Contains("modal-resizer", cut.Markup);
}
[Fact]
public void ShowMaximizeButton_Ok()
{
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Modal>(pb =>
{
pb.AddChildContent<ModalDialog>(pb =>
{
pb.Add(d => d.ShowMaximizeButton, true);
});
});
});
Assert.Contains("btn-maximize", cut.Markup);
var button = cut.Find(".btn-maximize");
button.Click();
cut.WaitForAssertion(() => cut.Contains("modal-fullscreen"));
button.Click();
cut.WaitForAssertion(() => cut.DoesNotContain("modal-fullscreen"));
}
[Fact]
public void HeaderTemplate_Ok()
{
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Modal>(pb =>
{
pb.AddChildContent<ModalDialog>(pb =>
{
pb.Add(d => d.HeaderTemplate, builder => builder.AddContent(0, "HeaderTemplate"));
});
});
});
Assert.Contains("HeaderTemplate", cut.Markup);
}
[Fact]
public void FooterTemplate_Ok()
{
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Modal>(pb =>
{
pb.AddChildContent<ModalDialog>(pb =>
{
pb.Add(d => d.FooterTemplate, builder => builder.AddContent(0, "FooterTemplate"));
});
});
});
Assert.Contains("FooterTemplate", cut.Markup);
}
[Fact]
public void BodyContext_Ok()
{
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Modal>(pb =>
{
pb.AddChildContent<ModalDialog>(pb =>
{
pb.Add(d => d.FooterContentTemplate, builder => builder.AddContent(0, "footer-content-template"));
pb.Add(d => d.BodyContext, new Foo() { Name = "Test_BodyContext" });
pb.Add(d => d.BodyTemplate, BootstrapDynamicComponent.CreateComponent<MockModalDialogContentComponent>().Render());
});
});
});
var content = cut.FindComponent<MockModalDialogContentComponent>().Instance;
var f = content.Context as Foo;
Assert.Equal("Test_BodyContext", f!.Name);
cut.Contains("footer-content-template");
}
[Fact]
public void OnSaveAsync_Ok()
{
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Modal>(pb =>
{
pb.AddChildContent<ModalDialog>(pb =>
{
pb.Add(d => d.ShowSaveButton, true);
pb.Add(d => d.IsAutoCloseAfterSave, true);
pb.Add(d => d.OnSaveAsync, () => Task.FromResult(true));
});
});
});
Assert.Contains("保存", HttpUtility.HtmlDecode(cut.Markup));
var b = cut.FindComponents<Button>().Last();
cut.InvokeAsync(() => b.Instance.OnClickWithoutRender!());
}
private class MockModalDialogContentComponent : ComponentBase
{
[CascadingParameter(Name = "BodyContext")]
public object? Context { get; set; }
}
}