diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2017-11-15 09:56:27 +0200 |
---|---|---|
committer | Pekka Maanpää <pekkamaa@vaadin.com> | 2017-11-15 09:56:27 +0200 |
commit | 1066d9897be1bdd2d52e46654a5fd7b246d54ab5 (patch) | |
tree | eaff7ad3d6660268ebb63f4953ed2b1683a93144 /server/src/test | |
parent | 2b73e6eb08412e9b37b312421bdda2651095529f (diff) | |
download | vaadin-framework-1066d9897be1bdd2d52e46654a5fd7b246d54ab5.tar.gz vaadin-framework-1066d9897be1bdd2d52e46654a5fd7b246d54ab5.zip |
Add new drop mode ON_GRID for GridDropTarget (#10296)
* Add new drop mode ON_GRID for GridDropTarget
Also adds a way to not accept drops on rows when the user has sorted the grid.
This way the bad UX can be avoided for showing the drop indicator for the wrong place when the grid has been sorted.
This has not been made default behavior to GridDropTarget since it would change behavior compared to 8.1.
Instead if is triggerable via API in GridDropTarget.
* Refactor sorted grid drop logic to server side
* Block setDropMode calls
Blocking setDropMode set values if the grid has been sorted and drop on
sorted rows is not allowed. The value is used once the grid is not sorted
anymore or the drops are allowed on sorted rows.
Diffstat (limited to 'server/src/test')
-rw-r--r-- | server/src/test/java/com/vaadin/tests/components/grid/GridDropTargetTest.java | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/server/src/test/java/com/vaadin/tests/components/grid/GridDropTargetTest.java b/server/src/test/java/com/vaadin/tests/components/grid/GridDropTargetTest.java new file mode 100644 index 0000000000..d5de0ad808 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/components/grid/GridDropTargetTest.java @@ -0,0 +1,152 @@ +package com.vaadin.tests.components.grid; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.shared.ui.grid.DropMode; +import com.vaadin.ui.Grid; +import com.vaadin.ui.components.grid.GridDropTarget; + +public class GridDropTargetTest { + + private Grid<String> grid; + private GridDropTarget<String> target; + + @Before + public void setup() { + grid = new Grid<>(); + grid.addColumn(s -> s).setId("1"); + grid.addColumn(s -> s).setId("2"); + target = new GridDropTarget<>(grid, DropMode.BETWEEN); + } + + @Test + public void dropAllowedOnSortedGridRows_defaultValue_isTrue() { + Assert.assertTrue("Default drop allowed should be backwards compatible", + target.isDropAllowedOnSortedGridRows()); + } + + @Test + public void dropAllowedOnSortedGridRows_notAllowed_changesDropModeWhenSorted() { + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(false); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + grid.sort("1"); + + Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); + + grid.sort("2"); + + Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); + + grid.clearSortOrder(); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + grid.clearSortOrder(); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + grid.sort("2"); + + Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); + } + + @Test + public void dropAllowedOnSortedGridRows_sortedGridIsDisallowed_modeChangesToOnGrid() { + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + grid.sort("1"); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(false); + + Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(true); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + } + + @Test + public void dropAllowedOnSortedGridRows_notAllowedBackToAllowed_changesBackToUserDefinedMode() { + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(false); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + grid.sort("1"); + + Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(true); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + grid.clearSortOrder(); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + } + + @Test + public void dropAllowedOnSortedGridRows_swappingAllowedDropOnSortedOffAndOn() { + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(false); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(false); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(true); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(true); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + } + + @Test + public void dropAllowedOnSortedGridRows_changingDropModeWhileSorted_replacesPreviouslyCachedButDoesntOverride() { + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(false); + + Assert.assertEquals(DropMode.BETWEEN, target.getDropMode()); + + grid.sort("1"); + + Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); + + target.setDropMode(DropMode.ON_TOP); + + Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); + Assert.assertFalse("Changing drop mode should not have any effect here", + target.isDropAllowedOnSortedGridRows()); + + grid.clearSortOrder(); + + Assert.assertEquals(DropMode.ON_TOP, target.getDropMode()); + + grid.sort("1"); + + Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); + + target.setDropMode(DropMode.ON_TOP_OR_BETWEEN); + + Assert.assertEquals(DropMode.ON_GRID, target.getDropMode()); + + target.setDropAllowedOnSortedGridRows(true); + + Assert.assertEquals(DropMode.ON_TOP_OR_BETWEEN, target.getDropMode()); + } +} |