|
1 | 1 | const expect = require('expect');
|
2 | 2 | const { pushPath, replacePath, UPDATE_PATH, routeReducer, syncReduxAndRouter } = require('../src/index');
|
3 |
| -const { createStore, combineReducers } = require('redux'); |
| 3 | +const { createStore, combineReducers, compose } = require('redux'); |
| 4 | +const { devTools } = require('redux-devtools'); |
| 5 | +const { ActionCreators } = require('redux-devtools/lib/devTools'); |
4 | 6 |
|
5 | 7 | function createSyncedHistoryAndStore(createHistory) {
|
6 | 8 | const store = createStore(combineReducers({
|
@@ -130,6 +132,77 @@ module.exports = function createTests(createHistory, name, reset = defaultReset)
|
130 | 132 | });
|
131 | 133 | });
|
132 | 134 |
|
| 135 | + describe('devtools', () => { |
| 136 | + let history, store, devToolsStore, unsubscribe; |
| 137 | + |
| 138 | + beforeEach(() => { |
| 139 | + history = createHistory(); |
| 140 | + const finalCreateStore = compose(devTools())(createStore); |
| 141 | + store = finalCreateStore(combineReducers({ |
| 142 | + routing: routeReducer |
| 143 | + })); |
| 144 | + devToolsStore = store.devToolsStore; |
| 145 | + |
| 146 | + // Set initial URL before syncing |
| 147 | + history.pushState(null, '/foo'); |
| 148 | + |
| 149 | + unsubscribe = syncReduxAndRouter(history, store); |
| 150 | + }); |
| 151 | + |
| 152 | + afterEach(() => { |
| 153 | + unsubscribe(); |
| 154 | + }); |
| 155 | + |
| 156 | + it('resets to the initial url', () => { |
| 157 | + let lastPath; |
| 158 | + const historyUnsubscribe = history.listen(location => { |
| 159 | + lastPath = location.pathname; |
| 160 | + }); |
| 161 | + |
| 162 | + history.pushState(null, '/bar'); |
| 163 | + store.dispatch(pushPath('/baz')); |
| 164 | + |
| 165 | + devToolsStore.dispatch(ActionCreators.reset()); |
| 166 | + |
| 167 | + expect(store.getState().routing.path).toEqual('/foo'); |
| 168 | + expect(lastPath).toEqual('/foo'); |
| 169 | + }); |
| 170 | + |
| 171 | + it('handles toggle after store change', () => { |
| 172 | + let lastPath; |
| 173 | + const historyUnsubscribe = history.listen(location => { |
| 174 | + lastPath = location.pathname; |
| 175 | + }); |
| 176 | + |
| 177 | + // action 2 |
| 178 | + history.pushState(null, '/foo2'); |
| 179 | + // action 3 |
| 180 | + history.pushState(null, '/foo3'); |
| 181 | + |
| 182 | + devToolsStore.dispatch(ActionCreators.toggleAction(3)); |
| 183 | + expect(lastPath).toEqual('/foo2'); |
| 184 | + |
| 185 | + historyUnsubscribe(); |
| 186 | + }); |
| 187 | + |
| 188 | + it('handles toggle after store change', () => { |
| 189 | + let lastPath; |
| 190 | + const historyUnsubscribe = history.listen(location => { |
| 191 | + lastPath = location.pathname; |
| 192 | + }); |
| 193 | + |
| 194 | + // action 2 |
| 195 | + store.dispatch(pushPath('/foo2')); |
| 196 | + // action 3 |
| 197 | + store.dispatch(pushPath('/foo3')); |
| 198 | + |
| 199 | + devToolsStore.dispatch(ActionCreators.toggleAction(3)); |
| 200 | + expect(lastPath).toEqual('/foo2'); |
| 201 | + |
| 202 | + historyUnsubscribe(); |
| 203 | + }); |
| 204 | + }); |
| 205 | + |
133 | 206 | describe('syncReduxAndRouter', () => {
|
134 | 207 | let history, store, unsubscribe;
|
135 | 208 |
|
|
0 commit comments