2015-09-24 22:14:03 +03:00
|
|
|
import expect from 'expect';
|
|
|
|
import jsdom from 'mocha-jsdom';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import TestUtils from 'react-addons-test-utils';
|
2015-09-24 22:51:59 +03:00
|
|
|
import { connectMonitor, devTools } from '../src';
|
2015-09-24 22:14:03 +03:00
|
|
|
import { createStore } from 'redux';
|
|
|
|
|
|
|
|
class MockMonitor extends Component {
|
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-24 22:51:59 +03:00
|
|
|
describe('connectMonitor', () => {
|
2015-09-24 22:14:03 +03:00
|
|
|
jsdom();
|
|
|
|
|
|
|
|
it('should pass devToolsStore to monitor', () => {
|
|
|
|
const store = devTools()(createStore)(() => {});
|
2015-09-24 22:51:59 +03:00
|
|
|
const ConnectedMonitor = connectMonitor(MockMonitor);
|
2015-09-24 22:14:03 +03:00
|
|
|
const tree = TestUtils.renderIntoDocument(
|
2015-09-24 22:51:59 +03:00
|
|
|
<ConnectedMonitor store={store} />
|
2015-09-24 22:14:03 +03:00
|
|
|
);
|
|
|
|
const mockMonitor = TestUtils.findRenderedComponentWithType(tree, MockMonitor);
|
|
|
|
expect(mockMonitor.props.store).toBe(store.devToolsStore);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should pass props to monitor', () => {
|
|
|
|
const store = devTools()(createStore)(() => {});
|
2015-09-24 22:51:59 +03:00
|
|
|
const ConnectedMonitor = connectMonitor(MockMonitor);
|
2015-09-24 22:14:03 +03:00
|
|
|
const tree = TestUtils.renderIntoDocument(
|
2015-09-24 22:51:59 +03:00
|
|
|
<ConnectedMonitor store={store} one={1} two={2}/>
|
2015-09-24 22:14:03 +03:00
|
|
|
);
|
|
|
|
const mockMonitor = TestUtils.findRenderedComponentWithType(tree, MockMonitor);
|
|
|
|
expect(mockMonitor.props.one).toBe(1);
|
|
|
|
expect(mockMonitor.props.two).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should subscribe monitor to store updates', () => {
|
2015-09-24 22:51:59 +03:00
|
|
|
const ConnectedMonitor = connectMonitor(MockMonitor);
|
2015-09-24 22:14:03 +03:00
|
|
|
const store = devTools()(createStore)(
|
|
|
|
(state, action) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case 'INC':
|
|
|
|
return state + 1;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
0
|
|
|
|
);
|
|
|
|
const tree = TestUtils.renderIntoDocument(
|
2015-09-24 22:51:59 +03:00
|
|
|
<ConnectedMonitor store={store} />
|
2015-09-24 22:14:03 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
store.dispatch({type: 'INC'});
|
|
|
|
|
|
|
|
const mockMonitor = TestUtils.findRenderedComponentWithType(tree, MockMonitor);
|
|
|
|
const currentStateIndex = mockMonitor.props.currentStateIndex;
|
|
|
|
const computedStates = mockMonitor.props.computedStates;
|
|
|
|
|
|
|
|
expect(computedStates[currentStateIndex].state).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should warn if devTools() not in middleware', () => {
|
|
|
|
const store = createStore(() => {});
|
2015-09-24 22:51:59 +03:00
|
|
|
const ConnectedMonitor = connectMonitor(MockMonitor);
|
|
|
|
|
|
|
|
// Force to re-evaluate propType checks on every run
|
|
|
|
ConnectedMonitor.displayName = Math.random().toString();
|
2015-09-24 22:14:03 +03:00
|
|
|
|
2015-09-24 22:51:59 +03:00
|
|
|
const spy = expect.spyOn(console, 'error');
|
|
|
|
TestUtils.renderIntoDocument(<ConnectedMonitor store={store} />);
|
|
|
|
spy.restore();
|
2015-09-24 22:14:03 +03:00
|
|
|
|
|
|
|
expect(spy.calls).toContain(
|
2015-09-24 22:51:59 +03:00
|
|
|
/Could not find the DevTools store/,
|
2015-09-24 22:14:03 +03:00
|
|
|
(call, errMsg) => call.arguments[0].match(errMsg)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|