-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
182044e
commit 400283a
Showing
1 changed file
with
5 additions
and
56 deletions.
There are no files selected for viewing
61 changes: 5 additions & 56 deletions
61
...ages/lib-classifier/src/plugins/drawingTools/components/DeleteButton/DeleteButton.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 |
---|---|---|
@@ -1,70 +1,19 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { render, screen } from '@testing-library/react' | ||
import { expect } from 'chai' | ||
import sinon from 'sinon' | ||
import { Point } from '@plugins/drawingTools/models/marks' | ||
import { DeleteButton } from './DeleteButton' | ||
|
||
describe('Drawing tools > DeleteButton', function () { | ||
const mark = Point.create({ id: 'point1', x: 50, y: 50, toolType: 'point' }) | ||
|
||
it('should render without crashing', function () { | ||
const wrapper = shallow(<DeleteButton label='Delete' mark={mark} />) | ||
expect(wrapper).to.be.ok() | ||
}) | ||
|
||
it('should be positioned by its mark', function () { | ||
const { x, y } = mark.deleteButtonPosition(1) | ||
const wrapper = shallow(<DeleteButton label='Delete' mark={mark} />) | ||
const transform = wrapper.root().prop('transform') | ||
expect(transform).to.have.string(`translate(${x}, ${y})`) | ||
}) | ||
|
||
describe('on pointer down', function () { | ||
it('should call onDelete', function () { | ||
const fakeEvent = new Event('pointerdown') | ||
const onDelete = sinon.stub() | ||
const wrapper = shallow(<DeleteButton label='Delete' mark={mark} onDelete={onDelete} />) | ||
wrapper.simulate('pointerdown', fakeEvent) | ||
expect(onDelete).to.have.been.calledOnce() | ||
}) | ||
}) | ||
render(<DeleteButton label='Delete' mark={mark} />) | ||
|
||
describe('on blur', function () { | ||
it('should be deselected', function () { | ||
const onDeselect = sinon.spy() | ||
const wrapper = shallow(<DeleteButton label='Delete' mark={mark} onDeselect={onDeselect} />) | ||
wrapper.simulate('blur') | ||
expect(onDeselect).to.have.been.calledOnce() | ||
}) | ||
}) | ||
|
||
describe('on key down', function () { | ||
it('should call onDelete for Enter', function () { | ||
const fakeEvent = new Event('keydown') | ||
fakeEvent.key = 'Enter' | ||
const onDelete = sinon.stub() | ||
const wrapper = shallow(<DeleteButton label='Delete' mark={mark} onDelete={onDelete} />) | ||
wrapper.simulate('keydown', fakeEvent) | ||
expect(onDelete).to.have.been.calledOnce() | ||
const deleteButton = screen.getByRole('button', { | ||
name: /delete/i | ||
}) | ||
|
||
it('should call onDelete for space', function () { | ||
const fakeEvent = new Event('keydown') | ||
fakeEvent.key = ' ' | ||
const onDelete = sinon.stub() | ||
const wrapper = shallow(<DeleteButton label='Delete' mark={mark} onDelete={onDelete} />) | ||
wrapper.simulate('keydown', fakeEvent) | ||
expect(onDelete).to.have.been.calledOnce() | ||
}) | ||
|
||
it('should ignore any other key', function () { | ||
const fakeEvent = new Event('keydown') | ||
fakeEvent.key = 'Tab' | ||
const onDelete = sinon.stub() | ||
const wrapper = shallow(<DeleteButton label='Delete' mark={mark} onDelete={onDelete} />) | ||
wrapper.simulate('keydown', fakeEvent) | ||
expect(onDelete).to.have.not.been.called() | ||
}) | ||
expect(deleteButton).to.exist() | ||
}) | ||
}) |