From 1f278a8b77bc18917a7aad37cb9418bb025cd99a Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Sun, 23 Jun 2019 18:58:06 -0500 Subject: [PATCH] Fixes #872 --- .../Components/ud-select.jsx | 16 ++++----- .../Tests/select.tests.ps1 | 36 +++++++++++++++++-- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/UniversalDashboard.Materialize/Components/ud-select.jsx b/src/UniversalDashboard.Materialize/Components/ud-select.jsx index 6538ae7d..31b8629a 100644 --- a/src/UniversalDashboard.Materialize/Components/ud-select.jsx +++ b/src/UniversalDashboard.Materialize/Components/ud-select.jsx @@ -29,10 +29,6 @@ export default class UDSelect extends React.Component { } onChange(e) { - if (this.props.onChange == null) { - return - } - var val = new Array(); if (e.target.selectedOptions) { @@ -53,16 +49,20 @@ export default class UDSelect extends React.Component { val = JSON.stringify(val); } + this.setState({ + value: val + }) + + if (this.props.onChange == null) { + return + } + UniversalDashboard.publish('element-event', { type: "clientEvent", eventId: this.props.onChange, eventName: 'onChange', eventData: val }); - - this.setState({ - value: val - }) } render() { diff --git a/src/UniversalDashboard.Materialize/Tests/select.tests.ps1 b/src/UniversalDashboard.Materialize/Tests/select.tests.ps1 index a3bcf403..0ec643f8 100644 --- a/src/UniversalDashboard.Materialize/Tests/select.tests.ps1 +++ b/src/UniversalDashboard.Materialize/Tests/select.tests.ps1 @@ -35,13 +35,45 @@ Describe "Select" { Start-Sleep 1 - $Element = Find-SeElement -XPath "//ul/li" -Element $Element | Select-Object -Skip 1 -First 1 + $Element = Find-SeElement -XPath "//ul/li" -Element $Element | Select-Object -Skip 2 -First 1 Invoke-SeClick -Element $Element $Button = Find-SeElement -Driver $Driver -Id 'btn' Invoke-SeClick -Element $Button - Get-TestData | Should be "2" + Get-TestData | Should be "3" + } + } + + Context "Get-UDElement" { + Set-TestDashboard -Content { + + New-UDButton -Text "Button" -Id 'btn' -OnClick { + $Value = (Get-UDElement -Id 'test').Attributes['value'] + + Set-TestData -Data $Value + } + + New-UDSelect -Label "Test" -Id 'test' -Option { + New-UDSelectOption -Nam "Test 1" -Value "1" + New-UDSelectOption -Nam "Test 2" -Value "2" + New-UDSelectOption -Nam "Test 3" -Value "3" + } + } + + It "should select item and get it with Get-UDElement" { + $Element = Find-SeElement -ClassName "select-wrapper" -Driver $Driver | Select-Object -First 1 + Invoke-SeClick -Element $Element + + Start-Sleep 1 + + $Element = Find-SeElement -XPath "//ul/li" -Element $Element | Select-Object -Skip 2 -First 1 + Invoke-SeClick -Element $Element + + $Button = Find-SeElement -Driver $Driver -Id 'btn' + Invoke-SeClick -Element $Button + + Get-TestData | Should be "3" } } } \ No newline at end of file