ant-design-blazor/tests/tabs/TabsTests.cs

118 lines
3.6 KiB
C#
Raw Normal View History

using System;
using AntDesign.JsInterop;
using Bunit;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.JSInterop;
using Moq;
using Xunit;
namespace AntDesign.Tests.tabs
{
public class TabsTests : AntDesignTestBase
{
private IRenderedComponent<Tabs> CreateTabs(Action<RenderTreeBuilder> childContent)
{
var jsRuntime = new Mock<IJSRuntime>();
jsRuntime.Setup(u => u.InvokeAsync<Element>(JSInteropConstants.GetDomInfo, It.IsAny<object[]>()))
.ReturnsAsync(new Element());
Context.Services.AddScoped(_ => jsRuntime.Object);
var cut = Context.RenderComponent<Tabs>(tabs => tabs
.Add(x => x.DefaultActiveKey, "2")
.Add(b => b.ChildContent, b => childContent(b))
);
return cut;
}
private static RenderFragment CreateTabPanel(string key, Action<ComponentParameterCollectionBuilder<TabPane>> configure = null)
{
var tabPane1Builder = new ComponentParameterCollectionBuilder<TabPane>()
.Add(x => x.Key, key)
.Add(x => x.Tab, $"Tab {key}".ToRenderFragment())
.Add(x => x.ChildContent, $"Content {key}".ToRenderFragment());
configure?.Invoke(tabPane1Builder);
return tabPane1Builder.Build().ToRenderFragment<TabPane>();
}
[Fact]
public void Should_only_render_the_active_pane_when_ForceRender_is_false()
{
var cut = CreateTabs(p =>
{
var tabPane1 = CreateTabPanel("1");
var tabPane2 = CreateTabPanel("2");
tabPane1(p);
tabPane2(p);
});
var renderedPanes = cut.FindAll(".ant-tabs-tabpane");
Assert.Equal(1, renderedPanes.Count);
}
[Fact]
public void Should_render_the_all_panes_when_ForceRender_is_true()
{
var cut = CreateTabs(p =>
{
var tabPane1 = CreateTabPanel("1", x => x.Add(y => y.ForceRender, true));
var tabPane2 = CreateTabPanel("2", x => x.Add(y => y.ForceRender, true));
tabPane1(p);
tabPane2(p);
});
var renderedPanes = cut.FindAll(".ant-tabs-tabpane");
Assert.Equal(2, renderedPanes.Count);
}
[Fact]
public void Should_preserve_tab_panels_once_they_have_been_rendered()
{
var cut = CreateTabs(p =>
{
var tabPane1 = CreateTabPanel("1");
var tabPane2 = CreateTabPanel("2");
tabPane1(p);
tabPane2(p);
});
var renderedPanes = cut.FindAll(".ant-tabs-tabpane", true);
Assert.Equal(1, renderedPanes.Count);
cut.SetParametersAndRender(p => p.Add(x => x.ActiveKey, "1"));
Assert.Equal(2, renderedPanes.Count);
}
[Fact]
public void Clicking_on_an_inactive_tab_should_make_it_active()
{
var cut = CreateTabs(p =>
{
var tabPane1 = CreateTabPanel("1");
var tabPane2 = CreateTabPanel("2");
tabPane1(p);
tabPane2(p);
});
feat(module: overlay): OverlayTrigger not bound to a div (#937) * feat(module:overlay): OverlayTrigger not bound to a div * feat(module:overlay): OverlayTrigger not bound to a div * feat(module:overlay): Logic transfer to single Overlay * feat(module:overlay): remove obsolete duplication * feat(module:Tooltip): Add for unbounded oncontextmenu event handler * feat(module:tooltip): unbound js event listeners remove * docs(module:tooltip): unbound explanation * fix(module:button): attach Ref to top level html element @ref * feat(module:dropdown&tooltip&popconfirm&popover): Overlay not bound to a div * docs(module:dropdown&tooltip&popconfirm&popover): unbound explanation * feat(module:OverlayTrigger): common logic relocation * feat(module:overlaytrigger): Overlay not bound to a div * feat(module:DatePicker): Overlay not bound to a div * feat(module:select): Overlay not boud to div * fix(module:select): onclickarrow event relocation * fix(module:select): rename Show to OnArrowClick * feat(module:avatar): Overlay not bound to a div * docs(module:avatar): demo switch to unbound version * feat(module:autocomplete): partial OverlayTrigger not bound to a div * feat(module:slider): tooltip * docs(module:slider): tooltip * fix(module:overlay): add SetVisible method * feat: set Ref where missing, performance components register Ref when missing IsFixed flag for CascadeValue changed hard-code sequence numbers when using RenderTreeBuilder Rate component use Tooltip Unbound version Tabs test fix * fix: revert changes (accidental) * feat(module:upload): tooltip with unbound usage * feat(module:table): column use of unbound tooltip * feat(module:autocomplete):overlay unbound from div * fix(module:upload): missing div restore Co-authored-by: James Yeung <shunjiey@hotmail.com>
2021-01-21 17:20:10 +08:00
Assert.Equal("Content 2", cut.Find(".ant-tabs-tabpane").TextContent.Trim());
cut.Find("div.ant-tabs-tab").Click();
feat(module: overlay): OverlayTrigger not bound to a div (#937) * feat(module:overlay): OverlayTrigger not bound to a div * feat(module:overlay): OverlayTrigger not bound to a div * feat(module:overlay): Logic transfer to single Overlay * feat(module:overlay): remove obsolete duplication * feat(module:Tooltip): Add for unbounded oncontextmenu event handler * feat(module:tooltip): unbound js event listeners remove * docs(module:tooltip): unbound explanation * fix(module:button): attach Ref to top level html element @ref * feat(module:dropdown&tooltip&popconfirm&popover): Overlay not bound to a div * docs(module:dropdown&tooltip&popconfirm&popover): unbound explanation * feat(module:OverlayTrigger): common logic relocation * feat(module:overlaytrigger): Overlay not bound to a div * feat(module:DatePicker): Overlay not bound to a div * feat(module:select): Overlay not boud to div * fix(module:select): onclickarrow event relocation * fix(module:select): rename Show to OnArrowClick * feat(module:avatar): Overlay not bound to a div * docs(module:avatar): demo switch to unbound version * feat(module:autocomplete): partial OverlayTrigger not bound to a div * feat(module:slider): tooltip * docs(module:slider): tooltip * fix(module:overlay): add SetVisible method * feat: set Ref where missing, performance components register Ref when missing IsFixed flag for CascadeValue changed hard-code sequence numbers when using RenderTreeBuilder Rate component use Tooltip Unbound version Tabs test fix * fix: revert changes (accidental) * feat(module:upload): tooltip with unbound usage * feat(module:table): column use of unbound tooltip * feat(module:autocomplete):overlay unbound from div * fix(module:upload): missing div restore Co-authored-by: James Yeung <shunjiey@hotmail.com>
2021-01-21 17:20:10 +08:00
Assert.Equal("Content 1", cut.Find(".ant-tabs-tabpane").TextContent.Trim());
}
}
}