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

bounds.test.ts 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { getShapeUtils } from 'state/shape-utils'
  2. import { getCommonBounds } from 'utils'
  3. import TestState, { arrowId, rectangleId } from './test-utils'
  4. describe('selection', () => {
  5. const tt = new TestState()
  6. it('measures correct bounds for selected item', () => {
  7. // Note: Each item should test its own bounds in its ./shapes/[shape].tsx file
  8. const shape = tt.getShape(rectangleId)
  9. tt.deselectAll().clickShape(rectangleId)
  10. expect(tt.state.values.selectedBounds).toStrictEqual(
  11. getShapeUtils(shape).getBounds(shape)
  12. )
  13. })
  14. it('measures correct bounds for rotated selected item', () => {
  15. const shape = tt.getShape(rectangleId)
  16. getShapeUtils(shape).rotateBy(shape, Math.PI * 2 * Math.random())
  17. tt.deselectAll().clickShape(rectangleId)
  18. expect(tt.state.values.selectedBounds).toStrictEqual(
  19. getShapeUtils(shape).getBounds(shape)
  20. )
  21. getShapeUtils(shape).rotateBy(shape, -Math.PI * 2 * Math.random())
  22. expect(tt.state.values.selectedBounds).toStrictEqual(
  23. getShapeUtils(shape).getBounds(shape)
  24. )
  25. })
  26. it('measures correct bounds for selected items', () => {
  27. const shape1 = tt.getShape(rectangleId)
  28. const shape2 = tt.getShape(arrowId)
  29. tt.deselectAll()
  30. .clickShape(shape1.id)
  31. .clickShape(shape2.id, { shiftKey: true })
  32. expect(tt.state.values.selectedBounds).toStrictEqual(
  33. getCommonBounds(
  34. getShapeUtils(shape1).getRotatedBounds(shape1),
  35. getShapeUtils(shape2).getRotatedBounds(shape2)
  36. )
  37. )
  38. })
  39. it('measures correct bounds for rotated selected items', () => {
  40. const shape1 = tt.getShape(rectangleId)
  41. const shape2 = tt.getShape(arrowId)
  42. getShapeUtils(shape1).rotateBy(shape1, Math.PI * 2 * Math.random())
  43. getShapeUtils(shape2).rotateBy(shape2, Math.PI * 2 * Math.random())
  44. tt.deselectAll()
  45. .clickShape(shape1.id)
  46. .clickShape(shape2.id, { shiftKey: true })
  47. expect(tt.state.values.selectedBounds).toStrictEqual(
  48. getCommonBounds(
  49. getShapeUtils(shape1).getRotatedBounds(shape1),
  50. getShapeUtils(shape2).getRotatedBounds(shape2)
  51. )
  52. )
  53. })
  54. })