Skip to content
Snippets Groups Projects
Commit 66a83422 authored by Chris Beer's avatar Chris Beer
Browse files

Use removeWindow instead of a separate closeWindow action

parent cd886107
No related branches found
No related tags found
No related merge requests found
......@@ -55,8 +55,24 @@ describe('window actions', () => {
const expectedAction = {
type: ActionTypes.REMOVE_WINDOW,
windowId: id,
companionWindowIds: ['a', 'b', 'c'],
};
expect(actions.removeWindow(id)).toEqual(expectedAction);
const mockState = {
windows: {
abc123: { companionWindowIds: ['a', 'b', 'c'] },
},
companionWindows: {},
};
const mockDispatch = jest.fn(() => ({}));
const mockGetState = jest.fn(() => mockState);
const thunk = actions.removeWindow(id);
thunk(mockDispatch, mockGetState);
const action = mockDispatch.mock.calls[0][0];
expect(action).toEqual(expectedAction);
});
});
......
......@@ -22,7 +22,7 @@ function createWrapper(props) {
maximizeWindow={() => {}}
maximized={false}
minimizeWindow={() => {}}
closeWindow={() => {}}
removeWindow={() => {}}
toggleWindowSideBar={() => {}}
{...props}
/>,
......@@ -63,9 +63,9 @@ describe('WindowTopBar', () => {
});
it('passes correct props to <Button/>', () => {
const closeWindow = jest.fn();
const wrapper = createWrapper({ closeWindow });
expect(wrapper.find(IconButton).last().props().onClick).toBe(closeWindow);
const removeWindow = jest.fn();
const wrapper = createWrapper({ removeWindow });
expect(wrapper.find(IconButton).last().props().onClick).toBe(removeWindow);
});
it('passes correct props to <Button/>', () => {
......
......@@ -76,4 +76,21 @@ describe('companionWindowsReducer', () => {
expect(companionWindowsReducer(beforeState, action)).toEqual(expectedState);
});
});
describe('REMOVE_WINDOW', () => {
it('should remove a companion window', () => {
const action = {
type: ActionTypes.REMOVE_WINDOW,
id: 'abc123',
companionWindowIds: ['a', 'b'],
};
const beforeState = {
a: {},
b: {},
c: {},
};
const expectedState = { c: {} };
expect(companionWindowsReducer(beforeState, action)).toEqual(expectedState);
});
});
});
......@@ -24,7 +24,7 @@ export class WindowTopBar extends Component {
*/
render() {
const {
closeWindow, windowId, classes, toggleWindowSideBar, t, manifestTitle,
removeWindow, windowId, classes, toggleWindowSideBar, t, manifestTitle,
maximizeWindow, maximized, minimizeWindow,
} = this.props;
return (
......@@ -56,7 +56,7 @@ export class WindowTopBar extends Component {
color="inherit"
className={ns('window-close')}
aria-label={t('closeWindow')}
onClick={closeWindow}
onClick={removeWindow}
>
<CloseIcon />
</IconButton>
......@@ -71,7 +71,7 @@ WindowTopBar.propTypes = {
maximizeWindow: PropTypes.func,
maximized: PropTypes.bool,
minimizeWindow: PropTypes.func,
closeWindow: PropTypes.func.isRequired,
removeWindow: PropTypes.func.isRequired,
windowId: PropTypes.string.isRequired,
classes: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
toggleWindowSideBar: PropTypes.func.isRequired,
......
......@@ -19,7 +19,7 @@ const mapStateToProps = (state, { windowId }) => ({
* @private
*/
const mapDispatchToProps = (dispatch, { windowId }) => ({
closeWindow: () => dispatch(actions.closeWindow(windowId)),
removeWindow: () => dispatch(actions.removeWindow(windowId)),
maximizeWindow: () => dispatch(actions.maximizeWindow(windowId)),
minimizeWindow: () => dispatch(actions.minimizeWindow(windowId)),
toggleWindowSideBar: () => dispatch(actions.toggleWindowSideBar(windowId)),
......
......@@ -75,7 +75,12 @@ export function setCompanionAreaOpen(id, companionAreaOpen) {
* @memberof ActionCreators
*/
export function removeWindow(windowId) {
return { type: ActionTypes.REMOVE_WINDOW, windowId };
return (dispatch, getState) => {
const { windows } = getState();
const { companionWindowIds } = windows[windowId];
dispatch({ type: ActionTypes.REMOVE_WINDOW, windowId, companionWindowIds });
};
}
/**
......@@ -99,17 +104,6 @@ export function setWindowSideBarPanel(windowId, panelType) {
return { type: ActionTypes.SET_WINDOW_SIDE_BAR_PANEL, windowId, panelType };
}
/**
* Clean up state and remove window
*/
export function closeWindow(windowId) {
return (dispatch, getState) => {
const { companionWindowIds } = getState().windows[windowId];
companionWindowIds.map(id => dispatch(removeCompanionWindow(id)));
dispatch(removeWindow(windowId));
};
}
/**
* setWindowThumbnailPosition - action creator
*
......
......@@ -15,6 +15,9 @@ export function companionWindowsReducer(state = {}, action) {
return newState;
}, state);
case ActionTypes.REMOVE_WINDOW:
return action.companionWindowIds.reduce((newState, id) => removeIn(newState, [id]), state);
case ActionTypes.UPDATE_COMPANION_WINDOW:
return updateIn(state, [action.id], orig => merge(orig, action.payload));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment