Skip to content

Commit 6e7c2ec

Browse files
authored
Add LinkButton unit tests (#142)
1 parent f0f0d12 commit 6e7c2ec

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@inherits TestComponentBase
2+
3+
<Fixture Test="FirstTest">
4+
<ComponentUnderTest>
5+
<LinkButton OnClick="OnClick">Click me!</LinkButton>
6+
</ComponentUnderTest>
7+
</Fixture>
8+
9+
@code{
10+
public string TheContent { get; set; } = "Not clicked yet!";
11+
12+
void OnClick()
13+
{
14+
TheContent = "I've been clicked";
15+
}
16+
17+
void FirstTest()
18+
{
19+
// Given
20+
var cut = GetComponentUnderTest();
21+
22+
TheContent.ShouldBe("Not clicked yet!");
23+
24+
// When
25+
cut.Find("a").Click();
26+
27+
// Then
28+
TheContent.ShouldBe("I've been clicked");
29+
}
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@inherits TestComponentBase
2+
3+
<Fixture Test="FirstTest">
4+
<ComponentUnderTest>
5+
<LinkButton CommandName="Foo" CommandArgument="CommandArgument" OnCommand="OnCommand">Click me!</LinkButton>
6+
</ComponentUnderTest>
7+
</Fixture>
8+
9+
@code{
10+
public string TheContent { get; set; } = "No Command yet!";
11+
12+
public string CommandArgument = "bar";
13+
14+
void OnCommand(CommandEventArgs args)
15+
{
16+
TheContent = $"Command '{args.CommandName}' : '{args.CommandArgument.ToString()}'";
17+
}
18+
19+
void FirstTest()
20+
{
21+
// Given
22+
var cut = GetComponentUnderTest();
23+
24+
TheContent.ShouldBe("No Command yet!");
25+
26+
// When
27+
cut.Find("a").Click();
28+
29+
// Then
30+
TheContent.ShouldBe("Command 'Foo' : 'bar'");
31+
32+
}
33+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@inherits TestComponentBase
2+
3+
<SnapshotTest Description="Verify HTML format of LinkButton">
4+
<TestInput>
5+
<LinkButton Text="Go to Bing!!" PostBackUrl="https://www.bing.com" />
6+
</TestInput>
7+
<ExpectedOutput>
8+
<a href="https://www.bing.com">Go to Bing!!</a>
9+
</ExpectedOutput>
10+
</SnapshotTest>

0 commit comments

Comments
 (0)