Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions src/BlazorUI/Bit.BlazorUI.Tests/Toggles/BitToggleTest.razor

This file was deleted.

40 changes: 19 additions & 21 deletions src/BlazorUI/Bit.BlazorUI.Tests/Toggles/BitToggleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class BitToggleTests : BunitTestContext
]
public void BitToggleTest(bool isEnabled, bool value)
{
var com = RenderComponent<BitToggleTest>(parameters =>
var com = RenderComponent<BitToggle>(parameters =>
{
parameters.Add(p => p.IsEnabled, isEnabled);
parameters.Add(p => p.Value, value);
Expand All @@ -41,7 +41,7 @@ public void BitToggleTest(bool isEnabled, bool value)
]
public void BitToggleWithoutOnOffTextShouldHaveClassName(string onText, string offText)
{
var com = RenderComponent<BitToggleTest>(parameters =>
var com = RenderComponent<BitToggle>(parameters =>
{
parameters.Add(p => p.OnText, onText);
parameters.Add(p => p.OffText, offText);
Expand All @@ -60,7 +60,7 @@ public void BitToggleWithoutOnOffTextShouldHaveClassName(string onText, string o
]
public void BitToggleInlineLabelShouldHaveClassName(bool isInlineLabel)
{
var com = RenderComponent<BitToggleTest>(parameters =>
var com = RenderComponent<BitToggle>(parameters =>
{
parameters.Add(p => p.IsInlineLabel, isInlineLabel);
});
Expand All @@ -75,7 +75,7 @@ public void BitToggleInlineLabelShouldHaveClassName(bool isInlineLabel)
[DataTestMethod, DataRow("Detailed AriaLabel")]
public void BitToggleAriaLabelTest(string ariaLabel)
{
var com = RenderComponent<BitToggleTest>(parameters =>
var com = RenderComponent<BitToggle>(parameters =>
{
parameters.Add(p => p.AriaLabel, ariaLabel);
});
Expand All @@ -92,7 +92,7 @@ public void BitToggleAriaLabelTest(string ariaLabel)
]
public void BitToggleAriaLabelledbyTest(bool value, string onText, string offText, string defaultText, string label)
{
var com = RenderComponent<BitToggleTest>(parameters =>
var com = RenderComponent<BitToggle>(parameters =>
{
parameters.Add(p => p.Value, value);
parameters.Add(p => p.OnText, onText);
Expand All @@ -104,9 +104,9 @@ public void BitToggleAriaLabelledbyTest(bool value, string onText, string offTex

var bitToggleButton = com.Find("button");


var labelId = bitToggleButton.Id.Replace("Button", "Label");

var stateTextId = bitToggleButton.Id.Replace("Button", "StateText");

var ariaLabelledById = string.Empty;
Expand All @@ -122,8 +122,6 @@ public void BitToggleAriaLabelledbyTest(bool value, string onText, string offTex
ariaLabelledById = ariaLabelledById.HasValue() ? $"{labelId} {stateTextId}" : stateTextId;
}

var aa = bitToggleButton.GetAttribute("aria-labelledby");

Assert.AreEqual(bitToggleButton.GetAttribute("aria-labelledby"), ariaLabelledById);
}

Expand All @@ -133,7 +131,7 @@ public void BitToggleAriaLabelledbyTest(bool value, string onText, string offTex
]
public void BitToggleAriaCheckedTest(bool value)
{
var com = RenderComponent<BitToggleTest>(parameters =>
var com = RenderComponent<BitToggle>(parameters =>
{
parameters.Add(p => p.Value, value);
});
Expand All @@ -146,7 +144,7 @@ public void BitToggleAriaCheckedTest(bool value)
[DataTestMethod, DataRow("Switch")]
public void BitToggleRoleTest(string role)
{
var com = RenderComponent<BitToggleTest>(parameters =>
var com = RenderComponent<BitToggle>(parameters =>
{
parameters.Add(p => p.Role, role);
});
Expand All @@ -170,7 +168,7 @@ public void BitToggleLabel(string label)
[DataTestMethod, DataRow("<div>This is labelTemplate</div>")]
public void BitToggleMarkupLabelTest(string labelTemplate)
{
var com = RenderComponent<BitToggleTest>(parameters =>
var com = RenderComponent<BitToggle>(parameters =>
{
parameters.Add(p => p.LabelTemplate, labelTemplate);
});
Expand All @@ -194,15 +192,15 @@ public void BitToggleValidationFormTest(bool value)
var form = com.Find("form");
form.Submit();

Assert.AreEqual(com.Instance.ValidCount, value ? 0 : 1);
Assert.AreEqual(com.Instance.InvalidCount, value ? 1 : 0);
Assert.AreEqual(value ? 0 : 1, com.Instance.ValidCount);
Assert.AreEqual(value ? 1 : 0, com.Instance.InvalidCount);

var button = com.Find("button");
button.Click();
form.Submit();

Assert.AreEqual(com.Instance.ValidCount, 1);
Assert.AreEqual(com.Instance.InvalidCount, 1);
Assert.AreEqual(1, com.Instance.ValidCount);
Assert.AreEqual(1, com.Instance.InvalidCount);
Assert.AreEqual(com.Instance.ValidCount, com.Instance.InvalidCount);
}

Expand All @@ -224,16 +222,16 @@ public void BitToggleValidationInvalidHtmlAttributeTest(bool value)
var form = com.Find("form");
form.Submit();

Assert.AreEqual(checkBox.HasAttribute("aria-invalid"), value);
Assert.AreEqual(value, checkBox.HasAttribute("aria-invalid"));
if (checkBox.HasAttribute("aria-invalid"))
{
Assert.AreEqual(checkBox.GetAttribute("aria-invalid"), "true");
Assert.AreEqual("true", checkBox.GetAttribute("aria-invalid"));
}

var button = com.Find("button");
button.Click();

Assert.AreEqual(checkBox.HasAttribute("aria-invalid"), !value);
Assert.AreEqual(value is false, checkBox.HasAttribute("aria-invalid"));
}

[DataTestMethod,
Expand All @@ -255,11 +253,11 @@ public void BitToggleValidationInvalidCssClassTest(bool value)
var form = com.Find("form");
form.Submit();

Assert.AreEqual(bitToggle.ClassList.Contains("invalid"), value);
Assert.AreEqual(value, bitToggle.ClassList.Contains("invalid"));

var button = com.Find("button");
button.Click();

Assert.AreEqual(bitToggle.ClassList.Contains("invalid"), !value);
Assert.AreEqual(value is false, bitToggle.ClassList.Contains("invalid"));
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
<EditForm Model="@TestModel" OnValidSubmit="@HandleValidSubmit" OnInvalidSubmit="@HandleInvalidSubmit">
<DataAnnotationsValidator />

<CascadingValue Value="Visual">
<BitToggle IsEnabled="IsEnabled"
@bind-Value="@TestModel.Value"
IsInlineLabel="IsInlineLabel"
OnText="@OnText"
OffText="@OffText"
AriaLabel="@AriaLabel"
Role="@Role"
Label="@Label">
<LabelTemplate>
@LabelTemplate
</LabelTemplate>
</BitToggle>
</CascadingValue>
<BitToggle IsEnabled="IsEnabled"
@bind-Value="@TestModel.Value"
IsInlineLabel="IsInlineLabel"
OnText="@OnText"
OffText="@OffText"
AriaLabel="@AriaLabel"
Role="@Role"
Label="@Label">
<LabelTemplate>
@LabelTemplate
</LabelTemplate>
</BitToggle>

</EditForm>

@code {
[Parameter] public Visual Visual { get; set; }
[Parameter] public bool IsEnabled { get; set; }
[Parameter] public bool IsInlineLabel { get; set; }
[Parameter] public string OnText { get; set; }
Expand Down