Skip to content

Commit

Permalink
Merge pull request #992 from ironmansoftware/941
Browse files Browse the repository at this point in the history
Fixes #941
  • Loading branch information
adamdriscoll authored Jul 30, 2019
2 parents 93d4b09 + 4e8c19f commit a7012a9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/UniversalDashboard.Materialize/Components/ud-checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
23 changes: 23 additions & 0 deletions src/UniversalDashboard.Materialize/Tests/checkbox.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit a7012a9

Please sign in to comment.