Skip to content
Snippets Groups Projects
Unverified Commit 4c87291d authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub
Browse files

Merge pull request #934 from paulkaplan/play-on-undo

Play the restored sound after undo/redo in the sound editor
parents dbe831a9 084deee3
No related branches found
No related tags found
No related merge requests found
...@@ -124,6 +124,7 @@ class SoundEditor extends React.Component { ...@@ -124,6 +124,7 @@ class SoundEditor extends React.Component {
const samples = this.undoStack.pop(); const samples = this.undoStack.pop();
if (samples) { if (samples) {
this.submitNewSamples(samples, this.props.sampleRate, true); this.submitNewSamples(samples, this.props.sampleRate, true);
this.handlePlay();
} }
} }
handleRedo () { handleRedo () {
...@@ -131,6 +132,7 @@ class SoundEditor extends React.Component { ...@@ -131,6 +132,7 @@ class SoundEditor extends React.Component {
if (samples) { if (samples) {
this.undoStack.push(this.props.samples.slice(0)); this.undoStack.push(this.props.samples.slice(0));
this.submitNewSamples(samples, this.props.sampleRate, true); this.submitNewSamples(samples, this.props.sampleRate, true);
this.handlePlay();
} }
} }
render () { render () {
......
...@@ -224,7 +224,7 @@ describe('Sound Editor Container', () => { ...@@ -224,7 +224,7 @@ describe('Sound Editor Container', () => {
expect(mockAudioEffects.instance.process).toHaveBeenCalled(); expect(mockAudioEffects.instance.process).toHaveBeenCalled();
}); });
test('undo/redo functionality', () => { test('undo/redo stack state', () => {
const wrapper = mountWithIntl( const wrapper = mountWithIntl(
<SoundEditor <SoundEditor
soundIndex={soundIndex} soundIndex={soundIndex}
...@@ -270,4 +270,34 @@ describe('Sound Editor Container', () => { ...@@ -270,4 +270,34 @@ describe('Sound Editor Container', () => {
component = wrapper.find(SoundEditorComponent); component = wrapper.find(SoundEditorComponent);
expect(component.prop('canRedo')).toEqual(false); expect(component.prop('canRedo')).toEqual(false);
}); });
test('undo and redo submit new samples and play the sound', () => {
const wrapper = mountWithIntl(
<SoundEditor
soundIndex={soundIndex}
store={store}
/>
);
let component = wrapper.find(SoundEditorComponent);
// Set up an undoable state
component.props().onActivateTrim(); // Activate trimming
component.props().onActivateTrim(); // Submit new samples by calling again
wrapper.update();
component = wrapper.find(SoundEditorComponent);
// Undo should update the sound buffer and play the new samples
component.props().onUndo();
expect(mockAudioBufferPlayer.instance.play).toHaveBeenCalled();
expect(vm.updateSoundBuffer).toHaveBeenCalled();
// Clear the mocks call history to assert again for redo.
vm.updateSoundBuffer.mockClear();
mockAudioBufferPlayer.instance.play.mockClear();
// Undo should update the sound buffer and play the new samples
component.props().onRedo();
expect(mockAudioBufferPlayer.instance.play).toHaveBeenCalled();
expect(vm.updateSoundBuffer).toHaveBeenCalled();
});
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment