From 4e8c19fbc7d4d23cbf813c80b238e127a7ff85fc Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Tue, 30 Jul 2019 14:20:05 -0600 Subject: [PATCH] Fixes #941 --- .../Components/ud-checkbox.jsx | 31 +++++++++++++++++++ .../Tests/checkbox.tests.ps1 | 23 ++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/UniversalDashboard.Materialize/Components/ud-checkbox.jsx b/src/UniversalDashboard.Materialize/Components/ud-checkbox.jsx index 4e0fa5fc..3a75a95a 100644 --- a/src/UniversalDashboard.Materialize/Components/ud-checkbox.jsx +++ b/src/UniversalDashboard.Materialize/Components/ud-checkbox.jsx @@ -3,7 +3,38 @@ import {Checkbox} from 'react-materialize'; export default class UDCheckbox extends React.Component { + constructor(props) { + super(props); + + this.state = { + checked: props.checked + } + } + + componentWillMount() { + this.pubSubToken = PubSub.subscribe(this.props.id, this.onIncomingEvent.bind(this)); + } + + componentWillUnmount() { + PubSub.unsubscribe(this.pubSubToken); + } + + onIncomingEvent(eventName, event) { + if (event.type === "requestState") { + UniversalDashboard.post(`/api/internal/component/element/sessionState/${event.requestId}`, { + attributes: { + checked: this.state.checked + } + }); + } + } + onChanged(e) { + + this.setState({ + checked: e.target.checked + }); + if (this.props.onChange == null) { return } diff --git a/src/UniversalDashboard.Materialize/Tests/checkbox.tests.ps1 b/src/UniversalDashboard.Materialize/Tests/checkbox.tests.ps1 index 3212d035..601f7d2e 100644 --- a/src/UniversalDashboard.Materialize/Tests/checkbox.tests.ps1 +++ b/src/UniversalDashboard.Materialize/Tests/checkbox.tests.ps1 @@ -44,4 +44,27 @@ Describe "Checkbox" { Get-TestData | should be $true } } + + Context "Get-UDElement" { + Set-TestDashboard { + New-UDCheckbox -Id "Test" -Label "Check me" + + New-UDElement -Tag div -Id 'Result' -Endpoint { + try { + New-UDElement -Tag div -Content { (Get-UDElement -Id 'Test').Attributes['checked'].ToString() } + } + catch { + + } + } -AutoRefresh -RefreshInterval 1 + } + + It "should check item" { + $Element = Find-SeElement -Id 'Test' -Driver $Driver + Invoke-SeClick -Element $Element -JavaScriptClick -Driver $Driver + Start-Sleep 3 + + (Find-SeElement -Id 'Result' -Driver $Driver).Text | Should be "true" + } + } } \ No newline at end of file