From a280d69d11e7db2cd3e4d9b5fff4e066a6f61cc7 Mon Sep 17 00:00:00 2001 From: Henri Kerola Date: Fri, 2 Jan 2015 22:43:31 -0800 Subject: [PATCH] more methods + tests for Grid.Column (part of #59) --- addon/src/main/scala/vaadin/scala/Grid.scala | 14 ++++++ .../scala/vaadin/scala/tests/GridTests.scala | 47 +++++++++++++++---- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/addon/src/main/scala/vaadin/scala/Grid.scala b/addon/src/main/scala/vaadin/scala/Grid.scala index b9d33b74..75af6df8 100644 --- a/addon/src/main/scala/vaadin/scala/Grid.scala +++ b/addon/src/main/scala/vaadin/scala/Grid.scala @@ -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) { diff --git a/addon/src/test/scala/vaadin/scala/tests/GridTests.scala b/addon/src/test/scala/vaadin/scala/tests/GridTests.scala index 0d100ed2..7d445466 100644 --- a/addon/src/test/scala/vaadin/scala/tests/GridTests.scala +++ b/addon/src/test/scala/vaadin/scala/tests/GridTests.scala @@ -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 @@ -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) @@ -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") { @@ -262,7 +295,6 @@ class GridTests extends ScaladinTestSuite { assert(grid.selectionListeners.isEmpty) } - test("sortOrder") { import vaadin.scala.SortDirection._ @@ -366,7 +398,6 @@ class GridTests extends ScaladinTestSuite { assert(!grid.headerVisible) } - test("getFooterRow") { grid.appendFooterRow() @@ -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) } @@ -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) }