From 677a1b5be7c9676634e0b9a95c510f1bb6e1ad93 Mon Sep 17 00:00:00 2001
From: Safia Abdalla
Date: Thu, 27 Feb 2020 09:23:29 -0800
Subject: [PATCH] Add tests for short values in BindTests
---
src/Components/test/E2ETest/Tests/BindTest.cs | 59 +++++++++++++++++++
.../BasicTestApp/BindCasesComponent.razor | 14 +++++
2 files changed, 73 insertions(+)
diff --git a/src/Components/test/E2ETest/Tests/BindTest.cs b/src/Components/test/E2ETest/Tests/BindTest.cs
index cefd842022..70fc700e89 100644
--- a/src/Components/test/E2ETest/Tests/BindTest.cs
+++ b/src/Components/test/E2ETest/Tests/BindTest.cs
@@ -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()
{
diff --git a/src/Components/test/testassets/BasicTestApp/BindCasesComponent.razor b/src/Components/test/testassets/BasicTestApp/BindCasesComponent.razor
index 45d5eacdcc..217c8dc65a 100644
--- a/src/Components/test/testassets/BasicTestApp/BindCasesComponent.razor
+++ b/src/Components/test/testassets/BasicTestApp/BindCasesComponent.razor
@@ -50,6 +50,18 @@
@textboxNullableLongValue
+
+ short:
+
+ @textboxLongValue
+
+
+
+ Nullable short:
+
+ @textboxNullableShortValue
+
+
float:
@@ -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;