From 0d88c7755b65aef965ce924405409b3bc675f609 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum <eric.rosenbaum@gmail.com> Date: Tue, 25 Jun 2019 17:07:50 -0400 Subject: [PATCH] Update tests --- test/__mocks__/audio-effects.js | 2 +- .../__snapshots__/sound-editor.test.jsx.snap | 268 ++++++++++++++---- test/unit/components/sound-editor.test.jsx | 22 +- test/unit/containers/sound-editor.test.jsx | 54 +++- test/unit/util/audio-effects.test.js | 14 +- 5 files changed, 275 insertions(+), 85 deletions(-) diff --git a/test/__mocks__/audio-effects.js b/test/__mocks__/audio-effects.js index b8a4c6994..06c36c7e8 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}); + this._finishProcessing = renderedBuffer => done(renderedBuffer, 0, 1); }); 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 38ddf76c4..32a5c45d8 100644 --- a/test/unit/components/__snapshots__/sound-editor.test.jsx.snap +++ b/test/unit/components/__snapshots__/sound-editor.test.jsx.snap @@ -3,6 +3,7 @@ exports[`Sound Editor Component matches snapshot 1`] = ` <div className={undefined} + onMouseDown={[Function]} > <div className={undefined} @@ -59,7 +60,59 @@ exports[`Sound Editor Component matches snapshot 1`] = ` </div> </div> <div - className="undefined" + 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="" onClick={[Function]} role="button" > @@ -71,9 +124,7 @@ exports[`Sound Editor Component matches snapshot 1`] = ` <div className={undefined} > - <span> - Save - </span> + Delete </div> </div> </div> @@ -107,11 +158,11 @@ exports[`Sound Editor Component matches snapshot 1`] = ` </svg> <div className={undefined} + onMouseDown={[Function]} + onTouchStart={[Function]} > <div className="" - onMouseDown={[Function]} - onTouchStart={[Function]} style={ Object { "alignContent": undefined, @@ -124,7 +175,8 @@ exports[`Sound Editor Component matches snapshot 1`] = ` "flexWrap": undefined, "height": undefined, "justifyContent": undefined, - "width": "20%", + "left": "20%", + "width": "60.00000000000001%", } } > @@ -148,6 +200,8 @@ exports[`Sound Editor Component matches snapshot 1`] = ` /> <div className="" + onMouseDown={[Function]} + onTouchStart={[Function]} style={ Object { "alignContent": undefined, @@ -185,6 +239,26 @@ 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="" @@ -207,62 +281,32 @@ 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> - <div - className={undefined} - > - <div - className="" - style={ - Object { - "transform": "translateX(50%)", - } - } - /> - </div> - <div - className="" - onMouseDown={[Function]} - onTouchStart={[Function]} - style={ - Object { - "alignContent": undefined, - "alignItems": undefined, - "alignSelf": undefined, - "flexBasis": undefined, - "flexDirection": undefined, - "flexGrow": undefined, - "flexShrink": undefined, - "flexWrap": undefined, - "height": undefined, - "justifyContent": undefined, - "left": "80%", - "width": "20%", - } - } - > - <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, - } - } - /> <div className="" + onMouseDown={[Function]} + onTouchStart={[Function]} style={ Object { "alignContent": undefined, @@ -300,6 +344,26 @@ 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="" @@ -322,9 +386,41 @@ 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> + <div + className={undefined} + > + <div + className="" + style={ + Object { + "transform": "translateX(50%)", + } + } + /> + </div> </div> </div> </div> @@ -453,6 +549,24 @@ 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]} @@ -471,6 +585,42 @@ 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 efb153b1f..78aee8704 100644 --- a/test/unit/components/sound-editor.test.jsx +++ b/test/unit/components/sound-editor.test.jsx @@ -6,6 +6,7 @@ describe('Sound Editor Component', () => { let props; beforeEach(() => { props = { + canPaste: false, canUndo: true, canRedo: false, chunkLevels: [1, 2, 3], @@ -13,7 +14,14 @@ describe('Sound Editor Component', () => { playhead: 0.5, trimStart: 0.2, trimEnd: 0.8, - onActivateTrim: jest.fn(), + onContainerClick: jest.fn(), + onCopy: jest.fn(), + onCopyToNew: jest.fn(), + onFadeIn: jest.fn(), + onFadeOut: jest.fn(), + onMute: jest.fn(), + onPaste: jest.fn(), + onDelete: jest.fn(), onChangeName: jest.fn(), onPlay: jest.fn(), onRedo: jest.fn(), @@ -36,7 +44,7 @@ describe('Sound Editor Component', () => { expect(component.toJSON()).toMatchSnapshot(); }); - test('trim button appears when trims are null', () => { + test('delete button is disabled when selection is null', () => { const wrapper = mountWithIntl( <SoundEditor {...props} @@ -44,11 +52,11 @@ describe('Sound Editor Component', () => { trimStart={null} /> ); - wrapper.find('[children="Trim"]').simulate('click'); - expect(props.onActivateTrim).toHaveBeenCalled(); + wrapper.find('[children="Delete"]').simulate('click'); + expect(props.onDelete).not.toHaveBeenCalled(); }); - test('save button appears when trims are not null', () => { + test('delete button calls delete when selection is not null', () => { const wrapper = mountWithIntl( <SoundEditor {...props} @@ -56,8 +64,8 @@ describe('Sound Editor Component', () => { trimStart={0.25} /> ); - wrapper.find('[children="Save"]').simulate('click'); - expect(props.onActivateTrim).toHaveBeenCalled(); + wrapper.find('[children="Delete"]').simulate('click'); + expect(props.onDelete).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 6070b7592..a2f87e5f4 100644 --- a/test/unit/containers/sound-editor.test.jsx +++ b/test/unit/containers/sound-editor.test.jsx @@ -85,7 +85,7 @@ describe('Sound Editor Container', () => { expect(component.props().playhead).toEqual(null); }); - test('it sets the component props for trimming and submits to the vm', () => { + test('it sets the component props for select and delete and submits to the vm', () => { const wrapper = mountWithIntl( <SoundEditor soundIndex={soundIndex} @@ -94,13 +94,15 @@ describe('Sound Editor Container', () => { ); let component = wrapper.find(SoundEditorComponent); - component.props().onActivateTrim(); + 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().onActivateTrim(); + component.props().onDelete(); wrapper.update(); component = wrapper.find(SoundEditorComponent); expect(vm.updateSoundBuffer).toHaveBeenCalled(); @@ -238,8 +240,8 @@ describe('Sound Editor Container', () => { expect(component.prop('canRedo')).toEqual(false); // Submitting new samples should make it possible to undo - component.props().onActivateTrim(); // Activate trimming - component.props().onActivateTrim(); // Submit new samples by calling again + component.props().onSetTrim(0.25, 0.75); + component.props().onDelete(); wrapper.update(); component = wrapper.find(SoundEditorComponent); expect(component.prop('canUndo')).toEqual(true); @@ -264,9 +266,8 @@ describe('Sound Editor Container', () => { wrapper.update(); component = wrapper.find(SoundEditorComponent); expect(component.prop('canRedo')).toEqual(true); - component.props().onActivateTrim(); // Activate trimming - component.props().onActivateTrim(); // Submit new samples by calling again - + component.props().onSetTrim(0.25, 0.75); + component.props().onDelete(); wrapper.update(); component = wrapper.find(SoundEditorComponent); expect(component.prop('canRedo')).toEqual(false); @@ -282,8 +283,8 @@ describe('Sound Editor Container', () => { let component = wrapper.find(SoundEditorComponent); // Set up an undoable state - component.props().onActivateTrim(); // Activate trimming - component.props().onActivateTrim(); // Submit new samples by calling again + component.props().onSetTrim(0.25, 0.75); + component.props().onDelete(); wrapper.update(); component = wrapper.find(SoundEditorComponent); @@ -301,4 +302,37 @@ 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 d1057de53..4c1877d6d 100644 --- a/test/unit/util/audio-effects.test.js +++ b/test/unit/util/audio-effects.test.js @@ -14,19 +14,17 @@ 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'); + const audioEffects = new AudioEffects(audioBuffer, 'faster', 0, 1); 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'); + const audioEffects = new AudioEffects(audioBuffer, 'slower', 0, 1); 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'); + const audioEffects = new AudioEffects(audioBuffer, 'echo', 0, 1); expect(audioEffects.audioContext._.length).toBeGreaterThan(400); }); @@ -43,15 +41,15 @@ describe('Effects', () => { }); test('all effects provide an input and output that are connected', () => { - const robotEffect = new RobotEffect(audioContext, 0.5); + const robotEffect = new RobotEffect(audioContext, 0.5, 0, 0.01); expect(robotEffect.input).toBeInstanceOf(AudioNode); expect(robotEffect.output).toBeInstanceOf(AudioNode); - const echoEffect = new EchoEffect(audioContext, 0.5); + const echoEffect = new EchoEffect(audioContext, 0.5, 0, 0.01); expect(echoEffect.input).toBeInstanceOf(AudioNode); expect(echoEffect.output).toBeInstanceOf(AudioNode); - const volumeEffect = new VolumeEffect(audioContext, 0.5); + const volumeEffect = new VolumeEffect(audioContext, 0.5, 0, 0.01); expect(volumeEffect.input).toBeInstanceOf(AudioNode); expect(volumeEffect.output).toBeInstanceOf(AudioNode); }); -- GitLab