-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove Template when Dot=True, add Badge Tests, format Badge cl…
…ass.
- Loading branch information
Showing
3 changed files
with
115 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Presenters; | ||
using Avalonia.Controls.Templates; | ||
using Avalonia.Headless.XUnit; | ||
using UrsaControls = Ursa.Controls; | ||
|
||
namespace HeadlessTest.Ursa.Controls.BadgeTests; | ||
|
||
public class BadgeTests | ||
{ | ||
[AvaloniaFact] | ||
public void Badge_Container_Should_DisAppear_If_Header_Is_Null_And_Dot_Equals_False() | ||
{ | ||
// Arrange | ||
var window = new Window(); | ||
var badge = new UrsaControls.Badge | ||
{ | ||
Header = string.Empty, | ||
Dot = true | ||
}; | ||
window.Content = badge; | ||
window.Show(); | ||
|
||
Assert.True(badge.IsVisible); | ||
|
||
var badgeContainer = badge.GetTemplateChildren().OfType<Border>() | ||
.FirstOrDefault(a => a.Name == UrsaControls.Badge.PART_BadgeContainer); | ||
|
||
Assert.NotNull(badgeContainer); | ||
|
||
Assert.True(badgeContainer.IsVisible); | ||
|
||
// Act | ||
badge.Header = null; | ||
// Assert | ||
Assert.True(badgeContainer.IsVisible); | ||
|
||
// Act | ||
badge.Dot = false; | ||
// Assert | ||
Assert.False(badgeContainer.IsVisible); | ||
} | ||
|
||
[AvaloniaFact] | ||
public void Badge_Container_Should_Overflow_If_Number_Larger_Than_OverflowCount() | ||
{ | ||
// Arrange | ||
var window = new Window(); | ||
var badge = new UrsaControls.Badge | ||
{ | ||
Header = 0, | ||
OverflowCount = 10 | ||
}; | ||
window.Content = badge; | ||
window.Show(); | ||
|
||
Assert.True(badge.IsVisible); | ||
|
||
var header = badge.GetTemplateChildren().OfType<ContentPresenter>() | ||
.FirstOrDefault(a => a.Name == UrsaControls.Badge.PART_HeaderPresenter); | ||
|
||
Assert.NotNull(header); | ||
Assert.Equal(header.Content, 0); | ||
|
||
// Act | ||
badge.Header = 10; | ||
|
||
// Assert | ||
Assert.Equal(header.Content, 10); | ||
|
||
// Act | ||
badge.Header = 11; | ||
Assert.Equal(header.Content, "10+"); | ||
|
||
// Act | ||
badge.OverflowCount = 100; | ||
Assert.Equal(header.Content, 11); | ||
} | ||
} |