Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
ensure first frame key is always valid
Browse files Browse the repository at this point in the history
Auditors: @NejcZdovc
fix #11208
Test Plan:
npm run test -- --grep="isFirstFrameKeyIntabPage"
  • Loading branch information
cezaraugusto committed Nov 7, 2017
1 parent 88974f2 commit 1c052f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ const isFirstFrameKeyInTabPage = (state, frameKey) => {
const firstFrame = unpinnedTabs
.slice(startingFrameIndex, startingFrameIndex + tabsPerTabPage).first()

return firstFrame.get('key') === frameKey
return !!firstFrame && firstFrame.get('key') === frameKey
}

const getTabPageIndex = (state) => {
Expand Down
36 changes: 36 additions & 0 deletions test/unit/state/frameStateUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,40 @@ describe('frameStateUtil', function () {
assert.equal(result, true)
})
})

describe('isFirstFrameKeyInTabPage', function () {
beforeEach(function () {
this.frameKey1 = 1
this.frameKey2 = 7
this.state = defaultWindowStore.mergeIn(['frames'],
[{key: this.frameKey1}, {}, {}, {}, {}, {}, {key: this.frameKey2}]
)
})
it('returns false if frames are undefined', function () {
getSettingsValue = 10
const nullFrames = this.state.mergeIn(['frames'], [{}])
const result = frameStateUtil.isFirstFrameKeyInTabPage(this.state, nullFrames)
assert.equal(result, false)
})
it('returns true if the frame is the first in the first tab set', function () {
getSettingsValue = 10
this.state = this.state.setIn(['ui', 'tabs', 'tabPageIndex'], 0)
const result = frameStateUtil.isFirstFrameKeyInTabPage(this.state, this.frameKey1)
assert.equal(result, true)
})
it('ignores pinned frames even if frame is the first in the tab set', function () {
getSettingsValue = 10
this.state = this.state
.setIn(['ui', 'tabs', 'tabPageIndex'], 0)
.mergeIn(['frames', 0], {pinnedLocation: true})
const result = frameStateUtil.isFirstFrameKeyInTabPage(this.state, this.frameKey1)
assert.equal(result, false)
})
it('returns true if the frame is the first in the second tab set', function () {
this.state = this.state.setIn(['ui', 'tabs', 'tabPageIndex'], 1)
getSettingsValue = 6
const result = frameStateUtil.isFirstFrameKeyInTabPage(this.state, this.frameKey2)
assert.equal(result, true)
})
})
})

0 comments on commit 1c052f1

Please sign in to comment.