Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const root = mount()
// Obtain a reference to the backend
const backend = getBackendFromInstance(root.instance() as any)
// Find the drag source ID and use it to simulate the dragging operation
const box: DndComponent = root
.find(Box)
.at(0)
.instance() as any
const dustbin: DndComponent = root
.find(Dustbin)
.instance() as any
window.alert = jest.fn()
simulateDragDropSequence(box, dustbin, backend)
expect(window.alert).toHaveBeenCalledWith(
`You dropped ${box.props.name} into Dustbin!`,
)
})
})
// interactions
// drop bottle into glass bin
simulateDragDropSequence(bottleBox, glassBin, backend)
expect(glassBin.props.lastDroppedItem.name).toEqual(bottleBox.props.name)
// food won't drop into the glass bin
simulateDragDropSequence(bananaBox, glassBin, backend)
expect(glassBin.props.lastDroppedItem.name).toEqual(bottleBox.props.name)
// glass won't drop into the food box...
simulateDragDropSequence(bottleBox, foodBin, backend)
expect(foodBin.props.lastDroppedItem).toBeNull()
// but some food will work
simulateDragDropSequence(bananaBox, foodBin, backend)
expect(foodBin.props.lastDroppedItem.name).toEqual(bananaBox.props.name)
})
})
const bottleBox: DndC = boxes.at(0).instance() as any
const bananaBox: DndC = boxes.at(1).instance() as any
// const magazineBox: DndC = boxes.at(2).instance() as any
// interactions
// drop bottle into glass bin
simulateDragDropSequence(bottleBox, glassBin, backend)
expect(glassBin.props.lastDroppedItem.name).toEqual(bottleBox.props.name)
// food won't drop into the glass bin
simulateDragDropSequence(bananaBox, glassBin, backend)
expect(glassBin.props.lastDroppedItem.name).toEqual(bottleBox.props.name)
// glass won't drop into the food box...
simulateDragDropSequence(bottleBox, foodBin, backend)
expect(foodBin.props.lastDroppedItem).toBeNull()
// but some food will work
simulateDragDropSequence(bananaBox, foodBin, backend)
expect(foodBin.props.lastDroppedItem.name).toEqual(bananaBox.props.name)
})
})
// .instance() as any
// const paperFileBin: DndC = dustbins.at(3).instance() as any
// Box Types
const bottleBox: DndC = boxes.at(0).instance() as any
const bananaBox: DndC = boxes.at(1).instance() as any
// const magazineBox: DndC = boxes.at(2).instance() as any
// interactions
// drop bottle into glass bin
simulateDragDropSequence(bottleBox, glassBin, backend)
expect(glassBin.props.lastDroppedItem.name).toEqual(bottleBox.props.name)
// food won't drop into the glass bin
simulateDragDropSequence(bananaBox, glassBin, backend)
expect(glassBin.props.lastDroppedItem.name).toEqual(bottleBox.props.name)
// glass won't drop into the food box...
simulateDragDropSequence(bottleBox, foodBin, backend)
expect(foodBin.props.lastDroppedItem).toBeNull()
// but some food will work
simulateDragDropSequence(bananaBox, foodBin, backend)
expect(foodBin.props.lastDroppedItem.name).toEqual(bananaBox.props.name)
})
})
const glassBin: DndC = dustbins.at(0).instance() as any
const foodBin: DndC = dustbins.at(1).instance() as any
// const paperGlassUrlBin: DndC = dustbins
// .at(2)
// .instance() as any
// const paperFileBin: DndC = dustbins.at(3).instance() as any
// Box Types
const bottleBox: DndC = boxes.at(0).instance() as any
const bananaBox: DndC = boxes.at(1).instance() as any
// const magazineBox: DndC = boxes.at(2).instance() as any
// interactions
// drop bottle into glass bin
simulateDragDropSequence(bottleBox, glassBin, backend)
expect(glassBin.props.lastDroppedItem.name).toEqual(bottleBox.props.name)
// food won't drop into the glass bin
simulateDragDropSequence(bananaBox, glassBin, backend)
expect(glassBin.props.lastDroppedItem.name).toEqual(bottleBox.props.name)
// glass won't drop into the food box...
simulateDragDropSequence(bottleBox, foodBin, backend)
expect(foodBin.props.lastDroppedItem).toBeNull()
// but some food will work
simulateDragDropSequence(bananaBox, foodBin, backend)
expect(foodBin.props.lastDroppedItem.name).toEqual(bananaBox.props.name)
})
})