test(commands): add coverage for duplicate command

This commit is contained in:
Tais Massaro 2021-07-20 23:09:45 +02:00
parent 1459a96a00
commit 6a68867e0c

View file

@ -1,40 +1,116 @@
import { ShapeType } from 'types'
import TestState from '../test-utils' import TestState from '../test-utils'
describe('duplicate command', () => { describe('duplicate command', () => {
const tt = new TestState() const tt = new TestState()
tt.resetDocumentState() tt.resetDocumentState()
.createShape(
{
type: ShapeType.Rectangle,
point: [0, 0],
size: [100, 100],
},
'rectangleShape'
)
.createShape(
{
type: ShapeType.Ellipse,
point: [150, 150],
radiusX: 50,
radiusY: 50,
},
'ellipseShape'
)
.save()
describe('when one item is selected', () => { describe('when one item is selected', () => {
it('does command', () => { it('does, undoes and redoes command', () => {
// TODO tt.restore()
null
})
it('un-does command', () => { const shapesBeforeDuplication = tt.getSortedPageShapeIds()
// TODO
null
})
it('re-does command', () => { tt.clickShape('rectangleShape').send('DUPLICATED')
// TODO
null const shapesAfterDuplication = tt.getSortedPageShapeIds()
const duplicatedShapeId = tt.selectedIds[0]
const duplicatedShape = tt.getShape(duplicatedShapeId)
expect(shapesAfterDuplication.length).toEqual(
shapesBeforeDuplication.length + 1
)
expect(
tt.assertShapeProps(duplicatedShape, {
type: ShapeType.Rectangle,
size: [100, 100],
})
)
tt.undo()
const shapesAfterUndo = tt.getSortedPageShapeIds()
expect(shapesAfterUndo.length).toEqual(shapesBeforeDuplication.length)
expect(tt.getShape(duplicatedShapeId)).toBe(undefined)
expect(tt.idsAreSelected(['rectangleShape'])).toBe(true)
tt.redo()
expect(tt.getShape(duplicatedShapeId)).toBeTruthy()
expect(tt.idsAreSelected([duplicatedShapeId])).toBe(true)
}) })
}) })
describe('when multiple items are selected', () => { describe('when multiple items are selected', () => {
it('does command', () => { it('does, undoes and redoes command', () => {
// TODO tt.restore()
null
})
it('un-does command', () => { const shapesBeforeDuplication = tt.getSortedPageShapeIds()
// TODO
null
})
it('re-does command', () => { tt.clickShape('rectangleShape')
// TODO .clickShape('ellipseShape', { shiftKey: true })
null .send('DUPLICATED')
const shapesAfterDuplication = tt.getSortedPageShapeIds()
const duplicatedShapesIds = tt.selectedIds
const [duplicatedRectangle, duplicatedEllipse] = duplicatedShapesIds.map(
(shapeId) => tt.getShape(shapeId)
)
expect(shapesAfterDuplication.length).toEqual(
shapesBeforeDuplication.length * 2
)
expect(
tt.assertShapeProps(duplicatedRectangle, {
type: ShapeType.Rectangle,
size: [100, 100],
})
)
expect(
tt.assertShapeProps(duplicatedEllipse, {
type: ShapeType.Ellipse,
radiusX: 50,
radiusY: 50,
})
)
tt.undo()
const shapesAfterUndo = tt.getSortedPageShapeIds()
expect(shapesAfterUndo.length).toEqual(shapesBeforeDuplication.length)
duplicatedShapesIds.forEach((shapeId) => {
expect(tt.getShape(shapeId)).toBe(undefined)
})
expect(tt.idsAreSelected(['rectangleShape', 'ellipseShape'])).toBe(true)
tt.redo()
duplicatedShapesIds.forEach((shapeId) => {
expect(tt.getShape(shapeId)).toBeTruthy()
})
expect(tt.idsAreSelected(duplicatedShapesIds)).toBe(true)
}) })
}) })
}) })