aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/test/java/com/vaadin/tests/components/grid/GridDropTargetTest.java
blob: cc5b31de0f041ffc615c9032110cab0ed959a219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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.isDropAllowedOnRowsWhenSorted());
    }

    @Test
    public void dropAllowedOnSortedGridRows_notAllowed_changesDropModeWhenSorted() {
        Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());

        target.setDropAllowedOnRowsWhenSorted(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.setDropAllowedOnRowsWhenSorted(false);

        Assert.assertEquals(DropMode.ON_GRID, target.getDropMode());

        target.setDropAllowedOnRowsWhenSorted(true);

        Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());
    }

    @Test
    public void dropAllowedOnSortedGridRows_notAllowedBackToAllowed_changesBackToUserDefinedMode() {
        Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());

        target.setDropAllowedOnRowsWhenSorted(false);

        Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());

        grid.sort("1");

        Assert.assertEquals(DropMode.ON_GRID, target.getDropMode());

        target.setDropAllowedOnRowsWhenSorted(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.setDropAllowedOnRowsWhenSorted(false);

        Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());

        target.setDropAllowedOnRowsWhenSorted(false);

        Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());

        target.setDropAllowedOnRowsWhenSorted(true);

        Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());

        target.setDropAllowedOnRowsWhenSorted(true);

        Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());
    }

    @Test
    public void dropAllowedOnSortedGridRows_changingDropModeWhileSorted_replacesPreviouslyCachedButDoesntOverride() {
        Assert.assertEquals(DropMode.BETWEEN, target.getDropMode());

        target.setDropAllowedOnRowsWhenSorted(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.isDropAllowedOnRowsWhenSorted());

        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.setDropAllowedOnRowsWhenSorted(true);

        Assert.assertEquals(DropMode.ON_TOP_OR_BETWEEN, target.getDropMode());
    }
}