diff --git a/app/renderer/reducers/frameReducer.js b/app/renderer/reducers/frameReducer.js index 44d9e12f443..7fe20926c75 100644 --- a/app/renderer/reducers/frameReducer.js +++ b/app/renderer/reducers/frameReducer.js @@ -186,21 +186,33 @@ const frameReducer = (state, action, immutableAction) => { }) break case windowConstants.WINDOW_CLOSE_OTHER_FRAMES: - const currentIndex = frameStateUtil.getIndexByTabId(state, action.tabId) - if (currentIndex === -1) { - return - } + { + const currentIndex = frameStateUtil.getIndexByTabId(state, action.tabId) + if (currentIndex === -1) { + break + } - state.get('frames').forEach((frame, i) => { - if (!frame.get('pinnedLocation') && - ((i < currentIndex && action.isCloseLeft) || (i > currentIndex && action.isCloseRight))) { - if (frame) { - appActions.tabCloseRequested(frame.get('tabId')) + let tabs = [] + + state.get('frames').forEach((frame, i) => { + if (!frame.get('pinnedLocation') && + ((i < currentIndex && action.isCloseLeft) || (i > currentIndex && action.isCloseRight))) { + if (frame) { + tabs.push(frame.get('tabId')) + appActions.tabCloseRequested(frame.get('tabId')) + } } - } - }) + }) + // TODO(nejc) this can be simplified when states are merged + const newFrames = state.get('frames').filter(frame => !tabs.includes(frame.get('tabId'))) + let newState = state.set('frames', newFrames) + newState = frameStateUtil.updateTabPageIndex(newState, action.tabId) + const index = newState.getIn(['ui', 'tabs', 'tabPageIndex'], 0) + state = state.setIn(['ui', 'tabs', 'tabPageIndex'], index) + } break + case windowConstants.WINDOW_CLOSE_FRAME: state = closeFrame(state, action) break diff --git a/test/lib/brave.js b/test/lib/brave.js index f8634e661f8..d8724579983 100644 --- a/test/lib/brave.js +++ b/test/lib/brave.js @@ -202,7 +202,7 @@ var exports = { const initialized = [] this.app.client.addCommand('ipcSend', function (message, ...param) { - logVerbose('ipcSend(' + message + ')') + logVerbose('ipcSend(' + message + ', "' + param + '")') return this.execute(function (message, ...param) { return devTools('electron').remote.getCurrentWindow().webContents.send(message, ...param) }, message, ...param).then((response) => response.value) diff --git a/test/tab-components/tabPagesTest.js b/test/tab-components/tabPagesTest.js index b419b19c9dd..95f3030e335 100644 --- a/test/tab-components/tabPagesTest.js +++ b/test/tab-components/tabPagesTest.js @@ -3,6 +3,7 @@ const Brave = require('../lib/brave') const appConfig = require('../../js/constants/appConfig') const settings = require('../../js/constants/settings') +const messages = require('../../js/constants/messages') const { urlInput, newFrameButton, @@ -68,6 +69,25 @@ describe('tab pages', function () { .waitForElementCount(tabsTabs, numTabsPerPage) }) + it('closing tabs with close-to-left option', function * () { + let tabId = 0 + yield this.app.client + .click(newFrameButton) + .waitForElementCount(tabPage, 2) + .waitUntil(function () { + return this.getAppState().then((state) => { + const length = state.value.tabs.length + tabId = state.value.tabs[length - 1].id + return true + }) + }) + .waitUntil(function () { + return this.ipcSend(messages.SHORTCUT_CLOSE_OTHER_FRAMES, tabId, false, true) + }) + .waitForElementCount(tabPage, 0) + .waitForElementCount(tabsTabs, 1) + }) + describe('allows changing to tab pages', function () { beforeEach(function * () { // Make sure there are 2 tab pages