Skip to content

Commit

Permalink
make tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-katayama committed May 12, 2024
1 parent 28d0810 commit 6893ea6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion __tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export const mockInnerHTML: string = `
item 3
</li>
</ul>
<ul class="second-sortable all-sortables"></ul>`
<ul class="second-sortable all-sortables"></ul>
<div class="custom-drag-img-string"></div>
`
17 changes: 17 additions & 0 deletions __tests__/setDragImage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,21 @@ describe('Testing setDragImage', () => {
// third argument in call
expect(mockCustomDragImageFn.mock.calls[0][2]).toBe(event)
})
test('Valid customDragImage Selector', () => {
const event = new DragEvent('dragstart')
const customDragImage = document.querySelectorAll('.custom-drag-img-string')
customDragImage[0].getClientRects = () => [{ left: 20, right: 40, top: 20, bottom: 40 }]

// Execute
setDragImage(event, element, customDragImage)

// Verify effectAllowed and data set correctly
expect(event.dataTransfer.effectAllowed).toEqual('copyMove')
expect(event.data).toEqual('text/plain')
})
test('Invalid customDragImage Selector', () => {
const event = new DragEvent('dragstart')
const customDragImage = document.querySelectorAll('.non-exist-selector')
expect(() => { setDragImage(event, element, customDragImage) }).toThrowError('The NodeList provided does not contain any valid elements.')
})
})

0 comments on commit 6893ea6

Please sign in to comment.