Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

selection.test.ts 4.3KB

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