mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-04 21:17:36 +08:00
test(module: divider): divider tests (#1397)
Co-authored-by: James Yeung <shunjiey@hotmail.com>
This commit is contained in:
parent
efbdf684d3
commit
68966ef511
@ -3,18 +3,17 @@ using System.Globalization;
|
||||
using Bunit;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace AntDesign.Tests
|
||||
{
|
||||
public class AntDesignTestBase : IDisposable
|
||||
public class AntDesignTestBase : TestContext, IDisposable
|
||||
{
|
||||
public TestContext Context { get; }
|
||||
public TestNavigationManager NavigationManager { get; }
|
||||
|
||||
protected TestContext Context => this;
|
||||
|
||||
public AntDesignTestBase()
|
||||
{
|
||||
Context = new TestContext();
|
||||
NavigationManager = new TestNavigationManager();
|
||||
|
||||
Context.Services.AddScoped<NavigationManager>(sp => NavigationManager);
|
||||
|
@ -6,16 +6,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="bunit.web" Version="1.0.0-preview-01" />
|
||||
<PackageReference Include="bunit.xunit" Version="1.0.0-preview-01" />
|
||||
<PackageReference Include="bunit.web" Version="1.0.19" />
|
||||
<PackageReference Include="bunit.xunit" Version="1.0.0-preview-02" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
|
||||
<PackageReference Include="Moq" Version="4.15.1" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="1.3.0">
|
||||
<PackageReference Include="coverlet.collector" Version="3.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
51
tests/AntDesign.Tests/Divider/DividerTests.razor
Normal file
51
tests/AntDesign.Tests/Divider/DividerTests.razor
Normal file
@ -0,0 +1,51 @@
|
||||
@inherits AntDesignTestBase
|
||||
@code {
|
||||
[Fact]
|
||||
public void Renders_basic_divider()
|
||||
{
|
||||
var cut = Context.Render(@<AntDesign.Divider/>);
|
||||
var id = (cut.Nodes.First() as IElement).GetAttribute("id");
|
||||
cut.MarkupMatches(@<span class="ant-divider ant-divider-horizontal" id="@id"></span>);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Renders_divider_with_title()
|
||||
{
|
||||
var style = "font-weight:bold";
|
||||
var orientation = "left";
|
||||
|
||||
var cut = Context.Render(@<AntDesign.Divider Orientation="@orientation" Style="@style">A Title</AntDesign.Divider>);
|
||||
var id = (cut.Nodes.First() as IElement).GetAttribute("id");
|
||||
cut.MarkupMatches(
|
||||
@<span class="ant-divider ant-divider-horizontal ant-divider-with-text ant-divider-with-text-left" style="@style" id="@id">
|
||||
<span class="ant-divider-inner-text">A Title</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Renders_divider_vertical()
|
||||
{
|
||||
var cut = Context.Render(
|
||||
@<text>
|
||||
Text
|
||||
<AntDesign.Divider Type=@DirectionVHType.Vertical/>
|
||||
<a href="#">Link 1</a>
|
||||
<AntDesign.Divider Type=@DirectionVHType.Vertical/>
|
||||
<a href="#">Link 2</a>
|
||||
</text>
|
||||
);
|
||||
var spanNodes = cut.Nodes.GetElementsByTagName("span");
|
||||
var id1 = spanNodes.First().GetAttribute("id");
|
||||
var id2 = spanNodes.Last().GetAttribute("id");
|
||||
cut.MarkupMatches(
|
||||
@<text>
|
||||
Text
|
||||
<span class="ant-divider ant-divider-vertical" id="@id1"></span>
|
||||
<a href="#">Link 1</a>
|
||||
<span class="ant-divider ant-divider-vertical" id="@id2"></span>
|
||||
<a href="#">Link 2</a>
|
||||
</text>
|
||||
);
|
||||
}
|
||||
}
|
9
tests/AntDesign.Tests/_Imports.razor
Normal file
9
tests/AntDesign.Tests/_Imports.razor
Normal file
@ -0,0 +1,9 @@
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.JSInterop
|
||||
@using Microsoft.Extensions.DependencyInjection
|
||||
@using AngleSharp.Dom
|
||||
@using Bunit
|
||||
@using Bunit.TestDoubles
|
||||
@using Xunit
|
||||
@using Moq
|
Loading…
Reference in New Issue
Block a user