2021-06-26 11:52:36 +00:00
|
|
|
import { ShapeType } from 'types'
|
2021-07-09 08:59:43 +00:00
|
|
|
import TestState, { rectangleId, arrowId } from '../test-utils'
|
2021-06-24 12:34:43 +00:00
|
|
|
|
2021-07-09 08:59:43 +00:00
|
|
|
describe('delete command', () => {
|
2021-07-01 14:03:02 +00:00
|
|
|
const tt = new TestState()
|
2021-06-24 12:34:43 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
describe('deleting single shapes', () => {
|
|
|
|
it('deletes a shape and undoes the delete', () => {
|
|
|
|
tt.deselectAll().clickShape(rectangleId).pressDelete()
|
2021-06-24 12:34:43 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.idsAreSelected([])).toBe(true)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.getShape(rectangleId)).toBe(undefined)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
tt.undo()
|
2021-06-24 12:34:43 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.getShape(rectangleId)).toBeTruthy()
|
|
|
|
expect(tt.idsAreSelected([rectangleId])).toBe(true)
|
2021-06-24 12:34:43 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
tt.redo()
|
2021-06-24 12:34:43 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.getShape(rectangleId)).toBe(undefined)
|
|
|
|
})
|
|
|
|
})
|
2021-06-24 12:34:43 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
describe('deleting and restoring grouped shapes', () => {
|
|
|
|
it('creates a group', () => {
|
|
|
|
tt.reset()
|
|
|
|
.deselectAll()
|
|
|
|
.clickShape(rectangleId)
|
|
|
|
.clickShape(arrowId, { shiftKey: true })
|
|
|
|
.send('GROUPED')
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
const group = tt.getOnlySelectedShape()
|
|
|
|
|
|
|
|
// Should select the group
|
|
|
|
expect(tt.assertShapeProps(group, { type: ShapeType.Group })).toBe(true)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
const arrow = tt.getShape(arrowId)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
// The arrow should be have the group as its parent
|
|
|
|
expect(tt.assertShapeProps(arrow, { parentId: group.id })).toBe(true)
|
|
|
|
})
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
it('selects the new group', () => {
|
|
|
|
const groupId = tt.getShape(arrowId).parentId
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.idsAreSelected([groupId])).toBe(true)
|
|
|
|
})
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
it('assigns a new parent', () => {
|
|
|
|
const groupId = tt.getShape(arrowId).parentId
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(groupId === tt.data.currentPageId).toBe(false)
|
|
|
|
})
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
// Rectangle has the same new parent?
|
|
|
|
it('assigns new parent to all selected shapes', () => {
|
|
|
|
const groupId = tt.getShape(arrowId).parentId
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.hasParent(arrowId, groupId)).toBe(true)
|
|
|
|
})
|
2021-06-26 11:52:36 +00:00
|
|
|
})
|
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
describe('selecting within the group', () => {
|
|
|
|
it('selects the group when pointing a shape', () => {
|
|
|
|
const groupId = tt.getShape(arrowId).parentId
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
tt.deselectAll().clickShape(rectangleId)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.idsAreSelected([groupId])).toBe(true)
|
|
|
|
})
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
it('keeps selection when pointing group shape', () => {
|
|
|
|
const groupId = tt.getShape(arrowId).parentId
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
tt.deselectAll().clickShape(groupId)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.idsAreSelected([groupId])).toBe(true)
|
|
|
|
})
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
it('selects a grouped shape by double-pointing', () => {
|
|
|
|
tt.deselectAll().doubleClickShape(rectangleId)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.idsAreSelected([rectangleId])).toBe(true)
|
|
|
|
})
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
it('selects a sibling on point after double-pointing into a grouped shape children', () => {
|
|
|
|
tt.deselectAll().doubleClickShape(rectangleId).clickShape(arrowId)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.idsAreSelected([arrowId])).toBe(true)
|
|
|
|
})
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
it('rises up a selection level when escape is pressed', () => {
|
|
|
|
const groupId = tt.getShape(arrowId).parentId
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
tt.deselectAll().doubleClickShape(rectangleId).send('CANCELLED')
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
tt.clickShape(rectangleId)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
expect(tt.idsAreSelected([groupId])).toBe(true)
|
|
|
|
})
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
// it('deletes and restores one shape', () => {
|
|
|
|
// // Delete the rectangle first
|
|
|
|
// state.send('UNDO')
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
// expect(tld.getShape(tt.data, rectangleId)).toBeTruthy()
|
|
|
|
// expect(tt.idsAreSelected([rectangleId])).toBe(true)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
// state.send('REDO')
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
// expect(tld.getShape(tt.data, rectangleId)).toBe(undefined)
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
// state.send('UNDO')
|
2021-06-26 11:52:36 +00:00
|
|
|
|
2021-07-01 14:03:02 +00:00
|
|
|
// expect(tld.getShape(tt.data, rectangleId)).toBeTruthy()
|
|
|
|
// expect(tt.idsAreSelected([rectangleId])).toBe(true)
|
|
|
|
})
|
|
|
|
})
|