Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Berg committed Sep 26, 2019
2 parents c8ea955 + 7280d93 commit 9c632aa
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 107 deletions.
4 changes: 2 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ By the default, the build will execute in the Debug configuration. If you are pr
.\build.ps1 -Configuration Release
```

When building the module, PlatyPS is used to generate the MAML help files from markdown. This is a time consuming process due to performance issues with the PlatyPS module. You can avoid building the hep with the `-NoHelp` switch.
When building the module, PlatyPS is used to generate the MAML help files from markdown. This is a time consuming process due to performance issues with the PlatyPS module. You can avoid building the hep with the `-Minimal` switch.

```
.\build.ps1 -NoHelp
.\build.ps1 -Minimal
```

The output from the build will be staged into the `.\src\output`.
Expand Down
18 changes: 13 additions & 5 deletions src/UniversalDashboard.Materialize/Components/ud-grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,17 @@ export default class UdGrid extends React.Component {
}

onPageChanged(x) {
this.setState({
currentPage: x
})
if (this.props.serverSideProcessing)
{
const { pageSize, sortColumn, sortAscending, filterText } = this.state;
this.loadData(x, pageSize, sortColumn, sortAscending, filterText);
}
else
{
this.setState({
currentPage: x
})
}
}

onExportData() {
Expand Down Expand Up @@ -389,9 +397,9 @@ class GridToolbar extends React.Component {
}

pagination = <ul className="pagination" style={{display: 'inline-block'}} >
<li className={this.props.activePage === 1 ? "disabled" : ""} style={this.props.activePage > 1 ? cursor : {}}><a onClick={() => this.props.activePage > 1 && this.props.onPageChanged(this.props.activePage - 1)}><UdIcon icon="ChevronLeft" /></a></li>
<li className={this.props.activePage === 1 ? "disabled" : ""} style={this.props.activePage > 1 ? cursor : {}}><a className="page-left" onClick={() => this.props.activePage > 1 && this.props.onPageChanged(this.props.activePage - 1)}><UdIcon icon="ChevronLeft" /></a></li>
{pages}
<li className={this.props.activePage === this.props.totalPages ? "disabled" : ""} style={this.props.activePage < this.props.totalPages ? cursor : {}}><a onClick={() => this.props.activePage < this.props.totalPages && this.props.onPageChanged(this.props.activePage + 1)}><UdIcon icon="ChevronRight" /></a></li>
<li className={this.props.activePage === this.props.totalPages ? "disabled" : ""} style={this.props.activePage < this.props.totalPages ? cursor : {}}><a className="page-right" onClick={() => this.props.activePage < this.props.totalPages && this.props.onPageChanged(this.props.activePage + 1)}><UdIcon icon="ChevronRight" /></a></li>
</ul>
}

Expand Down
207 changes: 114 additions & 93 deletions src/UniversalDashboard.Materialize/Tests/grid.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,119 @@
Describe "Grid" {


Context "server side processing" {
$dashboard = New-UDDashboard -Title "Test" -Content {New-UDGrid -Title "Grid" -Id "Grid" -Headers @("day", "jpg", "mp4") -Properties @("day", "jpg", "mp4") -ServerSideProcessing -DefaultSortColumn "day" -EndPoint {
$data = @(
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
)

if ($filterText -ne $null -and $filterText -ne "") {
$data = $data | Where {$_.day -eq $filterText -or $_.jpg -eq $filterText -or $_.mp4 -eq $filterText }
}

$sortDescending = -not $sortAscending
$data = $data | Sort-Object -Property $sortColumn -Descending:$sortDescending

$total = $data.length
$data = $data | Select-Object -First $take -Skip $skip

$data | Out-UDGridData -TotalItems $total
}
}

Set-TestDashboard -Dashboard $dashboard

It "should page data" {

$Element = Find-SeElement -ClassName "page-right" -Driver $Driver
Invoke-SeClick -Element $Element -JavaScriptClick -Driver $Driver

Start-Sleep 1

$Row = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[7]
$Element[0].Text | should be "3"
}

It "should have data" {

$Driver.Navigate().Refresh()

Start-Sleep 1

$Element = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Element[0]
$Element.Length | Should be 3
$Element[0].Text | should be "1"
$Element[1].Text | should be "10"
$Element[2].Text | should be "30"
}

It "should sort data" {

$Driver.Navigate().Refresh()

$Row = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[0]
$Element[0].Text | should be "1"
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[1]
$Element[0].Text | should be "1"

$Element = Find-SeElement -ClassName "griddle-table-heading-cell" -Driver $Driver
$header = $element[0]
Invoke-SeClick $header

$Row = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[0]
$Element[0].Text | should be "3"
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[1]
$Element[0].Text | should be "3"

$Element = Find-SeElement -ClassName "griddle-table-heading-cell" -Driver $Driver
$header = $element[0]
Invoke-SeClick $header

$Row = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[0]
$Element[0].Text | should be "1"
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[1]
$Element[0].Text | should be "1"
}

It "should filter data" {

$Driver.Navigate().Refresh()

$Element = Find-SeElement -ClassName "griddle-filter" -Driver $Driver

Send-SeKeys -Element $Element[0] -Keys "2"
Sleep 1
Send-SeKeys -Element $Element[0] -Keys "0"

$Element = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element.Length | Should be 6
}
}



Context "refresh doesnt reset filter" {
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDGrid -Title "Grid" -Id "Grid" -RefreshInterval 5 -AutoRefresh -DefaultSortColumn "jpg" -DefaultSortDescending -EndPoint {
Expand Down Expand Up @@ -214,99 +328,6 @@ Describe "Grid" {
}
}

Context "server side processing" {
$dashboard = New-UDDashboard -Title "Test" -Content {New-UDGrid -Title "Grid" -Id "Grid" -Headers @("day", "jpg", "mp4") -Properties @("day", "jpg", "mp4") -ServerSideProcessing -DefaultSortColumn "day" -EndPoint {
$data = @(
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
[PSCustomObject]@{"day" = 1; jpg = "10"; mp4= "30"}
[PSCustomObject]@{"day" = 2; jpg = "20"; mp4= "20"}
[PSCustomObject]@{"day" = 3; jpg = "30"; mp4= "10"}
)

if ($filterText -ne $null -and $filterText -ne "") {
$data = $data | Where {$_.day -eq $filterText -or $_.jpg -eq $filterText -or $_.mp4 -eq $filterText }
}

$sortDescending = -not $sortAscending
$data = $data | Sort-Object -Property $sortColumn -Descending:$sortDescending

$total = $data.length
$data = $data | Select-Object -First $take -Skip $skip

$data | Out-UDGridData -TotalItems $total
}
}

Set-TestDashboard -Dashboard $dashboard

It "should have data" {

Start-Sleep 1

$Element = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Element[0]
$Element.Length | Should be 2
$Element[0].Text | should be "1"
$Element[1].Text | should be "10"
$Element[2].Text | should be "30"
}

It "should sort data" {

$Row = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[0]
$Element[0].Text | should be "1"
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[1]
$Element[0].Text | should be "1"

$Element = Find-SeElement -ClassName "griddle-table-heading-cell" -Driver $Driver
$header = $element[0]
Invoke-SeClick $header

$Row = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[0]
$Element[0].Text | should be "3"
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[1]
$Element[0].Text | should be "3"

$Element = Find-SeElement -ClassName "griddle-table-heading-cell" -Driver $Driver
$header = $element[0]
Invoke-SeClick $header

$Row = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[0]
$Element[0].Text | should be "1"
$Element = Find-SeElement -ClassName "griddle-cell" -Driver $Row[1]
$Element[0].Text | should be "1"
}

It "should filter data" {

$Element = Find-SeElement -ClassName "griddle-filter" -Driver $Driver

Send-SeKeys -Element $Element[0] -Keys "2"
Sleep 1
Send-SeKeys -Element $Element[0] -Keys "0"

$Element = Find-SeElement -ClassName "griddle-row" -Driver $Driver
$Element.Length | Should be 6
}
}

Context "Grid" {
$dashboard = New-UDDashboard -Title "Test" -Content {
New-UDGrid -Title "Grid" -Id "Grid" -Headers @("day", "jpg", "mp4") -Properties @("day", "jpg", "mp4") -EndPoint {
Expand Down
4 changes: 2 additions & 2 deletions src/UniversalDashboard.Materialize/Tests/navigation.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ Describe "Navigation" {
Start-Sleep 1

$Element = Find-SeElement -Id "sidenavtrigger" -Driver $Driver
Invoke-SeClick $Element
Invoke-SeClick $Element -JavaScriptClick -Driver $Driver

Start-Sleep 1

$Element = Find-SeElement -LinkText "Page2" -Driver $Driver
Invoke-SeClick $Element
Invoke-SeClick $Element -JavaScriptClick -Driver $Driver

Start-Sleep 1

Expand Down
4 changes: 2 additions & 2 deletions src/UniversalDashboard.UITest/Integration/Dashboard.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ Describe "Dashboard" {

It 'should navigate custom navigation' {
$Element = Find-SeElement -Id "sidenavtrigger" -Driver $Driver
Invoke-SeClick $Element
Invoke-SeClick $Element -JavaScriptClick -Driver $Driver

Start-Sleep 1

$Element = Find-SeElement -LinkText "My First Page" -Driver $Driver
Invoke-SeClick $Element
Invoke-SeClick $Element -JavaScriptClick -Driver $Driver

Start-Sleep 1

Expand Down
65 changes: 65 additions & 0 deletions src/UniversalDashboard.UITest/Integration/Input.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,72 @@ $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 {
New-UDInputField -Type 'textbox' -Name 'MyField'
New-UDInputField -Type 'textbox' -Name 'MyField2'
} -Endpoint {
param (
[Parameter(Mandatory)]
$MyField,
[Parameter(Mandatory)]
$MyField2
)
}
}

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

It "should validate required" {
$Element = Find-SeElement -Id 'MyField' -Driver $Driver
Invoke-SeClick -Element $Element -JavaScriptClick -Driver $Driver
Send-SeKeys -Element $Element -Keys ''

$Element = Find-SeElement -Id 'MyField2' -Driver $Driver
Invoke-SeClick -Element $Element -JavaScriptClick -Driver $Driver
Send-SeKeys -Element $Element -Keys 'a'

(Find-SeElement -Id 'MyFieldtooltip' -Driver $Driver).getAttribute("textContent") | should be 'MyField is required.'
}
}

Context "drops to pipeline" {
$Dashboard = New-UDDashboard -Title "Test" -Content {
Expand Down
4 changes: 2 additions & 2 deletions src/UniversalDashboard.UITest/Integration/Page.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ Describe "New-UDPage" {

It "should navigate to page with spaces" {
$Element = Find-SeElement -Id "sidenavtrigger" -Driver $Driver
Invoke-SeClick $Element
Invoke-SeClick $Element -JavaScriptClick -Driver $Driver

Start-Sleep 1

$Element = Find-SeElement -LinkText "Page with spaces" -Driver $Driver
Invoke-SeClick $Element
Invoke-SeClick $Element -JavaScriptClick -Driver $Driver

Start-Sleep 1

Expand Down
Loading

0 comments on commit 9c632aa

Please sign in to comment.