From fdd4b61d5de22a670d86e6c16af861b6e5c174ac Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum <eric.rosenbaum@gmail.com> Date: Mon, 8 Jul 2019 13:57:36 -0400 Subject: [PATCH] Revert and fix tests This reverts commit 42ff50300cff7558fd03cdebb757eca8caf85199. --- test/__mocks__/audio-effects.js | 2 +- .../__snapshots__/sound-editor.test.jsx.snap | 194 +----------------- test/unit/components/sound-editor.test.jsx | 22 +- test/unit/containers/sound-editor.test.jsx | 71 +------ test/unit/util/audio-effects.test.js | 14 +- 5 files changed, 28 insertions(+), 275 deletions(-) diff --git a/test/__mocks__/audio-effects.js b/test/__mocks__/audio-effects.js index 06c36c7e8..b8a4c6994 100644 --- a/test/__mocks__/audio-effects.js +++ b/test/__mocks__/audio-effects.js @@ -14,7 +14,7 @@ export default class MockAudioEffects { this.buffer = buffer; this.name = name; this.process = jest.fn(done => { - this._finishProcessing = renderedBuffer => done(renderedBuffer, 0, 1); + this._finishProcessing = renderedBuffer => done({renderedBuffer}); }); MockAudioEffects.instance = this; } diff --git a/test/unit/components/__snapshots__/sound-editor.test.jsx.snap b/test/unit/components/__snapshots__/sound-editor.test.jsx.snap index 32a5c45d8..f9c476071 100644 --- a/test/unit/components/__snapshots__/sound-editor.test.jsx.snap +++ b/test/unit/components/__snapshots__/sound-editor.test.jsx.snap @@ -3,7 +3,7 @@ exports[`Sound Editor Component matches snapshot 1`] = ` <div className={undefined} - onMouseDown={[Function]} + onMouseDown={undefined} > <div className={undefined} @@ -60,59 +60,7 @@ exports[`Sound Editor Component matches snapshot 1`] = ` </div> </div> <div - className={undefined} - > - <div - className="" - onClick={[Function]} - role="button" - > - <img - className={undefined} - draggable={false} - src="test-file-stub" - /> - <div - className={undefined} - > - Copy - </div> - </div> - <div - className="" - onClick={null} - role="button" - > - <img - className={undefined} - draggable={false} - src="test-file-stub" - /> - <div - className={undefined} - > - Paste - </div> - </div> - <div - className="" - onClick={[Function]} - role="button" - > - <img - className={undefined} - draggable={false} - src="test-file-stub" - /> - <div - className={undefined} - > - Copy to New - </div> - </div> - </div> - <div - className="" + className="undefined" onClick={[Function]} role="button" > @@ -124,7 +72,9 @@ exports[`Sound Editor Component matches snapshot 1`] = ` <div className={undefined} > - Delete + <span> + Save + </span> </div> </div> </div> @@ -239,26 +189,6 @@ exports[`Sound Editor Component matches snapshot 1`] = ` <img src="test-file-stub" /> - <div - className="" - style={ - Object { - "alignContent": undefined, - "alignItems": undefined, - "alignSelf": undefined, - "flexBasis": undefined, - "flexDirection": undefined, - "flexGrow": undefined, - "flexShrink": undefined, - "flexWrap": undefined, - "height": undefined, - "justifyContent": undefined, - "width": undefined, - } - } - > - NaN - </div> </div> <div className="" @@ -281,26 +211,6 @@ exports[`Sound Editor Component matches snapshot 1`] = ` <img src="test-file-stub" /> - <div - className="" - style={ - Object { - "alignContent": undefined, - "alignItems": undefined, - "alignSelf": undefined, - "flexBasis": undefined, - "flexDirection": undefined, - "flexGrow": undefined, - "flexShrink": undefined, - "flexWrap": undefined, - "height": undefined, - "justifyContent": undefined, - "width": undefined, - } - } - > - NaN - </div> </div> </div> <div @@ -344,26 +254,6 @@ exports[`Sound Editor Component matches snapshot 1`] = ` <img src="test-file-stub" /> - <div - className="" - style={ - Object { - "alignContent": undefined, - "alignItems": undefined, - "alignSelf": undefined, - "flexBasis": undefined, - "flexDirection": undefined, - "flexGrow": undefined, - "flexShrink": undefined, - "flexWrap": undefined, - "height": undefined, - "justifyContent": undefined, - "width": undefined, - } - } - > - NaN - </div> </div> <div className="" @@ -386,26 +276,6 @@ exports[`Sound Editor Component matches snapshot 1`] = ` <img src="test-file-stub" /> - <div - className="" - style={ - Object { - "alignContent": undefined, - "alignItems": undefined, - "alignSelf": undefined, - "flexBasis": undefined, - "flexDirection": undefined, - "flexGrow": undefined, - "flexShrink": undefined, - "flexWrap": undefined, - "height": undefined, - "justifyContent": undefined, - "width": undefined, - } - } - > - NaN - </div> </div> </div> </div> @@ -549,24 +419,6 @@ exports[`Sound Editor Component matches snapshot 1`] = ` </span> </div> </div> - <div - className="" - onClick={[Function]} - role="button" - > - <img - className={undefined} - draggable={false} - src="test-file-stub" - /> - <div - className={undefined} - > - <span> - Mute - </span> - </div> - </div> <div className="" onClick={[Function]} @@ -585,42 +437,6 @@ exports[`Sound Editor Component matches snapshot 1`] = ` </span> </div> </div> - <div - className="" - onClick={[Function]} - role="button" - > - <img - className={undefined} - draggable={false} - src="test-file-stub" - /> - <div - className={undefined} - > - <span> - Fade out - </span> - </div> - </div> - <div - className="" - onClick={[Function]} - role="button" - > - <img - className={undefined} - draggable={false} - src="test-file-stub" - /> - <div - className={undefined} - > - <span> - Fade in - </span> - </div> - </div> </div> </div> `; diff --git a/test/unit/components/sound-editor.test.jsx b/test/unit/components/sound-editor.test.jsx index 78aee8704..efb153b1f 100644 --- a/test/unit/components/sound-editor.test.jsx +++ b/test/unit/components/sound-editor.test.jsx @@ -6,7 +6,6 @@ describe('Sound Editor Component', () => { let props; beforeEach(() => { props = { - canPaste: false, canUndo: true, canRedo: false, chunkLevels: [1, 2, 3], @@ -14,14 +13,7 @@ describe('Sound Editor Component', () => { playhead: 0.5, trimStart: 0.2, trimEnd: 0.8, - onContainerClick: jest.fn(), - onCopy: jest.fn(), - onCopyToNew: jest.fn(), - onFadeIn: jest.fn(), - onFadeOut: jest.fn(), - onMute: jest.fn(), - onPaste: jest.fn(), - onDelete: jest.fn(), + onActivateTrim: jest.fn(), onChangeName: jest.fn(), onPlay: jest.fn(), onRedo: jest.fn(), @@ -44,7 +36,7 @@ describe('Sound Editor Component', () => { expect(component.toJSON()).toMatchSnapshot(); }); - test('delete button is disabled when selection is null', () => { + test('trim button appears when trims are null', () => { const wrapper = mountWithIntl( <SoundEditor {...props} @@ -52,11 +44,11 @@ describe('Sound Editor Component', () => { trimStart={null} /> ); - wrapper.find('[children="Delete"]').simulate('click'); - expect(props.onDelete).not.toHaveBeenCalled(); + wrapper.find('[children="Trim"]').simulate('click'); + expect(props.onActivateTrim).toHaveBeenCalled(); }); - test('delete button calls delete when selection is not null', () => { + test('save button appears when trims are not null', () => { const wrapper = mountWithIntl( <SoundEditor {...props} @@ -64,8 +56,8 @@ describe('Sound Editor Component', () => { trimStart={0.25} /> ); - wrapper.find('[children="Delete"]').simulate('click'); - expect(props.onDelete).toHaveBeenCalled(); + wrapper.find('[children="Save"]').simulate('click'); + expect(props.onActivateTrim).toHaveBeenCalled(); }); test('play button appears when playhead is null', () => { diff --git a/test/unit/containers/sound-editor.test.jsx b/test/unit/containers/sound-editor.test.jsx index a2f87e5f4..b0a1a8399 100644 --- a/test/unit/containers/sound-editor.test.jsx +++ b/test/unit/containers/sound-editor.test.jsx @@ -85,31 +85,6 @@ describe('Sound Editor Container', () => { expect(component.props().playhead).toEqual(null); }); - test('it sets the component props for select and delete and submits to the vm', () => { - const wrapper = mountWithIntl( - <SoundEditor - soundIndex={soundIndex} - store={store} - /> - ); - let component = wrapper.find(SoundEditorComponent); - - component.props().onSetTrim(0.25, 0.75); - - wrapper.update(); - - component = wrapper.find(SoundEditorComponent); - expect(component.props().trimStart).not.toEqual(null); - expect(component.props().trimEnd).not.toEqual(null); - - component.props().onDelete(); - wrapper.update(); - component = wrapper.find(SoundEditorComponent); - expect(vm.updateSoundBuffer).toHaveBeenCalled(); - expect(component.props().trimStart).toEqual(null); - expect(component.props().trimEnd).toEqual(null); - }); - test('it submits name changes to the vm', () => { const wrapper = mountWithIntl( <SoundEditor @@ -240,8 +215,8 @@ describe('Sound Editor Container', () => { expect(component.prop('canRedo')).toEqual(false); // Submitting new samples should make it possible to undo - component.props().onSetTrim(0.25, 0.75); - component.props().onDelete(); + component.props().onFaster(); + mockAudioEffects.instance._finishProcessing(soundBuffer); wrapper.update(); component = wrapper.find(SoundEditorComponent); expect(component.prop('canUndo')).toEqual(true); @@ -266,8 +241,9 @@ describe('Sound Editor Container', () => { wrapper.update(); component = wrapper.find(SoundEditorComponent); expect(component.prop('canRedo')).toEqual(true); - component.props().onSetTrim(0.25, 0.75); - component.props().onDelete(); + component.props().onFaster(); + mockAudioEffects.instance._finishProcessing(soundBuffer); + wrapper.update(); component = wrapper.find(SoundEditorComponent); expect(component.prop('canRedo')).toEqual(false); @@ -283,8 +259,8 @@ describe('Sound Editor Container', () => { let component = wrapper.find(SoundEditorComponent); // Set up an undoable state - component.props().onSetTrim(0.25, 0.75); - component.props().onDelete(); + component.props().onFaster(); + mockAudioEffects.instance._finishProcessing(soundBuffer); wrapper.update(); component = wrapper.find(SoundEditorComponent); @@ -302,37 +278,4 @@ describe('Sound Editor Container', () => { expect(mockAudioBufferPlayer.instance.play).toHaveBeenCalled(); expect(vm.updateSoundBuffer).toHaveBeenCalled(); }); - - test('undo and redo updates selection state', () => { - const wrapper = mountWithIntl( - <SoundEditor - soundIndex={soundIndex} - store={store} - /> - ); - let component = wrapper.find(SoundEditorComponent); - - // Set up an undoable state - component.props().onSetTrim(0.25, 0.75); - component.props().onDelete(); - wrapper.update(); - component = wrapper.find(SoundEditorComponent); - - expect(component.props().trimStart).toEqual(null); - expect(component.props().trimEnd).toEqual(null); - - component.props().onUndo(); - wrapper.update(); - component = wrapper.find(SoundEditorComponent); - - expect(component.props().trimStart).toEqual(0.25); - expect(component.props().trimEnd).toEqual(0.75); - - component.props().onRedo(); - wrapper.update(); - component = wrapper.find(SoundEditorComponent); - - expect(component.props().trimStart).toEqual(null); - expect(component.props().trimEnd).toEqual(null); - }); }); diff --git a/test/unit/util/audio-effects.test.js b/test/unit/util/audio-effects.test.js index 4c1877d6d..d1057de53 100644 --- a/test/unit/util/audio-effects.test.js +++ b/test/unit/util/audio-effects.test.js @@ -14,17 +14,19 @@ describe('Audio Effects manager', () => { const audioBuffer = audioContext.createBuffer(1, 400, 44100); test('changes buffer length and playback rate for faster effect', () => { - const audioEffects = new AudioEffects(audioBuffer, 'faster', 0, 1); + const audioEffects = new AudioEffects(audioBuffer, 'faster'); expect(audioEffects.audioContext._.length).toBeLessThan(400); + expect(audioEffects.source.playbackRate.value).toBeGreaterThan(1); }); test('changes buffer length and playback rate for slower effect', () => { - const audioEffects = new AudioEffects(audioBuffer, 'slower', 0, 1); + const audioEffects = new AudioEffects(audioBuffer, 'slower'); expect(audioEffects.audioContext._.length).toBeGreaterThan(400); + expect(audioEffects.source.playbackRate.value).toBeLessThan(1); }); test('changes buffer length for echo effect', () => { - const audioEffects = new AudioEffects(audioBuffer, 'echo', 0, 1); + const audioEffects = new AudioEffects(audioBuffer, 'echo'); expect(audioEffects.audioContext._.length).toBeGreaterThan(400); }); @@ -41,15 +43,15 @@ describe('Effects', () => { }); test('all effects provide an input and output that are connected', () => { - const robotEffect = new RobotEffect(audioContext, 0.5, 0, 0.01); + const robotEffect = new RobotEffect(audioContext, 0.5); expect(robotEffect.input).toBeInstanceOf(AudioNode); expect(robotEffect.output).toBeInstanceOf(AudioNode); - const echoEffect = new EchoEffect(audioContext, 0.5, 0, 0.01); + const echoEffect = new EchoEffect(audioContext, 0.5); expect(echoEffect.input).toBeInstanceOf(AudioNode); expect(echoEffect.output).toBeInstanceOf(AudioNode); - const volumeEffect = new VolumeEffect(audioContext, 0.5, 0, 0.01); + const volumeEffect = new VolumeEffect(audioContext, 0.5); expect(volumeEffect.input).toBeInstanceOf(AudioNode); expect(volumeEffect.output).toBeInstanceOf(AudioNode); }); -- GitLab