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.

group.test.ts 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { ShapeType } from 'types'
  2. import TestState from '../test-utils'
  3. describe('group command', () => {
  4. const tt = new TestState()
  5. tt.resetDocumentState()
  6. .createShape(
  7. {
  8. type: ShapeType.Rectangle,
  9. point: [0, 0],
  10. size: [100, 100],
  11. childIndex: 1,
  12. isLocked: false,
  13. isHidden: false,
  14. isAspectRatioLocked: false,
  15. },
  16. 'rect1'
  17. )
  18. .createShape(
  19. {
  20. type: ShapeType.Rectangle,
  21. point: [400, 0],
  22. size: [100, 100],
  23. childIndex: 2,
  24. isHidden: false,
  25. isLocked: false,
  26. isAspectRatioLocked: false,
  27. },
  28. 'rect2'
  29. )
  30. .save()
  31. // it('deletes the group if it has only one child', () => {
  32. // tt.restore()
  33. // .clickShape('rect1')
  34. // .clickShape('rect2', { shiftKey: true })
  35. // .send('GROUPED')
  36. // const groupId = tt.getShape('rect1').parentId
  37. // expect(groupId === tt.data.currentPageId).toBe(false)
  38. // tt.doubleClickShape('rect1')
  39. // tt.send('DELETED')
  40. // expect(tt.getShape(groupId)).toBe(undefined)
  41. // expect(tt.getShape('rect2')).toBeTruthy()
  42. // })
  43. it('deletes the group if all children are deleted', () => {
  44. tt.restore()
  45. .clickShape('rect1')
  46. .clickShape('rect2', { shiftKey: true })
  47. .send('GROUPED')
  48. const groupId = tt.getShape('rect1').parentId
  49. expect(groupId === tt.data.currentPageId).toBe(false)
  50. tt.doubleClickShape('rect1').clickShape('rect2', { shiftKey: true })
  51. tt.send('DELETED')
  52. expect(tt.getShape(groupId)).toBe(undefined)
  53. })
  54. it('creates a group', () => {
  55. tt.restore()
  56. .clickShape('rect1')
  57. .clickShape('rect2', { shiftKey: true })
  58. .send('GROUPED')
  59. const groupId = tt.getShape('rect1').parentId
  60. expect(groupId === tt.data.currentPageId).toBe(false)
  61. })
  62. it('selects the group on single click', () => {
  63. tt.restore()
  64. .clickShape('rect1')
  65. .clickShape('rect2', { shiftKey: true })
  66. .send('GROUPED')
  67. .clickShape('rect1')
  68. const groupId = tt.getShape('rect1').parentId
  69. expect(tt.selectedIds).toEqual([groupId])
  70. })
  71. it('selects the item on double click', () => {
  72. tt.restore()
  73. .clickShape('rect1')
  74. .clickShape('rect2', { shiftKey: true })
  75. .send('GROUPED')
  76. .doubleClickShape('rect1')
  77. const groupId = tt.getShape('rect1').parentId
  78. expect(tt.data.currentParentId).toBe(groupId)
  79. expect(tt.selectedIds).toEqual(['rect1'])
  80. })
  81. it('resets currentPageId when clicking the canvas', () => {
  82. tt.restore()
  83. .clickShape('rect1')
  84. .clickShape('rect2', { shiftKey: true })
  85. .send('GROUPED')
  86. .doubleClickShape('rect1')
  87. .clickCanvas()
  88. .clickShape('rect1')
  89. const groupId = tt.getShape('rect1').parentId
  90. expect(tt.data.currentParentId).toBe(tt.data.currentPageId)
  91. expect(tt.selectedIds).toEqual([groupId])
  92. })
  93. it('creates a group and undoes and redoes', () => {
  94. tt.restore()
  95. .clickShape('rect1')
  96. .clickShape('rect2', { shiftKey: true })
  97. .send('GROUPED')
  98. const groupId = tt.getShape('rect1').parentId
  99. expect(groupId === tt.data.currentPageId).toBe(false)
  100. tt.undo()
  101. expect(tt.getShape('rect1').parentId === tt.data.currentPageId).toBe(true)
  102. expect(tt.getShape(groupId)).toBe(undefined)
  103. tt.redo()
  104. expect(tt.getShape('rect1').parentId === tt.data.currentPageId).toBe(false)
  105. expect(tt.getShape(groupId)).toBeTruthy()
  106. })
  107. it('groups shapes with different parents', () => {
  108. // TODO
  109. null
  110. })
  111. it('does not group a parent group shape and its child', () => {
  112. // TODO
  113. null
  114. })
  115. })