|
15 | 15 | */
|
16 | 16 | package org.springframework.shell.component.view.control;
|
17 | 17 |
|
| 18 | +import org.junit.jupiter.api.Nested; |
18 | 19 | import org.junit.jupiter.api.Test;
|
19 | 20 |
|
20 | 21 | import org.springframework.shell.component.view.screen.DefaultScreen;
|
21 | 22 |
|
22 | 23 | import static org.assertj.core.api.Assertions.assertThat;
|
| 24 | +import static org.mockito.Mockito.spy; |
| 25 | +import static org.mockito.Mockito.verify; |
23 | 26 |
|
24 | 27 | class GridViewTests extends AbstractViewTests {
|
25 | 28 |
|
26 |
| - @Test |
27 |
| - void hasBordersWith1x1() { |
28 |
| - BoxView box1 = new BoxView(); |
29 | 29 |
|
30 |
| - GridView grid = new GridView(); |
31 |
| - grid.setShowBorders(true); |
32 |
| - grid.setRowSize(0); |
33 |
| - grid.setColumnSize(0); |
34 |
| - grid.setShowBorder(false); |
35 |
| - grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
| 30 | + @Nested |
| 31 | + class ItemPositions { |
36 | 32 |
|
37 |
| - grid.setRect(0, 0, 80, 24); |
38 |
| - grid.draw(screen24x80); |
| 33 | + @Test |
| 34 | + void noBorderKeepsFullArea() { |
| 35 | + BoxView box1 = new BoxView(); |
| 36 | + BoxView sbox1 = spy(box1); |
| 37 | + GridView grid = new GridView(); |
39 | 38 |
|
40 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
41 |
| - } |
| 39 | + grid.setShowBorders(false); |
| 40 | + grid.setRowSize(0); |
| 41 | + grid.setColumnSize(0); |
| 42 | + grid.setShowBorder(false); |
| 43 | + grid.addItem(sbox1, 0, 0, 1, 1, 0, 0); |
42 | 44 |
|
43 |
| - @Test |
44 |
| - void hasBordersWith1x2() { |
45 |
| - BoxView box1 = new BoxView(); |
46 |
| - BoxView box2 = new BoxView(); |
47 |
| - |
48 |
| - GridView grid = new GridView(); |
49 |
| - grid.setShowBorders(true); |
50 |
| - grid.setRowSize(0); |
51 |
| - grid.setColumnSize(0, 0); |
52 |
| - grid.setShowBorder(false); |
53 |
| - grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
54 |
| - grid.addItem(box2, 0, 1, 1, 1, 0, 0); |
55 |
| - |
56 |
| - grid.setRect(0, 0, 80, 24); |
57 |
| - grid.draw(screen24x80); |
58 |
| - |
59 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
60 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 0, 39, 24); |
61 |
| - assertThat(forScreen(screen24x80)).hasBorder(39, 0, 41, 24); |
62 |
| - } |
| 45 | + grid.setRect(0, 0, 80, 24); |
| 46 | + grid.draw(screen24x80); |
63 | 47 |
|
64 |
| - @Test |
65 |
| - void hasBordersWith2x1() { |
66 |
| - BoxView box1 = new BoxView(); |
67 |
| - BoxView box2 = new BoxView(); |
68 |
| - |
69 |
| - GridView grid = new GridView(); |
70 |
| - grid.setShowBorders(true); |
71 |
| - grid.setRowSize(0, 0); |
72 |
| - grid.setColumnSize(0); |
73 |
| - grid.setShowBorder(false); |
74 |
| - grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
75 |
| - grid.addItem(box2, 1, 0, 1, 1, 0, 0); |
76 |
| - |
77 |
| - grid.setRect(0, 0, 80, 24); |
78 |
| - grid.draw(screen24x80); |
79 |
| - |
80 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
81 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 12); |
82 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 11, 80, 13); |
83 |
| - } |
| 48 | + verify(sbox1).setRect(0, 0, 80, 24); |
| 49 | + } |
84 | 50 |
|
85 |
| - @Test |
86 |
| - void hasBordersWith2x2() { |
87 |
| - BoxView box1 = new BoxView(); |
88 |
| - BoxView box2 = new BoxView(); |
89 |
| - BoxView box3 = new BoxView(); |
90 |
| - BoxView box4 = new BoxView(); |
91 |
| - |
92 |
| - GridView grid = new GridView(); |
93 |
| - grid.setShowBorders(true); |
94 |
| - grid.setRowSize(0, 0); |
95 |
| - grid.setColumnSize(0, 0); |
96 |
| - grid.setShowBorder(false); |
97 |
| - grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
98 |
| - grid.addItem(box2, 0, 1, 1, 1, 0, 0); |
99 |
| - grid.addItem(box3, 1, 0, 1, 1, 0, 0); |
100 |
| - grid.addItem(box4, 1, 1, 1, 1, 0, 0); |
101 |
| - |
102 |
| - grid.setRect(0, 0, 80, 24); |
103 |
| - grid.draw(screen24x80); |
104 |
| - |
105 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
106 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 0, 39, 12); |
107 |
| - assertThat(forScreen(screen24x80)).hasBorder(39, 0, 41, 12); |
108 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 11, 80, 13); |
109 |
| - assertThat(forScreen(screen24x80)).hasBorder(39, 11, 41, 13); |
110 |
| - } |
| 51 | + @Test |
| 52 | + void borderMakesItemSmaller() { |
| 53 | + BoxView box1 = new BoxView(); |
| 54 | + BoxView sbox1 = spy(box1); |
| 55 | + GridView grid = new GridView(); |
111 | 56 |
|
112 |
| - @Test |
113 |
| - void hasBordersWithHidden() { |
114 |
| - screen24x80 = new DefaultScreen(20, 10); |
| 57 | + grid.setShowBorders(true); |
| 58 | + grid.setRowSize(0); |
| 59 | + grid.setColumnSize(0); |
| 60 | + grid.setShowBorder(false); |
| 61 | + grid.addItem(sbox1, 0, 0, 1, 1, 0, 0); |
115 | 62 |
|
116 |
| - BoxView menu = new BoxView(); |
117 |
| - BoxView main = new BoxView(); |
118 |
| - BoxView sideBar = new BoxView(); |
119 |
| - BoxView header = new BoxView(); |
120 |
| - BoxView footer = new BoxView(); |
| 63 | + grid.setRect(0, 0, 80, 24); |
| 64 | + grid.draw(screen24x80); |
121 | 65 |
|
122 |
| - GridView grid = new GridView(); |
123 |
| - grid.setRowSize(3, 0, 3); |
124 |
| - grid.setColumnSize(30, 0, 30); |
125 |
| - grid.setShowBorders(true); |
| 66 | + verify(sbox1).setRect(1, 1, 78, 22); |
| 67 | + } |
126 | 68 |
|
127 |
| - grid.addItem(header, 0, 0, 1, 3, 0, 0); |
128 |
| - grid.addItem(footer, 2, 0, 1, 3, 0, 0); |
| 69 | + @Test |
| 70 | + void positionsWith1x2() { |
| 71 | + BoxView box1 = new BoxView(); |
| 72 | + BoxView box2 = new BoxView(); |
| 73 | + BoxView sbox1 = spy(box1); |
| 74 | + BoxView sbox2 = spy(box2); |
| 75 | + GridView grid = new GridView(); |
129 | 76 |
|
130 |
| - grid.addItem(menu, 0, 0, 0, 0, 0, 0); |
131 |
| - grid.addItem(main, 1, 0, 1, 3, 0, 0); |
132 |
| - grid.addItem(sideBar, 0, 0, 0, 0, 0, 0); |
| 77 | + grid.setShowBorders(false); |
| 78 | + grid.setRowSize(0, 0); |
| 79 | + grid.setColumnSize(0); |
| 80 | + grid.setShowBorder(false); |
| 81 | + grid.addItem(sbox1, 0, 0, 1, 1, 0, 0); |
| 82 | + grid.addItem(sbox2, 1, 0, 1, 1, 0, 0); |
133 | 83 |
|
134 |
| - grid.addItem(menu, 1, 0, 1, 1, 0, 100); |
135 |
| - grid.addItem(main, 1, 1, 1, 1, 0, 100); |
136 |
| - grid.addItem(sideBar, 1, 2, 1, 1, 0, 100); |
| 84 | + grid.setRect(0, 0, 80, 24); |
| 85 | + grid.draw(screen24x80); |
137 | 86 |
|
138 |
| - grid.setRect(0, 0, 10, 20); |
139 |
| - grid.draw(screen24x80); |
| 87 | + verify(sbox1).setRect(0, 0, 80, 12); |
| 88 | + verify(sbox2).setRect(0, 12, 80, 12); |
| 89 | + } |
140 | 90 |
|
141 |
| - // overflows, don't have full border anywhere |
142 |
| - // assertThat(forScreen(screen)).hasBorder(0, 0, 80, 24); |
143 | 91 | }
|
144 | 92 |
|
145 |
| - @Test |
146 |
| - void gridBoxHasTitle() { |
147 |
| - BoxView box1 = new BoxView(); |
| 93 | + @Nested |
| 94 | + class Borders { |
| 95 | + |
| 96 | + @Test |
| 97 | + void hasBordersWith1x1() { |
| 98 | + BoxView box1 = new BoxView(); |
| 99 | + |
| 100 | + GridView grid = new GridView(); |
| 101 | + grid.setShowBorders(true); |
| 102 | + grid.setRowSize(0); |
| 103 | + grid.setColumnSize(0); |
| 104 | + grid.setShowBorder(false); |
| 105 | + grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
| 106 | + |
| 107 | + grid.setRect(0, 0, 80, 24); |
| 108 | + grid.draw(screen24x80); |
| 109 | + |
| 110 | + assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + void hasBordersWith1x2() { |
| 115 | + BoxView box1 = new BoxView(); |
| 116 | + BoxView box2 = new BoxView(); |
| 117 | + |
| 118 | + GridView grid = new GridView(); |
| 119 | + grid.setShowBorders(true); |
| 120 | + grid.setRowSize(0); |
| 121 | + grid.setColumnSize(0, 0); |
| 122 | + grid.setShowBorder(false); |
| 123 | + grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
| 124 | + grid.addItem(box2, 0, 1, 1, 1, 0, 0); |
| 125 | + |
| 126 | + grid.setRect(0, 0, 80, 24); |
| 127 | + grid.draw(screen24x80); |
| 128 | + |
| 129 | + assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
| 130 | + assertThat(forScreen(screen24x80)).hasBorder(0, 0, 39, 24); |
| 131 | + assertThat(forScreen(screen24x80)).hasBorder(39, 0, 41, 24); |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + void hasBordersWith2x1() { |
| 136 | + BoxView box1 = new BoxView(); |
| 137 | + BoxView box2 = new BoxView(); |
| 138 | + |
| 139 | + GridView grid = new GridView(); |
| 140 | + grid.setShowBorders(true); |
| 141 | + grid.setRowSize(0, 0); |
| 142 | + grid.setColumnSize(0); |
| 143 | + grid.setShowBorder(false); |
| 144 | + grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
| 145 | + grid.addItem(box2, 1, 0, 1, 1, 0, 0); |
| 146 | + |
| 147 | + grid.setRect(0, 0, 80, 24); |
| 148 | + grid.draw(screen24x80); |
| 149 | + |
| 150 | + assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
| 151 | + assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 12); |
| 152 | + assertThat(forScreen(screen24x80)).hasBorder(0, 11, 80, 13); |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + void hasBordersWith2x2() { |
| 157 | + BoxView box1 = new BoxView(); |
| 158 | + BoxView box2 = new BoxView(); |
| 159 | + BoxView box3 = new BoxView(); |
| 160 | + BoxView box4 = new BoxView(); |
| 161 | + |
| 162 | + GridView grid = new GridView(); |
| 163 | + grid.setShowBorders(true); |
| 164 | + grid.setRowSize(0, 0); |
| 165 | + grid.setColumnSize(0, 0); |
| 166 | + grid.setShowBorder(false); |
| 167 | + grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
| 168 | + grid.addItem(box2, 0, 1, 1, 1, 0, 0); |
| 169 | + grid.addItem(box3, 1, 0, 1, 1, 0, 0); |
| 170 | + grid.addItem(box4, 1, 1, 1, 1, 0, 0); |
| 171 | + |
| 172 | + grid.setRect(0, 0, 80, 24); |
| 173 | + grid.draw(screen24x80); |
| 174 | + |
| 175 | + assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
| 176 | + assertThat(forScreen(screen24x80)).hasBorder(0, 0, 39, 12); |
| 177 | + assertThat(forScreen(screen24x80)).hasBorder(39, 0, 41, 12); |
| 178 | + assertThat(forScreen(screen24x80)).hasBorder(0, 11, 80, 13); |
| 179 | + assertThat(forScreen(screen24x80)).hasBorder(39, 11, 41, 13); |
| 180 | + } |
| 181 | + |
| 182 | + @Test |
| 183 | + void hasBordersWithHidden() { |
| 184 | + screen24x80 = new DefaultScreen(20, 10); |
| 185 | + |
| 186 | + BoxView menu = new BoxView(); |
| 187 | + BoxView main = new BoxView(); |
| 188 | + BoxView sideBar = new BoxView(); |
| 189 | + BoxView header = new BoxView(); |
| 190 | + BoxView footer = new BoxView(); |
| 191 | + |
| 192 | + GridView grid = new GridView(); |
| 193 | + grid.setRowSize(3, 0, 3); |
| 194 | + grid.setColumnSize(30, 0, 30); |
| 195 | + grid.setShowBorders(true); |
| 196 | + |
| 197 | + grid.addItem(header, 0, 0, 1, 3, 0, 0); |
| 198 | + grid.addItem(footer, 2, 0, 1, 3, 0, 0); |
| 199 | + |
| 200 | + grid.addItem(menu, 0, 0, 0, 0, 0, 0); |
| 201 | + grid.addItem(main, 1, 0, 1, 3, 0, 0); |
| 202 | + grid.addItem(sideBar, 0, 0, 0, 0, 0, 0); |
| 203 | + |
| 204 | + grid.addItem(menu, 1, 0, 1, 1, 0, 100); |
| 205 | + grid.addItem(main, 1, 1, 1, 1, 0, 100); |
| 206 | + grid.addItem(sideBar, 1, 2, 1, 1, 0, 100); |
| 207 | + |
| 208 | + grid.setRect(0, 0, 10, 20); |
| 209 | + grid.draw(screen24x80); |
| 210 | + } |
| 211 | + |
| 212 | + @Test |
| 213 | + void gridBoxHasTitle() { |
| 214 | + BoxView box1 = new BoxView(); |
| 215 | + |
| 216 | + GridView grid = new GridView(); |
| 217 | + grid.setShowBorder(true); |
| 218 | + grid.setTitle("title"); |
| 219 | + grid.setShowBorders(true); |
| 220 | + grid.setRowSize(0); |
| 221 | + grid.setColumnSize(0); |
| 222 | + grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
| 223 | + |
| 224 | + grid.setRect(0, 0, 80, 24); |
| 225 | + grid.draw(screen24x80); |
| 226 | + |
| 227 | + assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
| 228 | + assertThat(forScreen(screen24x80)).hasBorder(1, 1, 78, 22); |
| 229 | + assertThat(forScreen(screen24x80)).hasHorizontalText("title", 1, 0, 5); |
| 230 | + } |
148 | 231 |
|
149 |
| - GridView grid = new GridView(); |
150 |
| - grid.setShowBorder(true); |
151 |
| - grid.setTitle("title"); |
152 |
| - grid.setShowBorders(true); |
153 |
| - grid.setRowSize(0); |
154 |
| - grid.setColumnSize(0); |
155 |
| - grid.addItem(box1, 0, 0, 1, 1, 0, 0); |
156 |
| - |
157 |
| - grid.setRect(0, 0, 80, 24); |
158 |
| - grid.draw(screen24x80); |
159 |
| - |
160 |
| - assertThat(forScreen(screen24x80)).hasBorder(0, 0, 80, 24); |
161 |
| - assertThat(forScreen(screen24x80)).hasBorder(1, 1, 78, 22); |
162 |
| - assertThat(forScreen(screen24x80)).hasHorizontalText("title", 1, 0, 5); |
163 | 232 | }
|
164 | 233 |
|
| 234 | + |
165 | 235 | }
|
0 commit comments