componentWillReceiveProps(nextProps) {
if (nextProps.keydown.event) {
const loc = nextProps.location.pathname;
const his = nextProps.history;
const k = nextProps.keydown.event.which;
if (k === 39 && loc=== '/index') {
his.push('/index/loc1');
} else if (k === 39 && loc === '/index/loc1') {
his.push('/index/loc2');
} else if (k === 37 && loc === '/index/loc1') {
his.push('/index');
} else if (k === 37 && loc === '/index/loc2') {
his.push('/index/loc1');
}
}
}
const map = {};
Window.addEventListener = jest.genMockFn().mockImpl((event, cb) => {
map[event] = cb;
});
map.event(...args);
import { mount } from 'enzyme';
...
describe('Editor', function () {
it('dispatch COMMAND_SAVE when command+s key pressesd', function () {
const dispatchSpy = sinon.spy();
dispatchSpy.withArgs(COMMAND_SAVE);
// 1. use `mount` API for Full DOM Rendering
const wrapper = mount(<Editor dispatch={dispatchSpy} />);
// 2. find a DOM element with '.public-DraftEditor-content' classname
const ed = wrapper.find('.public-DraftEditor-content');
// 3. dispatch the 'keyDown' event with `simulate` API
ed.simulate('keyDown', {
keyCode: KeyCode.KEY_S,
metaKey: false, // is IS_OSX=true, this should be true
ctrlKey: true,
altKey: false,
});
assert.equal(dispatchSpy.calledOnce, true);
assert.equal(dispatchSpy.withArgs(COMMAND_SAVE).calledOnce, true);
});
});