-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes issue with SensorAPI | tryReleaseLock
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/unit/integration/drag-handle/shared-behaviours/lock-released-mid-drag.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import type { SensorAPI, Sensor } from '../../../../../src/types'; | ||
import { forEachSensor, type Control, simpleLift } from '../../util/controls'; | ||
import { isDragging } from '../../util/helpers'; | ||
import App from '../../util/app'; | ||
import { invariant } from '../../../../../src/invariant'; | ||
|
||
forEachSensor((control: Control) => { | ||
it('should cleanup a drag if a lock is forceably released mid drag', () => { | ||
let api: SensorAPI; | ||
const sensor: Sensor = (value: SensorAPI) => { | ||
api = value; | ||
}; | ||
|
||
const { getByText } = render(<App sensors={[sensor]} />); | ||
const handle: HTMLElement = getByText('item: 0'); | ||
invariant(api); | ||
|
||
simpleLift(control, handle); | ||
|
||
expect(api.isLockClaimed()).toBe(true); | ||
expect(isDragging(handle)).toBe(true); | ||
|
||
api.tryReleaseLock(); | ||
|
||
expect(api.isLockClaimed()).toBe(false); | ||
expect(isDragging(handle)).toBe(false); | ||
|
||
// allowing reclaiming after | ||
simpleLift(control, handle); | ||
|
||
expect(api.isLockClaimed()).toBe(true); | ||
expect(isDragging(handle)).toBe(true); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
test/unit/integration/drag-handle/shared-behaviours/lock-released-pre-drag.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import type { SensorAPI, Sensor } from '../../../../../src/types'; | ||
import { forEachSensor, type Control, simpleLift } from '../../util/controls'; | ||
import { isDragging } from '../../util/helpers'; | ||
import App from '../../util/app'; | ||
import { invariant } from '../../../../../src/invariant'; | ||
|
||
forEachSensor((control: Control) => { | ||
// keyboard has no pre lift | ||
if (control.name === 'keyboard') { | ||
return; | ||
} | ||
|
||
it('should cleanup a drag if a lock is forceably released mid drag', () => { | ||
let api: SensorAPI; | ||
const sensor: Sensor = (value: SensorAPI) => { | ||
api = value; | ||
}; | ||
|
||
const { getByText } = render(<App sensors={[sensor]} />); | ||
const handle: HTMLElement = getByText('item: 0'); | ||
invariant(api); | ||
|
||
control.preLift(handle); | ||
|
||
// lock is claimed but not dragging yet | ||
expect(api.isLockClaimed()).toBe(true); | ||
expect(isDragging(handle)).toBe(false); | ||
|
||
api.tryReleaseLock(); | ||
|
||
expect(isDragging(handle)).toBe(false); | ||
expect(api.isLockClaimed()).toBe(false); | ||
|
||
// a lift after a released lock can get the lock all good | ||
simpleLift(control, handle); | ||
expect(api.isLockClaimed()).toBe(true); | ||
expect(isDragging(handle)).toBe(true); | ||
}); | ||
}); |