Skip to content

Commit

Permalink
Fixes #1163 (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdriscoll authored Sep 25, 2019
2 parents 3931a7f + 804774e commit 33a7cab
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 105 deletions.
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
4 changes: 3 additions & 1 deletion src/UniversalDashboard.UITest/Integration/Input.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Describe "Input" {
checkbox = $checkbox
textbox = $textbox
}

}
}

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

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

0 comments on commit 33a7cab

Please sign in to comment.