Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(module:divider): divider tests #1397

Merged
merged 2 commits into from Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions tests/AntDesign.TestKit/AntDesignTestBase.cs
Expand Up @@ -3,18 +3,17 @@
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);
Expand Down
8 changes: 4 additions & 4 deletions tests/AntDesign.Tests/AntDesign.Tests.csproj
Expand Up @@ -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>
Expand Down
51 changes: 51 additions & 0 deletions tests/AntDesign.Tests/Divider/DividerTests.razor
@@ -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 changes: 9 additions & 0 deletions tests/AntDesign.Tests/_Imports.razor
@@ -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