-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathRenderModeTests.razor
More file actions
176 lines (150 loc) · 6.22 KB
/
RenderModeTests.razor
File metadata and controls
176 lines (150 loc) · 6.22 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
@code{
#if NET9_0_OR_GREATER
}
@using Bunit.TestAssets.RenderModes;
@inherits TestContext
@code {
[Fact(DisplayName = "TestRenderer provides RendererInfo")]
public void Test001()
{
SetRendererInfo(new RendererInfo("Server", true));
var cut = RenderComponent<RendererInfoComponent>();
cut.MarkupMatches(
@<text>
<p>Is interactive: True</p>
<p>Rendermode: Server</p>
</text>);
}
[Fact(DisplayName = "Renderer throws exception if RendererInfo is not specified")]
public void Test002()
{
Action act = () => RenderComponent<RendererInfoComponent>();
act.ShouldThrow<MissingRendererInfoException>();
}
[Fact(DisplayName = "Renderer should set the RenderModeAttribute on the component")]
public void Test003()
{
var cut = RenderComponent<ComponentWithServerRenderMode>();
cut.MarkupMatches(@<div>Assigned render mode: InteractiveServerRenderMode</div>);
}
[Fact(DisplayName = "The AssignedRenderMode is based on the RenderModeAttribute in the component hierarchy where parent component has no RenderMode")]
public void Test004()
{
var cut = Render(
@<ComponentWithoutRenderMode>
<ComponentWithWebAssemblyRenderMode />
</ComponentWithoutRenderMode>);
cut.MarkupMatches(
@<text>
<div>Parent assigned render mode: </div>
<div>Assigned render mode: InteractiveWebAssemblyRenderMode</div>
</text>);
}
[Fact(DisplayName = "Parent and child render mode is specified")]
public void Test005()
{
var cut = Render(
@<ComponentWithServerRenderMode>
<ComponentWithServerRenderMode />
</ComponentWithServerRenderMode>);
cut.MarkupMatches(
@<text>
<div>Parent assigned render mode: InteractiveServerRenderMode</div>
<div>Assigned render mode: InteractiveServerRenderMode</div>
</text>);
}
[Fact(DisplayName = "Parent and child render mode is not specified")]
public void Test006()
{
var cut = Render(
@<ComponentWithoutRenderMode>
<ComponentWithoutRenderMode />
</ComponentWithoutRenderMode>);
cut.MarkupMatches(
@<text>
<div>Parent assigned render mode: </div>
<div>Assigned render mode: </div>
</text>);
}
[Fact(DisplayName = "Rendermode specified on child")]
public void Test007()
{
var cut = Render(
@<ComponentWithChildContent>
<ComponentThatPrintsAssignedRenderMode @rendermode="RenderMode.InteractiveServer" />
</ComponentWithChildContent>);
cut.MarkupMatches(@<p>Assigned Render Mode: InteractiveServerRenderMode</p>);
}
[Fact(DisplayName = "Assigned Render Mode is inherited all the way down the component hierarchy")]
public void Test008()
{
var cut = Render(
@<ComponentWithChildContent @rendermode="RenderMode.InteractiveServer">
<ComponentWithChildContent>
<ComponentThatPrintsAssignedRenderMode />
</ComponentWithChildContent>
</ComponentWithChildContent>);
cut.MarkupMatches(@<p>Assigned Render Mode: InteractiveServerRenderMode</p>);
}
[Fact(DisplayName = "Having a component with section outlet and RenderMode is specifying for child component")]
public void Test009()
{
// See: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/sections?view=aspnetcore-8.0#section-interaction-with-other-blazor-features
var cut = Render(@<SectionOutletComponent><ComponentThatPrintsAssignedRenderMode/></SectionOutletComponent>);
cut.MarkupMatches(@<p>Assigned Render Mode: InteractiveWebAssemblyRenderMode</p>);
}
[Fact(DisplayName = "Assigned Render Mode on siblings")]
public void Test010()
{
var cut = Render(
@<ComponentWithChildContent>
<ComponentThatPrintsAssignedRenderMode @rendermode="RenderMode.InteractiveServer"/>
<ComponentThatPrintsAssignedRenderMode @rendermode="RenderMode.InteractiveWebAssembly"/>
</ComponentWithChildContent>);
cut.MarkupMatches(
@<text>
<p>Assigned Render Mode: InteractiveServerRenderMode</p>
<p>Assigned Render Mode: InteractiveWebAssemblyRenderMode</p>
</text>);
}
[Fact(DisplayName = "SetAssignedRenderMode on root component")]
public void Test011()
{
var cut = RenderComponent<ComponentThatPrintsAssignedRenderMode>(ps => ps.SetAssignedRenderMode(RenderMode.InteractiveServer));
cut.MarkupMatches(@<p>Assigned Render Mode: InteractiveServerRenderMode</p>);
}
[Fact(DisplayName = "SetAssignedRenderMode on parent component cascades to children")]
public void Test012()
{
var cut = RenderComponent<ComponentWithChildContent>(ps => ps
.SetAssignedRenderMode(RenderMode.InteractiveWebAssembly)
.AddChildContent<ComponentThatPrintsAssignedRenderMode>());
cut.MarkupMatches(@<p>Assigned Render Mode: InteractiveWebAssemblyRenderMode</p>);
}
[Fact(DisplayName = "SetAssignedRenderMode child components")]
public void Test013()
{
var cut = RenderComponent<ComponentWithChildContent>(ps => ps
.AddChildContent<ComponentThatPrintsAssignedRenderMode>(pps => pps.SetAssignedRenderMode(RenderMode.InteractiveServer))
.AddChildContent<ComponentThatPrintsAssignedRenderMode>(pps => pps.SetAssignedRenderMode(RenderMode.InteractiveWebAssembly)));
cut.MarkupMatches(
@<text>
<p>Assigned Render Mode: InteractiveServerRenderMode</p>
<p>Assigned Render Mode: InteractiveWebAssemblyRenderMode</p>
</text>);
}
[Fact(DisplayName = "Different assigned RenderMode between child and parent throws")]
public void Test020()
{
var act = () => Render(
@<ComponentWithChildContent @rendermode="RenderMode.InteractiveServer">
<ComponentWithChildContent @rendermode="RenderMode.InteractiveWebAssembly">
<ComponentThatPrintsAssignedRenderMode />
</ComponentWithChildContent>
</ComponentWithChildContent>);
act.ShouldThrow<RenderModeMisMatchException>();
}
}
@code{
#endif
}