| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- import state from 'state'
- import inputs from 'state/inputs'
- import { ShapeType } from 'types'
- import { getShape } from 'utils'
- import {
- idsAreSelected,
- point,
- rectangleId,
- arrowId,
- getOnlySelectedShape,
- assertShapeProps,
- } from './test-utils'
- import * as json from './__mocks__/document.json'
-
- describe('deleting single shapes', () => {
- state.reset()
- state.send('MOUNTED').send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
-
- it('deletes a shape and undoes the delete', () => {
- state
- .send('CANCELED')
- .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
- .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
-
- expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
-
- state.send('DELETED')
-
- expect(idsAreSelected(state.data, [])).toBe(true)
- expect(getShape(state.data, rectangleId)).toBe(undefined)
-
- state.send('UNDO')
-
- expect(getShape(state.data, rectangleId)).toBeTruthy()
- expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
-
- state.send('REDO')
-
- expect(getShape(state.data, rectangleId)).toBe(undefined)
-
- state.send('UNDO')
- })
- })
-
- describe('deletes and restores grouped shapes', () => {
- state.reset()
- state.send('MOUNTED').send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
-
- it('creates a group', () => {
- expect(state.data.document).toMatchSnapshot('data after mount from file')
-
- state
- .send('CANCELED')
- .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
- .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
- .send(
- 'POINTED_SHAPE',
- inputs.pointerDown(point({ shiftKey: true }), arrowId)
- )
- .send(
- 'STOPPED_POINTING',
- inputs.pointerUp(point({ shiftKey: true }), arrowId)
- )
-
- expect(idsAreSelected(state.data, [rectangleId, arrowId])).toBe(true)
-
- state.send('GROUPED')
-
- const group = getOnlySelectedShape(state.data)
-
- // Should select the group
- expect(assertShapeProps(group, { type: ShapeType.Group }))
-
- const arrow = getShape(state.data, arrowId)
-
- // The arrow should be have the group as its parent
- expect(assertShapeProps(arrow, { parentId: group.id }))
- })
-
- // it('selects the new group', () => {
- // expect(idsAreSelected(state.data, [groupId])).toBe(true)
- // })
-
- // it('assigns a new parent', () => {
- // expect(groupId === state.data.currentPageId).toBe(false)
- // })
-
- // // Rectangle has the same new parent?
- // it('assigns new parent to all selected shapes', () => {
- // expect(hasParent(state.data, arrowId, groupId)).toBe(true)
- // })
-
- // // New parent is selected?
- // it('selects the new parent', () => {
- // expect(idsAreSelected(state.data, [groupId])).toBe(true)
- // })
- })
-
- // // it('selects the group when pointing a shape', () => {
- // // state
- // // .send('CANCELED')
- // // .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
- // // .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
-
- // // expect(idsAreSelected(state.data, [groupId])).toBe(true)
- // // })
-
- // // it('keeps selection when pointing bounds', () => {
- // // state
- // // .send('CANCELED')
- // // .send('POINTED_BOUNDS', inputs.pointerDown(point(), 'bounds'))
- // // .send('STOPPED_POINTING', inputs.pointerUp(point(), 'bounds'))
-
- // // expect(idsAreSelected(state.data, [groupId])).toBe(true)
- // // })
-
- // // it('selects a grouped shape by double-pointing', () => {
- // // state
- // // .send('CANCELED')
- // // .send('DOUBLE_POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
- // // .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
-
- // // expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
- // // })
-
- // // it('selects a sibling on point when selecting a grouped shape', () => {
- // // state
- // // .send('POINTED_SHAPE', inputs.pointerDown(point(), arrowId))
- // // .send('STOPPED_POINTING', inputs.pointerUp(point(), arrowId))
-
- // // expect(idsAreSelected(state.data, [arrowId])).toBe(true)
- // // })
-
- // // it('rises up a selection level when escape is pressed', () => {
- // // state
- // // .send('CANCELED')
- // // .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
- // // .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
-
- // // expect(idsAreSelected(state.data, [groupId])).toBe(true)
- // // })
-
- // // it('deletes and restores one shape', () => {
- // // // Delete the rectangle first
- // // state.send('UNDO')
-
- // // expect(getShape(state.data, rectangleId)).toBeTruthy()
- // // expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
-
- // // state.send('REDO')
-
- // // expect(getShape(state.data, rectangleId)).toBe(undefined)
-
- // // state.send('UNDO')
-
- // // expect(getShape(state.data, rectangleId)).toBeTruthy()
- // // expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
- // // })
- // })
|