您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

delete.test.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { ShapeType } from 'types'
  2. import TestState, { rectangleId, arrowId } from '../test-utils'
  3. describe('delete command', () => {
  4. const tt = new TestState()
  5. describe('deleting single shapes', () => {
  6. it('deletes a shape and undoes the delete', () => {
  7. tt.deselectAll().clickShape(rectangleId).pressDelete()
  8. expect(tt.idsAreSelected([])).toBe(true)
  9. expect(tt.getShape(rectangleId)).toBe(undefined)
  10. tt.undo()
  11. expect(tt.getShape(rectangleId)).toBeTruthy()
  12. expect(tt.idsAreSelected([rectangleId])).toBe(true)
  13. tt.redo()
  14. expect(tt.getShape(rectangleId)).toBe(undefined)
  15. })
  16. })
  17. describe('deleting and restoring grouped shapes', () => {
  18. it('creates a group', () => {
  19. tt.reset()
  20. .deselectAll()
  21. .clickShape(rectangleId)
  22. .clickShape(arrowId, { shiftKey: true })
  23. .send('GROUPED')
  24. const group = tt.getOnlySelectedShape()
  25. // Should select the group
  26. expect(tt.assertShapeProps(group, { type: ShapeType.Group })).toBe(true)
  27. const arrow = tt.getShape(arrowId)
  28. // The arrow should be have the group as its parent
  29. expect(tt.assertShapeProps(arrow, { parentId: group.id })).toBe(true)
  30. })
  31. it('selects the new group', () => {
  32. const groupId = tt.getShape(arrowId).parentId
  33. expect(tt.idsAreSelected([groupId])).toBe(true)
  34. })
  35. it('assigns a new parent', () => {
  36. const groupId = tt.getShape(arrowId).parentId
  37. expect(groupId === tt.data.currentPageId).toBe(false)
  38. })
  39. // Rectangle has the same new parent?
  40. it('assigns new parent to all selected shapes', () => {
  41. const groupId = tt.getShape(arrowId).parentId
  42. expect(tt.hasParent(arrowId, groupId)).toBe(true)
  43. })
  44. })
  45. describe('selecting within the group', () => {
  46. it('selects the group when pointing a shape', () => {
  47. const groupId = tt.getShape(arrowId).parentId
  48. tt.deselectAll().clickShape(rectangleId)
  49. expect(tt.idsAreSelected([groupId])).toBe(true)
  50. })
  51. it('keeps selection when pointing group shape', () => {
  52. const groupId = tt.getShape(arrowId).parentId
  53. tt.deselectAll().clickShape(groupId)
  54. expect(tt.idsAreSelected([groupId])).toBe(true)
  55. })
  56. it('selects a grouped shape by double-pointing', () => {
  57. tt.deselectAll().doubleClickShape(rectangleId)
  58. expect(tt.idsAreSelected([rectangleId])).toBe(true)
  59. })
  60. it('selects a sibling on point after double-pointing into a grouped shape children', () => {
  61. tt.deselectAll().doubleClickShape(rectangleId).clickShape(arrowId)
  62. expect(tt.idsAreSelected([arrowId])).toBe(true)
  63. })
  64. it('rises up a selection level when escape is pressed', () => {
  65. const groupId = tt.getShape(arrowId).parentId
  66. tt.deselectAll().doubleClickShape(rectangleId).send('CANCELLED')
  67. tt.clickShape(rectangleId)
  68. expect(tt.idsAreSelected([groupId])).toBe(true)
  69. })
  70. // it('deletes and restores one shape', () => {
  71. // // Delete the rectangle first
  72. // state.send('UNDO')
  73. // expect(tld.getShape(tt.data, rectangleId)).toBeTruthy()
  74. // expect(tt.idsAreSelected([rectangleId])).toBe(true)
  75. // state.send('REDO')
  76. // expect(tld.getShape(tt.data, rectangleId)).toBe(undefined)
  77. // state.send('UNDO')
  78. // expect(tld.getShape(tt.data, rectangleId)).toBeTruthy()
  79. // expect(tt.idsAreSelected([rectangleId])).toBe(true)
  80. })
  81. })