sound-editor.test.jsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import React from 'react';
  2. import {mountWithIntl, componentWithIntl} from '../../helpers/intl-helpers.jsx';
  3. import SoundEditor from '../../../src/components/sound-editor/sound-editor';
  4. describe('Sound Editor Component', () => {
  5. let props;
  6. beforeEach(() => {
  7. props = {
  8. canUndo: true,
  9. canRedo: false,
  10. chunkLevels: [1, 2, 3],
  11. name: 'sound name',
  12. playhead: 0.5,
  13. trimStart: 0.2,
  14. trimEnd: 0.8,
  15. onChangeName: jest.fn(),
  16. onDelete: jest.fn(),
  17. onPlay: jest.fn(),
  18. onRedo: jest.fn(),
  19. onReverse: jest.fn(),
  20. onSofter: jest.fn(),
  21. onLouder: jest.fn(),
  22. onRobot: jest.fn(),
  23. onEcho: jest.fn(),
  24. onFaster: jest.fn(),
  25. onSlower: jest.fn(),
  26. onSetTrimEnd: jest.fn(),
  27. onSetTrimStart: jest.fn(),
  28. onStop: jest.fn(),
  29. onUndo: jest.fn()
  30. };
  31. });
  32. test('matches snapshot', () => {
  33. const component = componentWithIntl(<SoundEditor {...props} />);
  34. expect(component.toJSON()).toMatchSnapshot();
  35. });
  36. test('delete button appears when selection is not null', () => {
  37. const wrapper = mountWithIntl(
  38. <SoundEditor
  39. {...props}
  40. trimEnd={0.75}
  41. trimStart={0.25}
  42. />
  43. );
  44. wrapper.find('[children="Delete"]').simulate('click');
  45. expect(props.onDelete).toHaveBeenCalled();
  46. });
  47. test('play button appears when playhead is null', () => {
  48. const wrapper = mountWithIntl(
  49. <SoundEditor
  50. {...props}
  51. playhead={null}
  52. />
  53. );
  54. wrapper.find('button[title="Play"]').simulate('click');
  55. expect(props.onPlay).toHaveBeenCalled();
  56. });
  57. test('stop button appears when playhead is not null', () => {
  58. const wrapper = mountWithIntl(
  59. <SoundEditor
  60. {...props}
  61. playhead={0.5}
  62. />
  63. );
  64. wrapper.find('button[title="Stop"]').simulate('click');
  65. expect(props.onStop).toHaveBeenCalled();
  66. });
  67. test('submitting name calls the callback', () => {
  68. const wrapper = mountWithIntl(
  69. <SoundEditor {...props} />
  70. );
  71. wrapper.find('input')
  72. .simulate('change', {target: {value: 'hello'}})
  73. .simulate('blur');
  74. expect(props.onChangeName).toHaveBeenCalled();
  75. });
  76. test('effect buttons call the correct callbacks', () => {
  77. const wrapper = mountWithIntl(
  78. <SoundEditor {...props} />
  79. );
  80. wrapper.find('[children="Reverse"]').simulate('click');
  81. expect(props.onReverse).toHaveBeenCalled();
  82. wrapper.find('[children="Robot"]').simulate('click');
  83. expect(props.onRobot).toHaveBeenCalled();
  84. wrapper.find('[children="Faster"]').simulate('click');
  85. expect(props.onFaster).toHaveBeenCalled();
  86. wrapper.find('[children="Slower"]').simulate('click');
  87. expect(props.onSlower).toHaveBeenCalled();
  88. wrapper.find('[children="Louder"]').simulate('click');
  89. expect(props.onLouder).toHaveBeenCalled();
  90. wrapper.find('[children="Softer"]').simulate('click');
  91. expect(props.onSofter).toHaveBeenCalled();
  92. });
  93. test('undo and redo buttons can be disabled by canUndo/canRedo', () => {
  94. let wrapper = mountWithIntl(
  95. <SoundEditor
  96. {...props}
  97. canUndo
  98. canRedo={false}
  99. />
  100. );
  101. expect(wrapper.find('button[title="Undo"]').prop('disabled')).toBe(false);
  102. expect(wrapper.find('button[title="Redo"]').prop('disabled')).toBe(true);
  103. wrapper = mountWithIntl(
  104. <SoundEditor
  105. {...props}
  106. canRedo
  107. canUndo={false}
  108. />
  109. );
  110. expect(wrapper.find('button[title="Undo"]').prop('disabled')).toBe(true);
  111. expect(wrapper.find('button[title="Redo"]').prop('disabled')).toBe(false);
  112. });
  113. test.skip('undo/redo buttons call the correct callback', () => {
  114. const wrapper = mountWithIntl(
  115. <SoundEditor
  116. {...props}
  117. canRedo
  118. canUndo
  119. />
  120. );
  121. wrapper.find('button[title="Undo"]').simulate('click');
  122. expect(props.onUndo).toHaveBeenCalled();
  123. wrapper.find('button[title="Redo"]').simulate('click');
  124. expect(props.onRedo).toHaveBeenCalled();
  125. });
  126. });