Bind vm project_start event to passed in onGreenFlag prop
This commit is contained in:
1 parent
20645047f8
commit
c0e105dd94
2 files changed
+57
-1
No files matched your search
@@ -43,6 +43,7 @@ const vmListenerHOC = function (WrappedComponent) {
|
||||
this.props.vm.on('PROJECT_RUN_STOP', this.props.onProjectRunStop);
|
||||
this.props.vm.on('PROJECT_CHANGED', this.handleProjectChanged);
|
||||
this.props.vm.on('RUNTIME_STARTED', this.props.onRuntimeStarted);
|
||||
this.props.vm.on('PROJECT_START', this.props.onGreenFlag);
|
||||
this.props.vm.on('PERIPHERAL_DISCONNECT_ERROR', this.props.onShowExtensionAlert);
|
||||
this.props.vm.on('MIC_LISTENING', this.props.onMicListeningUpdate);
|
||||
|
||||
@@ -116,6 +117,7 @@ const vmListenerHOC = function (WrappedComponent) {
|
||||
attachKeyboardEvents,
|
||||
shouldEmitTargetsUpdate,
|
||||
onBlockDragUpdate,
|
||||
onGreenFlag,
|
||||
onKeyDown,
|
||||
onKeyUp,
|
||||
onMicListeningUpdate,
|
||||
@@ -136,6 +138,7 @@ const vmListenerHOC = function (WrappedComponent) {
|
||||
VMListener.propTypes = {
|
||||
attachKeyboardEvents: PropTypes.bool,
|
||||
onBlockDragUpdate: PropTypes.func.isRequired,
|
||||
onGreenFlag: PropTypes.func,
|
||||
onKeyDown: PropTypes.func,
|
||||
onKeyUp: PropTypes.func,
|
||||
onMicListeningUpdate: PropTypes.func.isRequired,
|
||||
@@ -152,7 +155,8 @@ const vmListenerHOC = function (WrappedComponent) {
|
||||
vm: PropTypes.instanceOf(VM).isRequired
|
||||
};
|
||||
VMListener.defaultProps = {
|
||||
attachKeyboardEvents: true
|
||||
attachKeyboardEvents: true,
|
||||
onGreenFlag: () => ({})
|
||||
};
|
||||
const mapStateToProps = state => ({
|
||||
// Do not emit target updates in fullscreen or player only mode
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import React from 'react';
|
||||
import configureStore from 'redux-mock-store';
|
||||
import {mount} from 'enzyme';
|
||||
import VM from 'scratch-vm';
|
||||
|
||||
import vmListenerHOC from '../../../src/lib/vm-listener-hoc.jsx';
|
||||
|
||||
describe('VMListenerHOC', () => {
|
||||
const mockStore = configureStore();
|
||||
let store;
|
||||
let vm;
|
||||
|
||||
beforeEach(() => {
|
||||
vm = new VM();
|
||||
store = mockStore({
|
||||
scratchGui: {
|
||||
mode: {},
|
||||
vm: vm
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('vm green flag event is bound to the passed in prop callback', () => {
|
||||
const Component = () => (<div />);
|
||||
const WrappedComponent = vmListenerHOC(Component);
|
||||
const onGreenFlag = jest.fn();
|
||||
mount(
|
||||
<WrappedComponent
|
||||
store={store}
|
||||
vm={vm}
|
||||
onGreenFlag={onGreenFlag}
|
||||
/>
|
||||
);
|
||||
expect(onGreenFlag).not.toHaveBeenCalled();
|
||||
vm.emit('PROJECT_START');
|
||||
expect(onGreenFlag).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('onGreenFlag is not passed to the children', () => {
|
||||
const Component = () => (<div />);
|
||||
const WrappedComponent = vmListenerHOC(Component);
|
||||
const wrapper = mount(
|
||||
<WrappedComponent
|
||||
store={store}
|
||||
vm={vm}
|
||||
onGreenFlag={jest.fn()}
|
||||
/>
|
||||
);
|
||||
const child = wrapper.find(Component);
|
||||
expect(child.props().onGreenFlag).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user