Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #15: implemented integration test to reproduce issue, no luck
Change-Id: Ia96ded6f96505f05ae6fd5076954262715eb2f68
- Loading branch information
Patrick Hund
committed
Jan 24, 2019
1 parent
a95c11a
commit ccdfcc2
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* eslint-disable react/prop-types */ | ||
import React, { Component } from 'react'; | ||
import { Provider, connect } from 'react-redux'; | ||
import { createStore, applyMiddleware } from 'redux'; | ||
import { combineNestedReducers, createFakeActionAndReducer } from './utils'; | ||
import BrickProvider from './BrickProvider'; | ||
import withBrick from './withBrick'; | ||
import createSagaMiddleware from 'redux-saga'; | ||
import { mount } from 'enzyme'; | ||
|
||
const [refreshableReducer, refreshableAction, refreshableSpy] = createFakeActionAndReducer('REFRESHABLE'); | ||
const [boardInfoReducer, boardInfoAction, boardInfoSpy] = createFakeActionAndReducer('BOARD_INFO'); | ||
|
||
function App({ children }) { | ||
return <div id="app">{children}</div>; | ||
} | ||
|
||
class Refreshable extends Component { | ||
componentDidMount() { | ||
this.props.dispatch(refreshableAction); | ||
} | ||
render() { | ||
return <div id="refreshable" />; | ||
} | ||
} | ||
|
||
const RefreshableContainer = connect()(Refreshable); | ||
|
||
const boardInfoBrick = { | ||
reducer: boardInfoReducer, | ||
selectors: {}, | ||
*saga() {} | ||
}; | ||
|
||
function BoardInfo() { | ||
return <div id="board-info" />; | ||
} | ||
|
||
function Sidebar({ children }) { | ||
return <div id="sidebar">{children}</div>; | ||
} | ||
|
||
const SidebarContainer = withBrick('bricks.sidebar.boardInfo', boardInfoBrick)(Sidebar); | ||
|
||
test('actions dispatched to original and brick reducer are processed correctly', () => { | ||
const originalReducer = combineNestedReducers({ | ||
modules: { | ||
refreshable: refreshableReducer | ||
} | ||
}); | ||
const sagaMiddleware = createSagaMiddleware(); | ||
const store = createStore(originalReducer, applyMiddleware(sagaMiddleware)); | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<BrickProvider store={store} sagaMiddleware={sagaMiddleware} reducer={originalReducer}> | ||
<App> | ||
<RefreshableContainer /> | ||
<SidebarContainer> | ||
<BoardInfo /> | ||
</SidebarContainer> | ||
</App> | ||
</BrickProvider> | ||
</Provider> | ||
); | ||
expect(store.getState()).toEqual({ | ||
modules: { | ||
refreshable: { value: 'refreshable' } | ||
}, | ||
bricks: { | ||
sidebar: { | ||
boardInfo: {} | ||
} | ||
} | ||
}); | ||
store.dispatch(boardInfoAction); | ||
store.dispatch(refreshableAction); | ||
expect(boardInfoSpy).toHaveBeenCalledTimes(1); | ||
expect(refreshableSpy).toHaveBeenCalledTimes(2); | ||
expect(store.getState()).toEqual({ | ||
modules: { | ||
refreshable: { | ||
value: 'refreshable' | ||
} | ||
}, | ||
bricks: { | ||
sidebar: { | ||
boardInfo: { | ||
value: 'board_info' | ||
} | ||
} | ||
} | ||
}); | ||
}); |