Skip to content

Commit

Permalink
more methods + tests for Grid.Column (part of #59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri Kerola committed Jan 3, 2015
1 parent bcce135 commit a280d69
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
14 changes: 14 additions & 0 deletions addon/src/main/scala/vaadin/scala/Grid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ object Grid {

def sortable: Boolean = p.isSortable
def sortable_=(sortable: Boolean): Unit = p.setSortable(sortable)

def expandRatio: Int = p.getExpandRatio
def expandRatio_=(expandRatio: Int): Unit = p.setExpandRatio(expandRatio)
def expandRatio_=(expandRatio: Option[Int]): Unit = {
if (expandRatio.isEmpty) p.clearExpandRatio()
else p.setExpandRatio(expandRatio.get)
}

def minimumWidth: Double = p.getMinimumWidth
def minimumWidth_=(minimumWidth: Double): Unit = p.setMinimumWidth(minimumWidth)

def maximumWidth: Double = p.getMaximumWidth
def maximumWidth_=(maximumWidth: Double): Unit = p.setMaximumWidth(maximumWidth)

}

case class RowReference(grid: Grid, itemId: Any) {
Expand Down
47 changes: 39 additions & 8 deletions addon/src/test/scala/vaadin/scala/tests/GridTests.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package vaadin.scala.tests

import com.vaadin.data.sort.SortOrder
import vaadin.scala.event.{SortEvent, SelectionEvent}
import vaadin.scala.event.{ SortEvent, SelectionEvent }
import com.vaadin.shared.data.sort.SortDirection
import com.vaadin.ui.Grid.{RowReference, Column}
import org.mockito.{ArgumentCaptor, Mockito}
import com.vaadin.ui.Grid.{ RowReference, Column }
import org.mockito.{ ArgumentCaptor, Mockito }
import vaadin.scala.mixins.GridMixin
import vaadin.scala._
import vaadin.scala.Grid.HeightMode
Expand Down Expand Up @@ -109,7 +109,7 @@ class GridTests extends ScaladinTestSuite {
assert(-1 == column.width)
}

test("sortable") {
test("Column.sortable") {
val column = grid.addColumn[String]("myColumn")

assert(column.sortable)
Expand All @@ -118,6 +118,39 @@ class GridTests extends ScaladinTestSuite {
assert(!column.sortable)
}

test("Column.expandRatio") {
val column = grid.addColumn[String]("myColumn")

assert(-1 == column.expandRatio)

column.expandRatio = 2
assert(2 == column.expandRatio)

column.expandRatio = None
assert(-1 == column.expandRatio)

column.expandRatio = Some(1)
assert(1 == column.expandRatio)
}

test("minimumWidth") {
val column = grid.addColumn[String]("myColumn")

assert(10 == column.minimumWidth)

column.minimumWidth = 5
assert(5 == column.minimumWidth)
}

test("maximumWidth") {
val column = grid.addColumn[String]("myColumn")

assert(-1 == column.maximumWidth)

column.maximumWidth = 20
assert(20 == column.maximumWidth)
}

// TODO tests for Grid.Column class

test("setColumnOrder") {
Expand Down Expand Up @@ -262,7 +295,6 @@ class GridTests extends ScaladinTestSuite {
assert(grid.selectionListeners.isEmpty)
}


test("sortOrder") {
import vaadin.scala.SortDirection._

Expand Down Expand Up @@ -366,7 +398,6 @@ class GridTests extends ScaladinTestSuite {
assert(!grid.headerVisible)
}


test("getFooterRow") {
grid.appendFooterRow()

Expand Down Expand Up @@ -421,7 +452,7 @@ class GridTests extends ScaladinTestSuite {
grid.rowStyleGenerator = None
assert(grid.rowStyleGenerator.isEmpty)

grid.rowStyleGenerator = Some({ e: Grid.RowReference => None})
grid.rowStyleGenerator = Some({ e: Grid.RowReference => None })
assert(grid.rowStyleGenerator.isDefined)
}

Expand All @@ -442,7 +473,7 @@ class GridTests extends ScaladinTestSuite {
grid.cellStyleGenerator = None
assert(grid.cellStyleGenerator.isEmpty)

grid.cellStyleGenerator = Some({ e: Grid.CellReference => None})
grid.cellStyleGenerator = Some({ e: Grid.CellReference => None })
assert(grid.cellStyleGenerator.isDefined)
}

Expand Down

0 comments on commit a280d69

Please sign in to comment.