cards.test.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React from 'react';
  2. import {mountWithIntl} from '../../helpers/intl-helpers.jsx';
  3. // Mock this utility because it uses dynamic imports that do not work with jest
  4. jest.mock('../../../src/lib/libraries/decks/translate-image.js', () => {});
  5. import Cards, {ImageStep, VideoStep} from '../../../src/components/cards/cards.jsx';
  6. describe('Cards component', () => {
  7. const defaultProps = () => ({
  8. activeDeckId: 'id1',
  9. content: {
  10. id1: {
  11. name: 'id1 - name',
  12. img: 'id1 - img',
  13. steps: [{video: 'videoUrl'}]
  14. }
  15. },
  16. dragging: false,
  17. expanded: true,
  18. isRtl: false,
  19. locale: 'en',
  20. onActivateDeckFactory: jest.fn(),
  21. onCloseCards: jest.fn(),
  22. onDrag: jest.fn(),
  23. onEndDrag: jest.fn(),
  24. onNextStep: jest.fn(),
  25. onPrevStep: jest.fn(),
  26. onShowAll: jest.fn(),
  27. onShrinkExpandCards: jest.fn(),
  28. onStartDrag: jest.fn(),
  29. showVideos: true,
  30. step: 0,
  31. x: 0,
  32. y: 0
  33. });
  34. test('showVideos=true shows the video step', () => {
  35. const component = mountWithIntl(
  36. <Cards
  37. {...defaultProps()}
  38. showVideos
  39. />
  40. );
  41. expect(component.find(ImageStep).exists()).toEqual(false);
  42. expect(component.find(VideoStep).exists()).toEqual(true);
  43. });
  44. test('showVideos=false shows the title image/name instead of video step', () => {
  45. const component = mountWithIntl(
  46. <Cards
  47. {...defaultProps()}
  48. showVideos={false}
  49. />
  50. );
  51. expect(component.find(VideoStep).exists()).toEqual(false);
  52. const imageStep = component.find(ImageStep);
  53. expect(imageStep.props().image).toEqual('id1 - img');
  54. expect(imageStep.props().title).toEqual('id1 - name');
  55. });
  56. });