選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

children.test.ts 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import { MoveType, ShapeType } from 'types'
  2. import TestState from './test-utils'
  3. describe('shapes with children', () => {
  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. },
  13. 'delete-me-bottom'
  14. )
  15. .createShape(
  16. {
  17. type: ShapeType.Rectangle,
  18. point: [0, 0],
  19. size: [100, 100],
  20. childIndex: 2,
  21. },
  22. '1'
  23. )
  24. .createShape(
  25. {
  26. type: ShapeType.Rectangle,
  27. point: [300, 0],
  28. size: [100, 100],
  29. childIndex: 3,
  30. },
  31. '2'
  32. )
  33. .createShape(
  34. {
  35. type: ShapeType.Rectangle,
  36. point: [0, 300],
  37. size: [100, 100],
  38. childIndex: 4,
  39. },
  40. 'delete-me-middle'
  41. )
  42. .createShape(
  43. {
  44. type: ShapeType.Rectangle,
  45. point: [0, 300],
  46. size: [100, 100],
  47. childIndex: 5,
  48. },
  49. '3'
  50. )
  51. .createShape(
  52. {
  53. type: ShapeType.Rectangle,
  54. point: [300, 300],
  55. size: [100, 100],
  56. childIndex: 6,
  57. },
  58. '4'
  59. )
  60. // Delete shapes at the start and in the middle of the list
  61. tt.clickShape('delete-me-bottom')
  62. .send('DELETED')
  63. .clickShape('delete-me-middle')
  64. .send('DELETED')
  65. it('has shapes in order', () => {
  66. expect(
  67. Object.values(tt.data.document.pages[tt.data.currentParentId].shapes)
  68. .sort((a, b) => a.childIndex - b.childIndex)
  69. .map((shape) => shape.childIndex)
  70. ).toStrictEqual([2, 3, 5, 6])
  71. })
  72. it('moves a shape to back', () => {
  73. tt.clickShape('3').send('MOVED', {
  74. type: MoveType.ToBack,
  75. })
  76. expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '1', '2', '4'])
  77. })
  78. it('moves two adjacent siblings to back', () => {
  79. tt.clickShape('4').clickShape('2', { shiftKey: true }).send('MOVED', {
  80. type: MoveType.ToBack,
  81. })
  82. expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '4', '3', '1'])
  83. })
  84. it('moves two non-adjacent siblings to back', () => {
  85. tt.clickShape('4').clickShape('1', { shiftKey: true }).send('MOVED', {
  86. type: MoveType.ToBack,
  87. })
  88. expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '1', '2', '3'])
  89. })
  90. it('moves a shape backward', () => {
  91. tt.clickShape('3').send('MOVED', {
  92. type: MoveType.Backward,
  93. })
  94. expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '1', '3', '2'])
  95. })
  96. it('moves a shape at first index backward', () => {
  97. tt.clickShape('4').send('MOVED', {
  98. type: MoveType.Backward,
  99. })
  100. expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '1', '3', '2'])
  101. })
  102. it('moves two adjacent siblings backward', () => {
  103. tt.clickShape('3').clickShape('2', { shiftKey: true }).send('MOVED', {
  104. type: MoveType.Backward,
  105. })
  106. expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '3', '2', '1'])
  107. })
  108. it('moves two non-adjacent siblings backward', () => {
  109. tt.clickShape('3')
  110. .clickShape('1', { shiftKey: true })
  111. .send('MOVED', { type: MoveType.Backward })
  112. expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '4', '1', '2'])
  113. })
  114. it('moves two adjacent siblings backward at zero index', () => {
  115. tt.clickShape('3').clickShape('4', { shiftKey: true }).send('MOVED', {
  116. type: MoveType.Backward,
  117. })
  118. expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '4', '1', '2'])
  119. })
  120. it('moves a shape forward', () => {
  121. tt.clickShape('4').send('MOVED', {
  122. type: MoveType.Forward,
  123. })
  124. expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '1', '4', '2'])
  125. })
  126. it('moves a shape forward at the top index', () => {
  127. tt.clickShape('2').send('MOVED', {
  128. type: MoveType.Forward,
  129. })
  130. expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '1', '4', '2'])
  131. })
  132. it('moves two adjacent siblings forward', () => {
  133. tt.deselectAll()
  134. .clickShape('4')
  135. .clickShape('1', { shiftKey: true })
  136. .send('MOVED', {
  137. type: MoveType.Forward,
  138. })
  139. expect(tt.idsAreSelected(['1', '4'])).toBe(true)
  140. expect(tt.getSortedPageShapeIds()).toStrictEqual(['3', '2', '1', '4'])
  141. })
  142. it('moves two non-adjacent siblings forward', () => {
  143. tt.deselectAll()
  144. .clickShape('3')
  145. .clickShape('1', { shiftKey: true })
  146. .send('MOVED', {
  147. type: MoveType.Forward,
  148. })
  149. expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '3', '4', '1'])
  150. })
  151. it('moves two adjacent siblings forward at top index', () => {
  152. tt.deselectAll()
  153. .clickShape('3')
  154. .clickShape('1', { shiftKey: true })
  155. .send('MOVED', {
  156. type: MoveType.Forward,
  157. })
  158. expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '4', '3', '1'])
  159. })
  160. it('moves a shape to front', () => {
  161. tt.deselectAll().clickShape('2').send('MOVED', {
  162. type: MoveType.ToFront,
  163. })
  164. expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '3', '1', '2'])
  165. })
  166. it('moves two adjacent siblings to front', () => {
  167. tt.deselectAll()
  168. .clickShape('3')
  169. .clickShape('1', { shiftKey: true })
  170. .send('MOVED', {
  171. type: MoveType.ToFront,
  172. })
  173. expect(tt.getSortedPageShapeIds()).toStrictEqual(['4', '2', '3', '1'])
  174. })
  175. it('moves two non-adjacent siblings to front', () => {
  176. tt.deselectAll()
  177. .clickShape('4')
  178. .clickShape('3', { shiftKey: true })
  179. .send('MOVED', {
  180. type: MoveType.ToFront,
  181. })
  182. expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '1', '4', '3'])
  183. })
  184. it('moves siblings already at front to front', () => {
  185. tt.deselectAll()
  186. .clickShape('4')
  187. .clickShape('3', { shiftKey: true })
  188. .send('MOVED', {
  189. type: MoveType.ToFront,
  190. })
  191. expect(tt.getSortedPageShapeIds()).toStrictEqual(['2', '1', '4', '3'])
  192. })
  193. })