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'
describe('duplicate command', () => {
const tt = new TestState()
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', () => {
it('does command', () => {
// TODO
null
})
it('does, undoes and redoes command', () => {
tt.restore()
it('un-does command', () => {
// TODO
null
})
const shapesBeforeDuplication = tt.getSortedPageShapeIds()
it('re-does command', () => {
// TODO
null
tt.clickShape('rectangleShape').send('DUPLICATED')
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', () => {
it('does command', () => {
// TODO
null
})
it('does, undoes and redoes command', () => {
tt.restore()
it('un-does command', () => {
// TODO
null
})
const shapesBeforeDuplication = tt.getSortedPageShapeIds()
it('re-does command', () => {
// TODO
null
tt.clickShape('rectangleShape')
.clickShape('ellipseShape', { shiftKey: true })
.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)
})
})
})