compare-props-with-shallow-array-compare.tests.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { expect } from 'chai'
  2. import comparePropsWithShallowArrayCompare from '../../../../../frontend/js/features/source-editor/components/review-panel/utils/compare-props-with-shallow-array-compare'
  3. describe('comparePropsWithShallowArrayCompare', function () {
  4. it('is true with all equal non-array props', function () {
  5. type NoArrayProps = { prop1: string; prop2: number }
  6. const props1: NoArrayProps = { prop1: 'wombat', prop2: 1 }
  7. const props2: NoArrayProps = { prop1: 'wombat', prop2: 1 }
  8. expect(comparePropsWithShallowArrayCompare()(props1, props2)).to.be.true
  9. })
  10. it('is false with non-equal non-array props', function () {
  11. type NoArrayProps = { prop1: string; prop2: number }
  12. const props1: NoArrayProps = { prop1: 'wombat', prop2: 1 }
  13. const props2: NoArrayProps = { prop1: 'squirrel', prop2: 1 }
  14. expect(comparePropsWithShallowArrayCompare()(props1, props2)).to.be.false
  15. })
  16. it('is false with similar but not specified array prop', function () {
  17. type ArrayProps = { prop1: string; prop2: number[] }
  18. const props1: ArrayProps = { prop1: 'wombat', prop2: [1] }
  19. const props2: ArrayProps = { prop1: 'wombat', prop2: [1] }
  20. expect(comparePropsWithShallowArrayCompare()(props1, props2)).to.be.false
  21. })
  22. it('is true with similar and specified array prop', function () {
  23. type ArrayProps = { prop1: string; prop2: number[] }
  24. const props1: ArrayProps = { prop1: 'wombat', prop2: [1] }
  25. const props2: ArrayProps = { prop1: 'wombat', prop2: [1] }
  26. expect(
  27. comparePropsWithShallowArrayCompare<ArrayProps>('prop2')(props1, props2)
  28. ).to.be.true
  29. })
  30. it('is false with non-similar and specified array prop', function () {
  31. type ArrayProps = { prop1: string; prop2: number[] }
  32. const props1: ArrayProps = { prop1: 'wombat', prop2: [1] }
  33. const props2: ArrayProps = { prop1: 'wombat', prop2: [2] }
  34. expect(
  35. comparePropsWithShallowArrayCompare<ArrayProps>('prop2')(props1, props2)
  36. ).to.be.false
  37. })
  38. it('is false with multiple similar array props with not all specified', function () {
  39. type MultipleArrayProps = { prop1: number[]; prop2: number[] }
  40. const props1: MultipleArrayProps = { prop1: [1], prop2: [2] }
  41. const props2: MultipleArrayProps = { prop1: [1], prop2: [2] }
  42. expect(
  43. comparePropsWithShallowArrayCompare<MultipleArrayProps>('prop1')(
  44. props1,
  45. props2
  46. )
  47. ).to.be.false
  48. })
  49. it('is true with multiple similar array props with all specified', function () {
  50. type MultipleArrayProps = { prop1: number[]; prop2: number[] }
  51. const props1: MultipleArrayProps = { prop1: [1], prop2: [2] }
  52. const props2: MultipleArrayProps = { prop1: [1], prop2: [2] }
  53. expect(
  54. comparePropsWithShallowArrayCompare<MultipleArrayProps>('prop1', 'prop2')(
  55. props1,
  56. props2
  57. )
  58. ).to.be.true
  59. })
  60. })