You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

delete.test.ts 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import state from 'state'
  2. import inputs from 'state/inputs'
  3. import { ShapeType } from 'types'
  4. import {
  5. idsAreSelected,
  6. point,
  7. rectangleId,
  8. arrowId,
  9. getOnlySelectedShape,
  10. assertShapeProps,
  11. } from './test-utils'
  12. import tld from 'utils/tld'
  13. import * as json from './__mocks__/document.json'
  14. describe('deleting single shapes', () => {
  15. state.reset()
  16. state.send('MOUNTED').send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
  17. it('deletes a shape and undoes the delete', () => {
  18. state
  19. .send('CANCELED')
  20. .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  21. .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  22. expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
  23. state.send('DELETED')
  24. expect(idsAreSelected(state.data, [])).toBe(true)
  25. expect(tld.getShape(state.data, rectangleId)).toBe(undefined)
  26. state.send('UNDO')
  27. expect(tld.getShape(state.data, rectangleId)).toBeTruthy()
  28. expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
  29. state.send('REDO')
  30. expect(tld.getShape(state.data, rectangleId)).toBe(undefined)
  31. state.send('UNDO')
  32. })
  33. })
  34. describe('deletes and restores grouped shapes', () => {
  35. state.reset()
  36. state.send('MOUNTED').send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
  37. it('creates a group', () => {
  38. state
  39. .send('CANCELED')
  40. .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  41. .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  42. .send(
  43. 'POINTED_SHAPE',
  44. inputs.pointerDown(point({ shiftKey: true }), arrowId)
  45. )
  46. .send(
  47. 'STOPPED_POINTING',
  48. inputs.pointerUp(point({ shiftKey: true }), arrowId)
  49. )
  50. expect(idsAreSelected(state.data, [rectangleId, arrowId])).toBe(true)
  51. state.send('GROUPED')
  52. const group = getOnlySelectedShape(state.data)
  53. // Should select the group
  54. expect(assertShapeProps(group, { type: ShapeType.Group }))
  55. const arrow = tld.getShape(state.data, arrowId)
  56. // The arrow should be have the group as its parent
  57. expect(assertShapeProps(arrow, { parentId: group.id }))
  58. })
  59. // it('selects the new group', () => {
  60. // expect(idsAreSelected(state.data, [groupId])).toBe(true)
  61. // })
  62. // it('assigns a new parent', () => {
  63. // expect(groupId === state.data.currentPageId).toBe(false)
  64. // })
  65. // // Rectangle has the same new parent?
  66. // it('assigns new parent to all selected shapes', () => {
  67. // expect(hasParent(state.data, arrowId, groupId)).toBe(true)
  68. // })
  69. // // New parent is selected?
  70. // it('selects the new parent', () => {
  71. // expect(idsAreSelected(state.data, [groupId])).toBe(true)
  72. // })
  73. })
  74. // // it('selects the group when pointing a shape', () => {
  75. // // state
  76. // // .send('CANCELED')
  77. // // .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  78. // // .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  79. // // expect(idsAreSelected(state.data, [groupId])).toBe(true)
  80. // // })
  81. // // it('keeps selection when pointing bounds', () => {
  82. // // state
  83. // // .send('CANCELED')
  84. // // .send('POINTED_BOUNDS', inputs.pointerDown(point(), 'bounds'))
  85. // // .send('STOPPED_POINTING', inputs.pointerUp(point(), 'bounds'))
  86. // // expect(idsAreSelected(state.data, [groupId])).toBe(true)
  87. // // })
  88. // // it('selects a grouped shape by double-pointing', () => {
  89. // // state
  90. // // .send('CANCELED')
  91. // // .send('DOUBLE_POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  92. // // .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  93. // // expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
  94. // // })
  95. // // it('selects a sibling on point when selecting a grouped shape', () => {
  96. // // state
  97. // // .send('POINTED_SHAPE', inputs.pointerDown(point(), arrowId))
  98. // // .send('STOPPED_POINTING', inputs.pointerUp(point(), arrowId))
  99. // // expect(idsAreSelected(state.data, [arrowId])).toBe(true)
  100. // // })
  101. // // it('rises up a selection level when escape is pressed', () => {
  102. // // state
  103. // // .send('CANCELED')
  104. // // .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  105. // // .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  106. // // expect(idsAreSelected(state.data, [groupId])).toBe(true)
  107. // // })
  108. // // it('deletes and restores one shape', () => {
  109. // // // Delete the rectangle first
  110. // // state.send('UNDO')
  111. // // expect(tld.getShape(state.data, rectangleId)).toBeTruthy()
  112. // // expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
  113. // // state.send('REDO')
  114. // // expect(tld.getShape(state.data, rectangleId)).toBe(undefined)
  115. // // state.send('UNDO')
  116. // // expect(tld.getShape(state.data, rectangleId)).toBeTruthy()
  117. // // expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
  118. // // })
  119. // })