|
12 | 12 | * action is skipped; a second finger or the window losing focus cancels; |
13 | 13 | * inside a scroller a flick is left to the scroller; a mouse under a fine |
14 | 14 | * pointer is tracked like a finger; the shared tracker does the tracking; |
15 | | - * no render per move |
| 15 | + * a caller's no-paint option and press callbacks; no render per move |
16 | 16 | * @position jsdom tests of packages/core/src/hooks/useActionGroupTracking.ts |
17 | 17 | */ |
18 | 18 |
|
@@ -313,6 +313,96 @@ describe('useActionGroupTracking', () => { |
313 | 313 | expect(onDelete).not.toHaveBeenCalled(); |
314 | 314 | }); |
315 | 315 |
|
| 316 | + describe('a group that draws its own highlight (Lab TabBar)', () => { |
| 317 | + const nameOf = (element: Element | null) => element?.textContent ?? 'none'; |
| 318 | + |
| 319 | + it('paints nothing with paintsHighlight off, and still runs the action it lifts on', () => { |
| 320 | + const {cancel, del, onCancel} = mount({ |
| 321 | + options: {paintsHighlight: false}, |
| 322 | + }); |
| 323 | + const f = finger(); |
| 324 | + f.down(cancel, centerOf(CANCEL)); |
| 325 | + expect(paintOf(cancel)).toBeNull(); |
| 326 | + f.move(cancel, centerOf(DELETE)); |
| 327 | + expect(paintOf(del)).toBeNull(); |
| 328 | + f.move(cancel, centerOf(CANCEL)); |
| 329 | + f.up(cancel, centerOf(CANCEL)); |
| 330 | + expect(paintOf(cancel)).toBeNull(); |
| 331 | + expect(onCancel).toHaveBeenCalledTimes(1); |
| 332 | + }); |
| 333 | + |
| 334 | + it('reports the press around the tracker: the action at the begin and after each move, then the lift before its action runs', () => { |
| 335 | + const log: string[] = []; |
| 336 | + const {cancel} = mount({ |
| 337 | + options: { |
| 338 | + onPressBegin: (_x, _y, action) => log.push(`begin ${nameOf(action)}`), |
| 339 | + onPressMove: (_x, _y, action) => log.push(`move ${nameOf(action)}`), |
| 340 | + onPressEnd: action => log.push(`end ${nameOf(action)}`), |
| 341 | + onPressCancel: () => log.push('cancel'), |
| 342 | + onActivate: action => log.push(`activate ${nameOf(action)}`), |
| 343 | + }, |
| 344 | + }); |
| 345 | + const f = finger(); |
| 346 | + f.down(cancel, centerOf(CANCEL)); |
| 347 | + f.move(cancel, {x: 104, y: 124}); |
| 348 | + f.move(cancel, centerOf(DELETE)); |
| 349 | + f.up(cancel, centerOf(DELETE)); |
| 350 | + expect(log).toEqual([ |
| 351 | + 'begin Cancel', |
| 352 | + 'move none', |
| 353 | + 'move Delete', |
| 354 | + 'end Delete', |
| 355 | + 'activate Delete', |
| 356 | + ]); |
| 357 | + }); |
| 358 | + |
| 359 | + it('reports a press that a second finger ends as a cancel, and runs nothing (family:action-groups FR3)', () => { |
| 360 | + const log: string[] = []; |
| 361 | + const {cancel, del} = mount({ |
| 362 | + options: { |
| 363 | + onPressBegin: (_x, _y, action) => log.push(`begin ${nameOf(action)}`), |
| 364 | + onPressEnd: () => log.push('end'), |
| 365 | + onPressCancel: () => log.push('cancel'), |
| 366 | + onActivate: () => log.push('activate'), |
| 367 | + }, |
| 368 | + }); |
| 369 | + const first = {id: nextTouchId++, ...centerOf(CANCEL)}; |
| 370 | + const second = {id: nextTouchId++, ...centerOf(DELETE)}; |
| 371 | + time += 1000; |
| 372 | + touch('touchstart', cancel, first, time); |
| 373 | + time += 30; |
| 374 | + touch('touchstart', del, second, time, [first]); |
| 375 | + time += 16; |
| 376 | + touch('touchend', del, second, time, [first]); |
| 377 | + time += 16; |
| 378 | + touch('touchend', cancel, first, time); |
| 379 | + expect(log).toEqual(['begin Cancel', 'cancel']); |
| 380 | + }); |
| 381 | + |
| 382 | + it('reports a press that turning tracking off ends as a cancel, and runs nothing', () => { |
| 383 | + const log: string[] = []; |
| 384 | + const options: Partial<ActionGroupTrackingOptions> = { |
| 385 | + paintsHighlight: false, |
| 386 | + onPressBegin: (_x, _y, action) => log.push(`begin ${nameOf(action)}`), |
| 387 | + onPressEnd: () => log.push('end'), |
| 388 | + onPressCancel: () => log.push('cancel'), |
| 389 | + onActivate: () => log.push('activate'), |
| 390 | + }; |
| 391 | + const view = mount({options}); |
| 392 | + const f = finger(); |
| 393 | + f.down(view.cancel, centerOf(CANCEL)); |
| 394 | + view.rerender( |
| 395 | + <Group |
| 396 | + onCancel={view.onCancel} |
| 397 | + onDelete={view.onDelete} |
| 398 | + options={{...options, isEnabled: false}} |
| 399 | + />, |
| 400 | + ); |
| 401 | + f.up(view.cancel, centerOf(CANCEL)); |
| 402 | + expect(log).toEqual(['begin Cancel', 'cancel']); |
| 403 | + }); |
| 404 | + }); |
| 405 | + |
316 | 406 | it('ends the gesture with nothing acting when the window loses focus (family:action-groups FR3)', () => { |
317 | 407 | const {cancel, onCancel} = mount(); |
318 | 408 | const f = finger(); |
|
0 commit comments