Skip to content

Commit

Permalink
Fixes #1095 (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll authored Sep 25, 2019
1 parent 5d972f7 commit 3931a7f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
40 changes: 36 additions & 4 deletions src/UniversalDashboard.UITest/Integration/Input.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -27,7 +61,7 @@ Describe "Input" {
)
}
}

$Server.DashboardService.SetDashboard($Dashboard)
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"

Expand All @@ -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" {
Expand Down
15 changes: 14 additions & 1 deletion src/UniversalDashboard/Cmdlets/Inputs/NewInputFieldCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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));
Expand Down

0 comments on commit 3931a7f

Please sign in to comment.