frame.get('key') === sourceDragData.get('key'))
- if (sourceDragFromPageIndex !== -1) {
- sourceDragFromPageIndex /= this.props.tabsPerTabPage
- }
- }
return
{
- tabPageCount > 1 &&
- Array.from(new Array(tabPageCount)).map((x, i) =>
+ this.props.tabPageCount > 1 &&
+ Array.from(new Array(this.props.tabPageCount)).map((x, i) =>
)
+ index={i} />
+ )
}
}
}
-module.exports = TabPages
+module.exports = ReduxComponent.connect(TabPages)
diff --git a/js/state/frameStateUtil.js b/js/state/frameStateUtil.js
index 0c93c09df3d..3c2c7269bfe 100644
--- a/js/state/frameStateUtil.js
+++ b/js/state/frameStateUtil.js
@@ -525,6 +525,13 @@ const isValidClosedFrame = (frame) => {
return !frame.get('isPrivate')
}
+const getTabPageCount = (state) => {
+ const frames = getNonPinnedFrames(state) || Immutable.List()
+ const tabsPerPage = Number(getSetting(settings.TABS_PER_PAGE))
+
+ return Math.ceil(frames.size / tabsPerPage)
+}
+
module.exports = {
deleteTabInternalIndex,
deleteFrameInternalIndex,
@@ -574,5 +581,6 @@ module.exports = {
getTotalBlocks,
isPinned,
updateTabPageIndex,
- isValidClosedFrame
+ isValidClosedFrame,
+ getTabPageCount
}
diff --git a/test/unit/state/frameStateUtilTest.js b/test/unit/state/frameStateUtilTest.js
index 2205be2cb82..4752268dd8c 100644
--- a/test/unit/state/frameStateUtilTest.js
+++ b/test/unit/state/frameStateUtilTest.js
@@ -13,15 +13,19 @@ const defaultWindowStore = Immutable.fromJS({
})
describe('frameStateUtil', function () {
- let frameStateUtil
+ let frameStateUtil, getSettingsValue
before(function () {
+ getSettingsValue = 20
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
})
mockery.registerMock('electron', fakeElectron)
+ mockery.registerMock('../settings', {
+ getSetting: () => getSettingsValue
+ })
frameStateUtil = require('../../../js/state/frameStateUtil')
this.windowState = Immutable.fromJS(Object.assign({}, defaultWindowStore.toJS()))
})
@@ -319,4 +323,92 @@ describe('frameStateUtil', function () {
assert.equal(result, '99+')
})
})
+
+ describe('getTabPageCount', function () {
+ before(function () {
+ getSettingsValue = 6
+ })
+
+ it('returns two pages when we have more tabs then the tab page limit', function () {
+ let state = Immutable.fromJS({
+ activeFrameKey: 1,
+ frames: [
+ { key: 1 },
+ { key: 2 },
+ { key: 3 },
+ { key: 4 },
+ { key: 5 },
+ { key: 6 },
+ { key: 7 },
+ { key: 8 }
+ ],
+ framesInternal: {
+ index: {
+ 1: 0,
+ 2: 1,
+ 3: 2,
+ 4: 3,
+ 5: 4,
+ 6: 5,
+ 7: 6,
+ 8: 7
+ }
+ }
+ })
+ const result = frameStateUtil.getTabPageCount(state)
+ assert.equal(result, 2)
+ })
+
+ it('returns one pages when we have exactly the same tabs as the tab page limit', function () {
+ let state = Immutable.fromJS({
+ activeFrameKey: 1,
+ frames: [
+ { key: 1 },
+ { key: 2 },
+ { key: 3 },
+ { key: 4 },
+ { key: 5 },
+ { key: 6 }
+ ],
+ framesInternal: {
+ index: {
+ 1: 0,
+ 2: 1,
+ 3: 2,
+ 4: 3,
+ 5: 4,
+ 6: 5
+ }
+ }
+ })
+ const result = frameStateUtil.getTabPageCount(state)
+ assert.equal(result, 1)
+ })
+
+ it('returns one pages when we have less tabs then the tab page limit', function () {
+ let state = Immutable.fromJS({
+ activeFrameKey: 1,
+ frames: [
+ { key: 1 },
+ { key: 2 },
+ { key: 3 },
+ { key: 4 },
+ { key: 5 },
+ { key: 6 }
+ ],
+ framesInternal: {
+ index: {
+ 1: 0,
+ 2: 1,
+ 3: 2,
+ 4: 3,
+ 5: 4,
+ 6: 5
+ }
+ }
+ })
+ const result = frameStateUtil.getTabPageCount(state)
+ assert.equal(result, 1)
+ })
+ })
})