Skip to content

Commit

Permalink
Issue #15: implemented integration test to reproduce issue, no luck
Browse files Browse the repository at this point in the history
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.
93 changes: 93 additions & 0 deletions packages/bricks/src/integration.test.js
@@ -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'
}
}
}
});
});

0 comments on commit ccdfcc2

Please sign in to comment.