Add tests for short values in BindTests

This commit is contained in:
Safia Abdalla 2020-02-27 09:23:29 -08:00 committed by Ryan Nowak
parent 1407d9ab05
commit 677a1b5be7
2 changed files with 73 additions and 0 deletions

View File

@ -355,6 +355,65 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
Assert.Equal(string.Empty, mirrorValue.GetAttribute("value"));
}
[Fact]
public void CanBindTextboxShort()
{
var target = Browser.FindElement(By.Id("textbox-short"));
var boundValue = Browser.FindElement(By.Id("textbox-short-value"));
var mirrorValue = Browser.FindElement(By.Id("textbox-short-mirror"));
Assert.Equal("-42", target.GetAttribute("value"));
Assert.Equal("-42", boundValue.Text);
Assert.Equal("-42", mirrorValue.GetAttribute("value"));
// Clear target; value resets to zero
target.Clear();
Browser.Equal("0", () => target.GetAttribute("value"));
Assert.Equal("0", boundValue.Text);
Assert.Equal("0", mirrorValue.GetAttribute("value"));
// Modify target; verify value is updated and that textboxes linked to the same data are updated
// Leading zeros are not preserved
target.SendKeys("42");
Browser.Equal("042", () => target.GetAttribute("value"));
target.SendKeys("\t");
Browser.Equal("42", () => target.GetAttribute("value"));
Assert.Equal("42", boundValue.Text);
Assert.Equal("42", mirrorValue.GetAttribute("value"));
}
[Fact]
public void CanBindTextboxNullableShort()
{
var target = Browser.FindElement(By.Id("textbox-nullable-short"));
var boundValue = Browser.FindElement(By.Id("textbox-nullable-short-value"));
var mirrorValue = Browser.FindElement(By.Id("textbox-nullable-short-mirror"));
Assert.Equal(string.Empty, target.GetAttribute("value"));
Assert.Equal(string.Empty, boundValue.Text);
Assert.Equal(string.Empty, mirrorValue.GetAttribute("value"));
// Modify target; verify value is updated and that textboxes linked to the same data are updated
target.Clear();
Browser.Equal("", () => boundValue.Text);
Assert.Equal("", mirrorValue.GetAttribute("value"));
// Modify target; verify value is updated and that textboxes linked to the same data are updated
target.SendKeys("-42\t");
Browser.Equal("-42", () => boundValue.Text);
Assert.Equal("-42", mirrorValue.GetAttribute("value"));
// Modify target; verify value is updated and that textboxes linked to the same data are updated
target.Clear();
target.SendKeys("42\t");
Browser.Equal("42", () => boundValue.Text);
Assert.Equal("42", mirrorValue.GetAttribute("value"));
// Modify target; verify value is updated and that textboxes linked to the same data are updated
target.Clear();
target.SendKeys("\t");
Browser.Equal(string.Empty, () => boundValue.Text);
Assert.Equal(string.Empty, mirrorValue.GetAttribute("value"));
}
[Fact]
public void CanBindTextboxFloat()
{

View File

@ -50,6 +50,18 @@
<span id="textbox-nullable-long-value">@textboxNullableLongValue</span>
<input id="textbox-nullable-long-mirror" @bind="textboxNullableLongValue" readonly />
</p>
<p>
short:
<input id="textbox-short" @bind="textboxShortValue" type="number" />
<span id="textbox-short-value">@textboxLongValue</span>
<input id="textbox-short-mirror" @bind="textboxShortValue" readonly />
</p>
<p>
Nullable short:
<input id="textbox-nullable-short" @bind="textboxNullableShortValue" type="number" />
<span id="textbox-nullable-short-value">@textboxNullableShortValue</span>
<input id="textbox-nullable-short-mirror" @bind="textboxNullableShortValue" readonly />
</p>
<p>
float:
<input id="textbox-float" @bind-value="textboxFloatValue" type="number" />
@ -328,6 +340,8 @@
int? textboxNullableIntValue = null;
long textboxLongValue = 3_000_000_000;
long? textboxNullableLongValue = null;
short textboxShortValue = -42;
short? textboxNullableShortValue = null;
float textboxFloatValue = 3.141f;
float? textboxNullableFloatValue = null;
double textboxDoubleValue = 3.14159265359d;