diff --git a/src/UniversalDashboard.UITest/Integration/Input.Tests.ps1 b/src/UniversalDashboard.UITest/Integration/Input.Tests.ps1 index 60a5b415..4ba6c85d 100644 --- a/src/UniversalDashboard.UITest/Integration/Input.Tests.ps1 +++ b/src/UniversalDashboard.UITest/Integration/Input.Tests.ps1 @@ -13,6 +13,40 @@ $Server = Start-UDDashboard -Port 10001 -Dashboard (New-UDDashboard -Title "Test $Driver = Start-SeFirefox Describe "Input" { + Context "uses correct type" { + $Dashboard = New-UDDashboard -Title "Test" -Content { + New-UDInput -Title "Simple Form" -Id "Form" -Content { + New-UDInputField -Name 'checkbox' -Type 'checkbox' + New-UDInputField -Name 'textbox' -Type 'textbox' + } -Endpoint { + param($checkbox, $textbox) + + $Cache:Data = @{ + checkbox = $checkbox + textbox = $textbox + } + + $Server.DashboardService.SetDashboard($Dashboard) + Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort" + + It "should set correct value types" { + + $Element = Find-SeElement -Id "textbox" -Driver $Driver + Send-SeKeys -Element $Element -Keys "hello" + + $Element = Find-SeElement -Id "checkbox" -Driver $Driver + Invoke-SeClick -Element $Element -JavaScriptClick -Driver $Driver + + $Button = Find-SeElement -Id "btnForm" -Driver $Driver + Invoke-SeClick $Button + + Start-Sleep 2 + + $Cache:Data.textbox.GetType().Name | Should be "string" + $Cache:Data.checkbox.GetType().Name | Should be "boolean" + } + } + Context "validate with content\endpoint" { $Dashboard = New-UDDashboard -Title "Test" -Content { New-UDInput -Title 'Request' -Validate -Content { @@ -27,7 +61,7 @@ Describe "Input" { ) } } - + $Server.DashboardService.SetDashboard($Dashboard) Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort" @@ -41,9 +75,7 @@ Describe "Input" { Send-SeKeys -Element $Element -Keys 'a' (Find-SeElement -Id 'MyFieldtooltip' -Driver $Driver).getAttribute("textContent") | should be 'MyField is required.' - } - - + } } Context "drops to pipeline" { diff --git a/src/UniversalDashboard/Cmdlets/Inputs/NewInputFieldCommand.cs b/src/UniversalDashboard/Cmdlets/Inputs/NewInputFieldCommand.cs index 74ee977e..dcf31eff 100644 --- a/src/UniversalDashboard/Cmdlets/Inputs/NewInputFieldCommand.cs +++ b/src/UniversalDashboard/Cmdlets/Inputs/NewInputFieldCommand.cs @@ -48,6 +48,18 @@ protected override void EndProcessing() { DefaultValue = Values[0]; } + + var type = typeof(string); + switch(Type.ToLower()) + { + case "checkbox": + type = typeof(bool); + break; + case "date": + type = typeof(DateTime); + break; + } + var field = new Field { Name = Name, @@ -58,7 +70,8 @@ protected override void EndProcessing() Type = Type, OkText = OkText, CancelText = CancelText, - ClearText = ClearText + ClearText = ClearText, + DotNetType = type.FullName }; Log.Debug(JsonConvert.SerializeObject(field));