Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

selection.test.ts 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import state from 'state'
  2. import inputs from 'state/inputs'
  3. import { idsAreSelected, point, rectangleId, arrowId } from './test-utils'
  4. import * as json from './__mocks__/document.json'
  5. // Mount the state and load the test file from json
  6. state.reset()
  7. state.send('MOUNTED').send('LOADED_FROM_FILE', { json: JSON.stringify(json) })
  8. describe('selection', () => {
  9. it('selects a shape', () => {
  10. state
  11. .send('CANCELED')
  12. .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  13. .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  14. expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
  15. })
  16. it('selects and deselects a shape', () => {
  17. state
  18. .send('CANCELED')
  19. .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  20. .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  21. expect(idsAreSelected(state.data, [rectangleId])).toBe(true)
  22. state
  23. .send('POINTED_CANVAS', inputs.pointerDown(point(), 'canvas'))
  24. .send('STOPPED_POINTING', inputs.pointerUp(point(), 'canvas'))
  25. expect(idsAreSelected(state.data, [])).toBe(true)
  26. })
  27. it('selects multiple shapes', () => {
  28. expect(idsAreSelected(state.data, [])).toBe(true)
  29. state
  30. .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  31. .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  32. .send(
  33. 'POINTED_SHAPE',
  34. inputs.pointerDown(point({ shiftKey: true }), arrowId)
  35. )
  36. .send(
  37. 'STOPPED_POINTING',
  38. inputs.pointerUp(point({ shiftKey: true }), arrowId)
  39. )
  40. expect(idsAreSelected(state.data, [rectangleId, arrowId])).toBe(true)
  41. })
  42. it('shift-selects to deselect shapes', () => {
  43. state
  44. .send('CANCELLED')
  45. .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  46. .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  47. .send(
  48. 'POINTED_SHAPE',
  49. inputs.pointerDown(point({ shiftKey: true }), arrowId)
  50. )
  51. .send(
  52. 'STOPPED_POINTING',
  53. inputs.pointerUp(point({ shiftKey: true }), arrowId)
  54. )
  55. .send(
  56. 'POINTED_SHAPE',
  57. inputs.pointerDown(point({ shiftKey: true }), rectangleId)
  58. )
  59. .send(
  60. 'STOPPED_POINTING',
  61. inputs.pointerUp(point({ shiftKey: true }), rectangleId)
  62. )
  63. expect(idsAreSelected(state.data, [arrowId])).toBe(true)
  64. })
  65. it('single-selects shape in selection on pointerup', () => {
  66. state
  67. .send('CANCELLED')
  68. .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  69. .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  70. .send(
  71. 'POINTED_SHAPE',
  72. inputs.pointerDown(point({ shiftKey: true }), arrowId)
  73. )
  74. .send(
  75. 'STOPPED_POINTING',
  76. inputs.pointerUp(point({ shiftKey: true }), arrowId)
  77. )
  78. expect(idsAreSelected(state.data, [rectangleId, arrowId])).toBe(true)
  79. state.send('POINTED_SHAPE', inputs.pointerDown(point(), arrowId))
  80. expect(idsAreSelected(state.data, [rectangleId, arrowId])).toBe(true)
  81. state.send('STOPPED_POINTING', inputs.pointerUp(point(), arrowId))
  82. expect(idsAreSelected(state.data, [arrowId])).toBe(true)
  83. })
  84. it('selects shapes if shift key is lifted before pointerup', () => {
  85. state
  86. .send('CANCELLED')
  87. .send('POINTED_SHAPE', inputs.pointerDown(point(), rectangleId))
  88. .send('STOPPED_POINTING', inputs.pointerUp(point(), rectangleId))
  89. .send(
  90. 'POINTED_SHAPE',
  91. inputs.pointerDown(point({ shiftKey: true }), arrowId)
  92. )
  93. .send(
  94. 'STOPPED_POINTING',
  95. inputs.pointerUp(point({ shiftKey: true }), arrowId)
  96. )
  97. .send(
  98. 'POINTED_SHAPE',
  99. inputs.pointerDown(point({ shiftKey: true }), arrowId)
  100. )
  101. .send('STOPPED_POINTING', inputs.pointerUp(point(), arrowId))
  102. expect(idsAreSelected(state.data, [arrowId])).toBe(true)
  103. })
  104. it('does not select on meta-click', () => {
  105. state
  106. .send('CANCELLED')
  107. .send(
  108. 'POINTED_SHAPE',
  109. inputs.pointerDown(point({ ctrlKey: true }), rectangleId)
  110. )
  111. .send(
  112. 'STOPPED_POINTING',
  113. inputs.pointerUp(point({ ctrlKey: true }), rectangleId)
  114. )
  115. expect(idsAreSelected(state.data, [])).toBe(true)
  116. })
  117. })