Skip to content

Commit

Permalink
Tree view tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll committed Aug 20, 2018
1 parent c8df3aa commit b80a642
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 39 deletions.
51 changes: 51 additions & 0 deletions examples/tree-view/filesystem.ps1
@@ -0,0 +1,51 @@
$Dashboard = New-UdDashboard -Title "Tree View" -Content {
New-UDRow -Columns {
New-UDColumn -Size 3 -Content {
$Root = New-UDTreeNode -Name 'FileSystem' -Id 'FileSystem'
New-UDTreeView -ActiveBackgroundColor '#DFE8E4' -Node $Root -OnNodeClicked {
param($Body)

$Depth = [int]$Obj.NodeId

if ($Obj.NodeId -eq 'FileSystem') {
Get-PSDrive -PSProvider FileSystem | ForEach-Object {
New-UDTreeNode -Name $_.Root -Id $_.Root -Icon hdd_o
}
} else {

Get-ChildItem -Path $Obj.NodeId | ForEach-Object {
if ($Obj.NodeId -eq $_.FullName) {
return;
}

if ($_.PSIsContainer) {
New-UDTreeNode -Name $_.Name -Id $_.FullName -Icon folder
} else {
New-UDTreeNode -Name $_.Name -Id $_.FullName -Icon file_text
}

} | ConvertTo-JsonEx

Set-UDElement -Id "properties" -Content {
New-UDGrid -Title $Obj.NodeId -Headers @("Name", "Value") -Properties @("Name", "Value") -Endpoint {
$Obj = $ArgumentList[0]
(Get-ItemProperty -Path $Obj.NodeId).PSObject.Properties | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Value = if ( $_.Value -eq $null) { "" } else { $_.Value.ToString() }
}
} | Out-UDGridData
} -ArgumentList $Obj
}
}
}
}
New-UDColumn -Size 9 -Content {
New-UDElement -Tag "div" -Id "properties" -Content {}
}
}


}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
50 changes: 12 additions & 38 deletions src/UniversalDashboard.UITest/Integration/TreeView.Tests.ps1
Expand Up @@ -10,60 +10,34 @@ Get-UDDashboard | Stop-UDDashboard
Describe "TreeView" {
Context "blank tree view" {
$Dashboard = New-UdDashboard -Title "Tree View" -Content {

New-UDRow -Columns {
New-UDColumn -Size 3 -Content {
$Root = New-UDTreeNode -Name 'FileSystem' -Id 'FileSystem'
$Root = New-UDTreeNode -Name '1' -Id '1'
New-UDTreeView -ActiveBackgroundColor '#DFE8E4' -Node $Root -OnNodeClicked {
param($Body)

$Obj = $Body | ConvertFrom-Json

if ($Obj.NodeId -eq 'FileSystem') {
Get-PSDrive -PSProvider FileSystem | ForEach-Object {
New-UDTreeNode -Name $_.Root -Id $_.Root -Icon hdd_o
}
} else {
Get-ChildItem -Path $Obj.NodeId | ForEach-Object {
if ($Obj.NodeId -eq $_.FullName) {
return;
}

if ($_.PSIsContainer) {
New-UDTreeNode -Name $_.Name -Id $_.FullName -Icon folder
} else {
New-UDTreeNode -Name $_.Name -Id $_.FullName -Icon file_text
}

} | ConvertTo-JsonEx
$Depth = ([int]$Obj.NodeId) + 1

Set-UDElement -Id "properties" -Content {
New-UDGrid -Title $_.FullName -Headers @("Name", "Value") -Properties @("Name", "Value") -Endpoint {
(Get-ItemProperty -Path $Obj.NodeId).PSObject.Properties | ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Value = if ( $_.Value -eq $null) { "" } else { $_.Value.ToString() }
}
} | Out-UDGridData
}
}
}
New-UDTreeNode -Name ($Depth).ToString() -Id ($Depth).ToString()
}
}
New-UDColumn -Size 9 -Content {
New-UDElement -Tag "div" -Id "properties" -Content {}
}
}


}
}

$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
$Driver = Start-SeFirefox
Enter-SeUrl -Driver $Driver -Url "http://localhost:$BrowserPort"
Start-Sleep 2

#TODO: Write tests for tree view
It "should expand dynamically" {
1..5 | % {
$Element = Find-SeElement -Id $_ -Driver $Driver
$Element | Should not be $null
Invoke-SeClick $Element
Start-Sleep 1
}
}

Stop-SeDriver $Driver
Stop-UDDashboard -Server $Server
Expand Down
3 changes: 2 additions & 1 deletion src/client/src/app/ud-treeview.jsx
Expand Up @@ -37,7 +37,7 @@ export default class UDTreeView extends React.Component {
const iconStyle = {marginRight: '5px'};

return (
<div style={style.base}>
<div style={style.base} id={node.id}>
<div style={style.title}>
<i className={iconClass} style={iconStyle}/>

Expand All @@ -53,6 +53,7 @@ export default class UDTreeView extends React.Component {
listStyle: 'none',
backgroundColor: this.props.backgroundColor,
margin: 0,
marginTop: '5px',
padding: 0,
color: this.props.fontColor,
fontFamily: 'lucida grande ,tahoma,verdana,arial,sans-serif',
Expand Down

0 comments on commit b80a642

Please sign in to comment.