Skip to content

Commit 8227811

Browse files
authored
Unit test footer style(#15) (#76)
* DataList bind item and data (#63) * (#15) Exercise DataList FooterStyle
1 parent 2d73640 commit 8227811

File tree

11 files changed

+261
-7
lines changed

11 files changed

+261
-7
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
@page "/ControlSamples/DataList/FooterStyle"
2+
@using static BlazorWebFormsComponents.WebColor
3+
4+
<h2>DataList FooterStyle sample</h2>
5+
6+
<Nav />
7+
8+
<p>Here is a simple datalist bound to a collection of widgets with simple FooterStyle applied</p>
9+
10+
<DataList @ref="simpleDataList"
11+
runat="server"
12+
EnableViewState="false"
13+
Context="Item"
14+
ItemType="SharedSampleObjects.Models.Widget">
15+
<ChildContent>
16+
<BlazorWebFormsComponents.FooterStyle BackColor="Blue" ForeColor="White"></BlazorWebFormsComponents.FooterStyle>
17+
</ChildContent>
18+
<FooterTemplate>Simple Widgets</FooterTemplate>
19+
<ItemTemplate>
20+
@Item.Name - @Item.Price.ToString("c")
21+
</ItemTemplate>
22+
</DataList>
23+
24+
<br />
25+
<h3>Setting Values in the footer style from inline attributes</h3>
26+
<DataList
27+
runat="server"
28+
EnableViewState="false"
29+
Context="Item"
30+
FooterStyle-BackColor="@("#C84630")"
31+
FooterStyle-ForeColor="White"
32+
FooterStyle-BorderColor="White"
33+
FooterStyle-BorderStyle="Solid"
34+
FooterStyle-BorderWidth="2"
35+
SelectMethod="GetWidgets"
36+
ItemType="SharedSampleObjects.Models.Widget">
37+
<ChildContent>
38+
<BlazorWebFormsComponents.FooterStyle BackColor="Blue"></BlazorWebFormsComponents.FooterStyle>
39+
</ChildContent>
40+
<FooterTemplate>Simple Widgets</FooterTemplate>
41+
<ItemTemplate>
42+
@Item.Name - @Item.Price.ToString("c")
43+
</ItemTemplate>
44+
</DataList>
45+
46+
@code {
47+
48+
BlazorWebFormsComponents.DataList<Widget> simpleDataList { get; set; }
49+
50+
protected override void OnAfterRender(bool firstRender)
51+
{
52+
53+
if (firstRender)
54+
{
55+
simpleDataList.DataSource = Widget.SimpleWidgetList;
56+
simpleDataList.DataBind();
57+
}
58+
59+
//base.OnParametersSet();
60+
base.OnAfterRender(firstRender);
61+
62+
}
63+
64+
IQueryable<Widget> GetWidgets(int maxRows, int startRowIndex, string sortByExpression, out int totalRowCount)
65+
{
66+
67+
totalRowCount = Widget.SimpleWidgetList.Length;
68+
69+
return Widget.SimpleWidgetList.AsQueryable();
70+
71+
}
72+
73+
74+
}
75+

samples/AfterBlazorServerSide/Pages/ControlSamples/DataList/Nav.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<NavLink href="/ControlSamples/DataList" class="component-link" Match="NavLinkMatch.All">Simple Table</NavLink> |
44
<NavLink href="/ControlSamples/DataList/Flow" class="component-link" Match="NavLinkMatch.All">Simple Flow</NavLink> |
55
<NavLink href="/ControlSamples/DataList/HeaderStyle" class="component-link" Match="NavLinkMatch.All">Header Style</NavLink> |
6+
<NavLink href="/ControlSamples/DataList/FooterStyle" class="component-link" Match="NavLinkMatch.All">Footer Style</NavLink>
67
<NavLink href="/ControlSamples/DataList/ComplexStyle" class="component-link" Match="NavLinkMatch.All">Complex Style</NavLink>
7-
</div>
8+
</div>

samples/AfterBlazorServerSide/Shared/NavMenu.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<TreeNode NavigateUrl="/ControlSamples/DataList" Text="Simple Table" />
2020
<TreeNode NavigateUrl="/ControlSamples/DataList/Flow" Text="Simple Flow" />
2121
<TreeNode NavigateUrl="/ControlSamples/DataList/HeaderStyle" Text="Header Style" />
22+
<TreeNode NavigateUrl="/ControlSamples/DataList/FooterStyle" Text="Footer Style" />
2223
<TreeNode NavigateUrl="/ControlSamples/DataList/ComplexStyle" Text="Complex Style" />
2324
</TreeNode>
2425

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@inherits TestComponentBase
2+
@using BlazorWebFormsComponents
3+
4+
<Fixture Test="FirstTest">
5+
<ComponentUnderTest>
6+
<DataList Items="Widget.SimpleWidgetList"
7+
ItemType="Widget"
8+
RepeatLayout="Flow"
9+
Context="Item">
10+
<ChildContent>
11+
<FooterStyle CssClass="myClass"></FooterStyle>
12+
</ChildContent>
13+
<FooterTemplate>FooterTemplate</FooterTemplate>
14+
<ItemTemplate>@Item.Name</ItemTemplate>
15+
</DataList>
16+
</ComponentUnderTest>
17+
</Fixture>
18+
19+
@code {
20+
void FirstTest()
21+
{
22+
var cut = GetComponentUnderTest();
23+
Console.WriteLine(cut.Markup);
24+
var footer = cut.Find("span").Children.FirstOrDefault(x => x.InnerHtml.Contains("FooterTemplate"));
25+
var @class = footer.GetAttribute("class");
26+
27+
@class.ShouldNotBeNull();
28+
@class.ShouldBe("myClass");
29+
30+
}
31+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@inherits TestComponentBase
2+
@using BlazorWebFormsComponents
3+
@using System.Linq;
4+
5+
<Fixture Test="FirstTest">
6+
<ComponentUnderTest>
7+
<DataList Items="Widget.SimpleWidgetList"
8+
ItemType="Widget"
9+
RepeatLayout="Flow"
10+
Context="Item">
11+
<FooterTemplate>FooterTemplate</FooterTemplate>
12+
<ItemTemplate>@Item.Name</ItemTemplate>
13+
</DataList>
14+
</ComponentUnderTest>
15+
</Fixture>
16+
17+
@code {
18+
void FirstTest()
19+
{
20+
var cut = GetComponentUnderTest();
21+
Console.WriteLine(cut.Markup);
22+
var footer = cut.Find("span").Children.FirstOrDefault(x => x.InnerHtml.Contains("FooterTemplate"));
23+
24+
footer.HasAttribute("style").ShouldBeFalse();
25+
}
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@inherits TestComponentBase
2+
@using static BlazorWebFormsComponents.WebColor
3+
@using static BlazorWebFormsComponents.Enums.BorderStyle
4+
@using BlazorWebFormsComponents
5+
6+
<Fixture Test="FirstTest">
7+
<ComponentUnderTest>
8+
<DataList Items="Widget.SimpleWidgetList"
9+
ItemType="Widget"
10+
RepeatLayout="Flow"
11+
Context="Item">
12+
<ChildContent>
13+
<FooterStyle BackColor="Blue" BorderStyle="Solid" BorderColor="Black" BorderWidth="2"></FooterStyle>
14+
</ChildContent>
15+
<FooterTemplate>FooterTemplate</FooterTemplate>
16+
<ItemTemplate>@Item.Name</ItemTemplate>
17+
</DataList>
18+
</ComponentUnderTest>
19+
</Fixture>
20+
21+
@code {
22+
void FirstTest()
23+
{
24+
var cut = GetComponentUnderTest();
25+
Console.WriteLine(cut.Markup);
26+
var footer = cut.Find("span").Children.FirstOrDefault(x => x.InnerHtml.Contains("FooterTemplate"));
27+
footer.HasAttribute("style").ShouldBeTrue();
28+
var style = footer.GetAttribute("style");
29+
30+
style.ShouldNotBeNull();
31+
style.ShouldContain("background-color:Blue");
32+
style.ShouldContain("border:2px solid");
33+
}
34+
}

src/BlazorWebFormsComponents.Test/DataList/FlowLayout/HeaderStyleCss.razor renamed to src/BlazorWebFormsComponents.Test/DataList/FlowLayout/HeaderStyleClass.razor

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
//context.WaitForNextRender(() => { }, TimeSpan.FromSeconds(2));
4444
4545
var cut = GetComponentUnderTest();
46+
Console.WriteLine(cut.Markup);
4647

4748
var theHeaderElement = cut.FindAll("span")[1];
4849

@@ -67,4 +68,4 @@
6768

6869
}
6970

70-
}
71+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@inherits TestComponentBase
2+
@using BlazorWebFormsComponents
3+
4+
<Fixture Test="FirstTest">
5+
<ComponentUnderTest>
6+
<DataList Items="Widget.SimpleWidgetList"
7+
ItemType="Widget"
8+
RepeatLayout="Table"
9+
Context="Item">
10+
<ChildContent>
11+
<FooterStyle CssClass="myClass"></FooterStyle>
12+
</ChildContent>
13+
<FooterTemplate>FooterTemplate</FooterTemplate>
14+
<ItemTemplate>@Item.Name</ItemTemplate>
15+
</DataList>
16+
</ComponentUnderTest>
17+
</Fixture>
18+
19+
@code {
20+
void FirstTest()
21+
{
22+
var cut = GetComponentUnderTest();
23+
Console.WriteLine(cut.Markup);
24+
var footer = cut.FindAll("td").FirstOrDefault(x => x.InnerHtml.Contains("FooterTemplate"));
25+
footer.HasAttribute("class").ShouldBeTrue();
26+
var @class = footer.GetAttribute("class");
27+
28+
@class.ShouldNotBeNull();
29+
@class.ShouldBe("myClass");
30+
}
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@inherits TestComponentBase
2+
@using BlazorWebFormsComponents
3+
@using System.Linq;
4+
5+
<Fixture Test="FirstTest">
6+
<ComponentUnderTest>
7+
<DataList Items="Widget.SimpleWidgetList"
8+
ItemType="Widget"
9+
RepeatLayout="Table"
10+
Context="Item">
11+
<FooterTemplate>FooterTemplate</FooterTemplate>
12+
<ItemTemplate>@Item.Name</ItemTemplate>
13+
</DataList>
14+
</ComponentUnderTest>
15+
</Fixture>
16+
17+
@code {
18+
void FirstTest()
19+
{
20+
var cut = GetComponentUnderTest();
21+
Console.WriteLine(cut.Markup);
22+
var footer = cut.FindAll("td").FirstOrDefault(x => x.InnerHtml.Contains("FooterTemplate"));
23+
footer.HasAttribute("style").ShouldBeFalse();
24+
}
25+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@inherits TestComponentBase
2+
@using static BlazorWebFormsComponents.WebColor
3+
@using static BlazorWebFormsComponents.Enums.BorderStyle
4+
@using BlazorWebFormsComponents
5+
6+
<Fixture Test="FirstTest">
7+
<ComponentUnderTest>
8+
<DataList Items="Widget.SimpleWidgetList"
9+
ItemType="Widget"
10+
RepeatLayout="Table"
11+
Context="Item">
12+
<ChildContent>
13+
<FooterStyle BackColor="Blue" BorderStyle="Solid" BorderColor="Black" BorderWidth="2"></FooterStyle>
14+
</ChildContent>
15+
<FooterTemplate>FooterTemplate</FooterTemplate>
16+
<ItemTemplate>@Item.Name</ItemTemplate>
17+
</DataList>
18+
</ComponentUnderTest>
19+
</Fixture>
20+
21+
@code {
22+
void FirstTest()
23+
{
24+
var cut = GetComponentUnderTest();
25+
Console.WriteLine(cut.Markup);
26+
var footer = cut.FindAll("td").FirstOrDefault(x => x.InnerHtml.Contains("FooterTemplate"));
27+
footer.HasAttribute("style").ShouldBeTrue();
28+
var style = footer.GetAttribute("style");
29+
30+
style.ShouldNotBeNull();
31+
style.ShouldContain("background-color:Blue");
32+
style.ShouldContain("border:2px solid");
33+
}
34+
}

0 commit comments

Comments
 (0)