mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-05 05:27:37 +08:00
555fdb9a43
* fix(module:checkbox): allow binding to Checked parameter * fix(module:switch): allow binding to Checked parameter * fix(modules): checkbox & switch get AntInputBoolComponentBase class * test(module:switch): add tests * test(module:checkbox): add tests * test(module:divider): simplify by using id:ignore * docs(module:checkbox): bind example * docs(module:switch): bind example * fix(module:switch): add Control + docs + tests * feat(module:checkboxgroup): add layout and mixed mode * fix: review comments + tests * fix(module:checkboxgroup): parameter name should be MixedMode added more tests * fix demo * fix(module:checkboxgroup): allow toggling between modes Co-authored-by: James Yeung <shunjiey@hotmail.com>
113 lines
2.9 KiB
C#
113 lines
2.9 KiB
C#
@inherits AntDesignTestBase
|
|
@code {
|
|
[Fact]
|
|
public void Renders_basic_switch()
|
|
{
|
|
var cut = Render(@<Switch/>);
|
|
cut.MarkupMatches(
|
|
@<button type="button" role="switch" aria-checked="false" class="ant-switch" ant-click-animating="false">
|
|
<div class="ant-switch-handle"></div>
|
|
<span class="ant-switch-inner"> </span>
|
|
<div class="ant-click-animating-node"></div>
|
|
</button>);
|
|
}
|
|
|
|
[Fact]
|
|
public void Toggle_basic_switch()
|
|
{
|
|
//Arrange
|
|
IRenderedComponent<Switch> cut = Render<Switch>(@<Switch/>);
|
|
Switch switchComponent = cut.Instance;
|
|
var buttonElement = cut.Find("button");
|
|
var oldValue = switchComponent.Checked;
|
|
//Act
|
|
buttonElement.Click();
|
|
|
|
//Assert
|
|
Assert.True(switchComponent.Checked);
|
|
Assert.NotEqual(oldValue, switchComponent.Checked);
|
|
}
|
|
|
|
[Fact]
|
|
public void Bind_Checked_basic_switch()
|
|
{
|
|
//Arrange
|
|
bool isChecked = false;
|
|
var cut = Render(@<Switch @bind-Checked=isChecked/>);
|
|
var buttonElement = cut.Find("button");
|
|
//Act
|
|
buttonElement.Click();
|
|
//Assert
|
|
Assert.True(isChecked);
|
|
}
|
|
|
|
[Fact]
|
|
public void Bind_Value_basic_switch()
|
|
{
|
|
//Arrange
|
|
bool isChecked = false;
|
|
var cut = Render(@<Switch @bind-Value=isChecked/>);
|
|
var buttonElement = cut.Find("button");
|
|
//Act
|
|
buttonElement.Click();
|
|
//Assert
|
|
Assert.True(isChecked);
|
|
}
|
|
|
|
[Fact]
|
|
public void Renders_switch_with_text()
|
|
{
|
|
string onChild = "On", offChild = "Off";
|
|
var cut = Render(@<Switch Checked="false" CheckedChildren=@onChild UnCheckedChildren=@offChild/>);
|
|
var buttonElement = cut.Find("button");
|
|
var spanWithOffText = cut.Find("span.ant-switch-inner");
|
|
string actuallOffText = spanWithOffText.TextContent.Trim();
|
|
//Act
|
|
buttonElement.Click();
|
|
//Assert
|
|
var spanWithOnText = cut.Find("span.ant-switch-inner");
|
|
Assert.Equal(offChild, actuallOffText );
|
|
Assert.Equal(onChild, spanWithOnText.TextContent.Trim());
|
|
}
|
|
|
|
[Fact]
|
|
public void Fires_OnChange()
|
|
{
|
|
//Arrange
|
|
bool handlerExecuted = false;
|
|
Action<bool> onChangeHandler = value => { handlerExecuted = true; };
|
|
var cut = Render(@<Switch OnChange="onChangeHandler"/>);
|
|
var buttonElement = cut.Find("button");
|
|
//Act
|
|
buttonElement.Click();
|
|
//Assert
|
|
Assert.True(handlerExecuted);
|
|
}
|
|
|
|
[Fact]
|
|
public void Fires_OnClick()
|
|
{
|
|
//Arrange
|
|
bool handlerExecuted = false;
|
|
Action onClickHandler = () => { handlerExecuted = true; };
|
|
var cut = Render(@<Switch OnClick="onClickHandler"/>);
|
|
var buttonElement = cut.Find("button");
|
|
//Act
|
|
buttonElement.Click();
|
|
//Assert
|
|
Assert.True(handlerExecuted);
|
|
}
|
|
|
|
[Fact]
|
|
public void Control_parameter()
|
|
{
|
|
//Arrange
|
|
bool isChecked = false;
|
|
var cut = Render(@<Switch @bind-Value=@isChecked Control/>);
|
|
var buttonElement = cut.Find("button");
|
|
//Act
|
|
buttonElement.Click();
|
|
//Assert
|
|
Assert.False(isChecked);
|
|
}
|
|
} |