forked from irihitech/Ursa.Avalonia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request irihitech#432 from irihitech/breadcrumb
Fix BreadcrumbItem :last pseudo class for dynamic added items.
- Loading branch information
Showing
9 changed files
with
213 additions
and
3 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
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,10 @@ | ||
<Application xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:semi="https://irihi.tech/semi" | ||
xmlns:u-semi="https://irihi.tech/ursa/themes/semi" | ||
x:Class="HeadlessTest.Ursa.App"> | ||
<Application.Styles> | ||
<semi:SemiTheme /> | ||
<u-semi:SemiTheme/> | ||
</Application.Styles> | ||
</Application> |
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,13 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace HeadlessTest.Ursa; | ||
|
||
public partial class App : Application | ||
{ | ||
public override void Initialize() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
tests/HeadlessTest.Ursa/Controls/BreadcrumbTests/BreadcrumbTests.cs
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,87 @@ | ||
using System.Collections.ObjectModel; | ||
using Avalonia.Controls; | ||
using Avalonia.Headless.XUnit; | ||
using Avalonia.LogicalTree; | ||
using Ursa.Controls; | ||
|
||
namespace HeadlessTest.Ursa.Controls; | ||
|
||
public class BreadcrumbTests | ||
{ | ||
[AvaloniaFact] | ||
public void BreadcrumbItem_Should_Have_Correct_PseudoClasses() | ||
{ | ||
var window = new Window(); | ||
var breadcrumb = new Breadcrumb(); | ||
window.Content = breadcrumb; | ||
window.Show(); | ||
var item1 = new BreadcrumbItem(); | ||
var item2 = new BreadcrumbItem(); | ||
breadcrumb.Items.Add(item1); | ||
Assert.Contains(":last", item1.Classes); | ||
breadcrumb.Items.Add(item2); | ||
Assert.Contains(":last", item2.Classes); | ||
Assert.DoesNotContain(":last", item1.Classes); | ||
} | ||
|
||
[AvaloniaFact] | ||
public void Generated_BreadcrumbItem_Should_Have_Correct_PseudoClasses() | ||
{ | ||
var window = new Window(); | ||
var breadcrumb = new Breadcrumb(); | ||
window.Content = breadcrumb; | ||
window.Show(); | ||
var item1 = new TextBlock(); | ||
var item2 = new TextBlock(); | ||
breadcrumb.Items.Add(item1); | ||
var firstItem = breadcrumb.GetLogicalChildren().OfType<BreadcrumbItem>().FirstOrDefault(); | ||
Assert.NotNull(firstItem); | ||
Assert.Contains(":last", firstItem.Classes); | ||
breadcrumb.Items.Add(item2); | ||
var lastItem = breadcrumb.GetLogicalChildren().OfType<BreadcrumbItem>().LastOrDefault(); | ||
Assert.NotNull(lastItem); | ||
Assert.Contains(":last", lastItem.Classes); | ||
Assert.DoesNotContain(":last", firstItem.Classes); | ||
} | ||
|
||
[AvaloniaFact] | ||
public void BreadcrumbItem_FromItemsSource_Should_Have_Correct_PseudoClasses() | ||
{ | ||
var window = new Window(); | ||
var breadcrumb = new Breadcrumb(); | ||
window.Content = breadcrumb; | ||
window.Show(); | ||
var items = new ObservableCollection<string>(); | ||
breadcrumb.ItemsSource = items; | ||
items.Add("Item 1"); | ||
var item1 = breadcrumb.GetLogicalChildren().OfType<BreadcrumbItem>().FirstOrDefault(); | ||
Assert.NotNull(item1); | ||
Assert.Contains(":last", item1.Classes); | ||
items.Add("Item 2"); | ||
var item2 = breadcrumb.GetLogicalChildren().OfType<BreadcrumbItem>().LastOrDefault(); | ||
Assert.NotNull(item2); | ||
Assert.Contains(":last", item2.Classes); | ||
Assert.DoesNotContain(":last", item1.Classes); | ||
} | ||
|
||
[AvaloniaFact] | ||
public void Bulk_Added_BreadcrumbItem_Should_Have_Correct_PseudoClasses() | ||
{ | ||
var window = new Window(); | ||
var breadcrumb = new Breadcrumb(); | ||
window.Content = breadcrumb; | ||
window.Show(); | ||
var items = new ObservableCollection<string> | ||
{ | ||
"Item 1", | ||
"Item 2" | ||
}; | ||
breadcrumb.ItemsSource = items; | ||
var item1 = breadcrumb.GetLogicalChildren().OfType<BreadcrumbItem>().FirstOrDefault(); | ||
var item2 = breadcrumb.GetLogicalChildren().OfType<BreadcrumbItem>().LastOrDefault(); | ||
Assert.NotNull(item1); | ||
Assert.NotNull(item2); | ||
Assert.Contains(":last", item2.Classes); | ||
Assert.DoesNotContain(":last", item1.Classes); | ||
} | ||
} |
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,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Avalonia.Headless.XUnit" Version="11.1.3" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/> | ||
<PackageReference Include="Semi.Avalonia" Version="11.1.0.4" /> | ||
<PackageReference Include="xunit" Version="2.5.3"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Ursa\Ursa.csproj" /> | ||
<ProjectReference Include="..\..\src\Ursa.Themes.Semi\Ursa.Themes.Semi.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,13 @@ | ||
using Avalonia; | ||
using Avalonia.Headless; | ||
using HeadlessTest.Ursa; | ||
|
||
[assembly: AvaloniaTestApplication(typeof(TestAppBuilder))] | ||
|
||
namespace HeadlessTest.Ursa; | ||
|
||
public class TestAppBuilder | ||
{ | ||
public static AppBuilder BuildAvaloniaApp() => | ||
AppBuilder.Configure<App>().UseHeadless(new AvaloniaHeadlessPlatformOptions()); | ||
} |
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,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"/> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/> | ||
<PackageReference Include="xunit" Version="2.5.3"/> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Ursa\Ursa.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |