Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: always unsubscribe backend when connector reconnects (#1355)
- Loading branch information
1 parent
f59978e
commit aeeb7c4
Showing
4 changed files
with
107 additions
and
20 deletions.
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
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
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,48 @@ | ||
import SourceConnector from '../SourceConnector' | ||
import { Backend } from 'dnd-core' | ||
|
||
describe('SourceConnector', () => { | ||
let backend: jest.Mocked<Backend> | ||
let connector: SourceConnector | ||
|
||
beforeEach(() => { | ||
backend = { | ||
setup: jest.fn(), | ||
teardown: jest.fn(), | ||
connectDragSource: jest.fn(), | ||
connectDragPreview: jest.fn(), | ||
connectDropTarget: jest.fn(), | ||
} | ||
connector = new SourceConnector(backend) | ||
}) | ||
|
||
it('unsubscribes drag source when clearing handler id', () => { | ||
const unsubscribeDragSource = jest.fn() | ||
backend.connectDragSource.mockReturnValueOnce(unsubscribeDragSource) | ||
|
||
connector.receiveHandlerId('test') | ||
connector.hooks.dragSource()({}) | ||
expect(backend.connectDragSource).toHaveBeenCalled() | ||
expect(unsubscribeDragSource).not.toHaveBeenCalled() | ||
backend.connectDragSource.mockClear() | ||
|
||
connector.receiveHandlerId(null) | ||
expect(backend.connectDragSource).not.toHaveBeenCalled() | ||
expect(unsubscribeDragSource).toHaveBeenCalled() | ||
}) | ||
|
||
it('unsubscribes drag preview when clearing handler id', () => { | ||
const unsubscribeDragPreview = jest.fn() | ||
backend.connectDragPreview.mockReturnValueOnce(unsubscribeDragPreview) | ||
|
||
connector.receiveHandlerId('test') | ||
connector.hooks.dragPreview()({}) | ||
expect(backend.connectDragPreview).toHaveBeenCalled() | ||
expect(unsubscribeDragPreview).not.toHaveBeenCalled() | ||
backend.connectDragPreview.mockClear() | ||
|
||
connector.receiveHandlerId(null) | ||
expect(backend.connectDragPreview).not.toHaveBeenCalled() | ||
expect(unsubscribeDragPreview).toHaveBeenCalled() | ||
}) | ||
}) |
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,26 @@ | ||
import TargetConnector from '../TargetConnector' | ||
|
||
describe('TargetConnector', () => { | ||
it('unsubscribes drop target when clearing handler id', () => { | ||
const backend = { | ||
setup: jest.fn(), | ||
teardown: jest.fn(), | ||
connectDragSource: jest.fn(), | ||
connectDragPreview: jest.fn(), | ||
connectDropTarget: jest.fn(), | ||
} | ||
const connector = new TargetConnector(backend) | ||
const unsubscribeDropTarget = jest.fn() | ||
backend.connectDropTarget.mockReturnValueOnce(unsubscribeDropTarget) | ||
|
||
connector.receiveHandlerId('test') | ||
connector.hooks.dropTarget()({}) | ||
expect(backend.connectDropTarget).toHaveBeenCalled() | ||
expect(unsubscribeDropTarget).not.toHaveBeenCalled() | ||
backend.connectDropTarget.mockClear() | ||
|
||
connector.receiveHandlerId(null) | ||
expect(backend.connectDropTarget).not.toHaveBeenCalled() | ||
expect(unsubscribeDropTarget).toHaveBeenCalled() | ||
}) | ||
}) |