|
1 | 1 | import fc, { array } from 'fast-check'; |
2 | | -import { take, last, head, startsWith } from "ramda"; |
3 | | -import { multiselect } from '../index'; |
| 2 | +import { take, last, head, reverse } from "ramda"; |
| 3 | +import { Context, multiselect } from '../index'; |
| 4 | +import { indexWithAdjacentConnections, takeFromTo } from './arbitraries'; |
4 | 5 |
|
5 | 6 | describe('Select Adjacent', () => { |
6 | 7 | test('Should select from top to bottom in an empty list', () => { |
@@ -188,4 +189,118 @@ describe('Select Adjacent', () => { |
188 | 189 | ), |
189 | 190 | ) |
190 | 191 | }) |
| 192 | + |
| 193 | + test('Should perform a minus between the old and new end selection group, when selection is ascendent', () => { |
| 194 | + fc.assert( |
| 195 | + fc.property( |
| 196 | + indexWithAdjacentConnections() |
| 197 | + , |
| 198 | + ({ |
| 199 | + list, |
| 200 | + adjacentGroup1, |
| 201 | + adjacentGroup2, |
| 202 | + adjacentGroup3, |
| 203 | + adjacentGroup4, |
| 204 | + start, |
| 205 | + end, |
| 206 | + }) => { |
| 207 | + |
| 208 | + const expectedSelection = takeFromTo(list, start, end); |
| 209 | + |
| 210 | + let context: Context = { |
| 211 | + adjacentPivot: undefined, |
| 212 | + list, |
| 213 | + selected: [] |
| 214 | + } |
| 215 | + |
| 216 | + context = [ |
| 217 | + ...adjacentGroup1, |
| 218 | + ...adjacentGroup2, |
| 219 | + ...adjacentGroup3, |
| 220 | + ...adjacentGroup4, |
| 221 | + start |
| 222 | + ].reduce( |
| 223 | + (ctx, id) => multiselect( |
| 224 | + ctx, |
| 225 | + { |
| 226 | + type: "TOGGLE SELECTION", |
| 227 | + id |
| 228 | + } |
| 229 | + ), |
| 230 | + context |
| 231 | + ); |
| 232 | + |
| 233 | + const result = multiselect( |
| 234 | + context, |
| 235 | + { |
| 236 | + type: 'SELECT ADJACENT', |
| 237 | + id: end |
| 238 | + } |
| 239 | + ) |
| 240 | + expect(result).toEqual({ |
| 241 | + list, |
| 242 | + adjacentPivot: start, |
| 243 | + selected: expectedSelection, |
| 244 | + }) |
| 245 | + } |
| 246 | + ), |
| 247 | + ) |
| 248 | + }) |
| 249 | + |
| 250 | + test('Should perform a minus between the old and new end selection group, when selection is descendent', () => { |
| 251 | + fc.assert( |
| 252 | + fc.property( |
| 253 | + indexWithAdjacentConnections() |
| 254 | + , |
| 255 | + ({ |
| 256 | + list, |
| 257 | + adjacentGroup1, |
| 258 | + adjacentGroup2, |
| 259 | + adjacentGroup3, |
| 260 | + adjacentGroup4, |
| 261 | + start, |
| 262 | + end, |
| 263 | + }) => { |
| 264 | + |
| 265 | + const expectedSelection = reverse(takeFromTo(list, start, end)); |
| 266 | + |
| 267 | + let context: Context = { |
| 268 | + adjacentPivot: undefined, |
| 269 | + list, |
| 270 | + selected: [] |
| 271 | + } |
| 272 | + |
| 273 | + context = [ |
| 274 | + ...adjacentGroup1, |
| 275 | + ...adjacentGroup2, |
| 276 | + ...adjacentGroup3, |
| 277 | + ...adjacentGroup4, |
| 278 | + end, |
| 279 | + ].reduce( |
| 280 | + (ctx, id) => multiselect( |
| 281 | + ctx, |
| 282 | + { |
| 283 | + type: "TOGGLE SELECTION", |
| 284 | + id |
| 285 | + } |
| 286 | + ), |
| 287 | + context |
| 288 | + ); |
| 289 | + |
| 290 | + const result = multiselect( |
| 291 | + context, |
| 292 | + { |
| 293 | + type: 'SELECT ADJACENT', |
| 294 | + id: start |
| 295 | + } |
| 296 | + ) |
| 297 | + expect(result).toEqual({ |
| 298 | + list, |
| 299 | + adjacentPivot: end, |
| 300 | + selected: expectedSelection, |
| 301 | + }) |
| 302 | + } |
| 303 | + ), |
| 304 | + ) |
| 305 | + }) |
191 | 306 | }) |
0 commit comments