123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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, undoes and redoes command', () => {
- tt.restore()
-
- const shapesBeforeDuplication = tt.getSortedPageShapeIds()
-
- 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, undoes and redoes command', () => {
- tt.restore()
-
- const shapesBeforeDuplication = tt.getSortedPageShapeIds()
-
- 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)
- })
- })
- })
|