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

Check for no frame info in tab content components #9687

Merged
merged 1 commit into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/renderer/components/tabs/content/audioTabIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const React = require('react')
const {StyleSheet, css} = require('aphrodite/no-important')
const Immutable = require('immutable')

// Components
const ReduxComponent = require('../../reduxComponent')
Expand Down Expand Up @@ -43,7 +44,10 @@ class AudioTabIcon extends React.Component {

mergeProps (state, dispatchProps, ownProps) {
const currentWindow = state.get('currentWindow')
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey)

// AudioIcon will never be created if there is no frameKey, but for consistency
// across other components I added teh || Immutable.Map()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: teh -> the

const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map()

const props = {}
// used in other functions
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/tabs/content/closeTabIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const React = require('react')
const {StyleSheet, css} = require('aphrodite/no-important')
const Immutable = require('immutable')

// Components
const ReduxComponent = require('../../reduxComponent')
Expand Down Expand Up @@ -51,7 +52,7 @@ class CloseTabIcon extends React.Component {
mergeProps (state, dispatchProps, ownProps) {
const currentWindow = state.get('currentWindow')
const isPinnedTab = frameStateUtil.isPinned(currentWindow, ownProps.frameKey)
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey)
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map()

const props = {}
// used in renderer
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/tabs/content/newSessionIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const React = require('react')
const {StyleSheet, css} = require('aphrodite/no-important')
const Immutable = require('immutable')

// Components
const ReduxComponent = require('../../reduxComponent')
Expand All @@ -25,7 +26,7 @@ const newSessionSvg = require('../../../../extensions/brave/img/tabs/new_session
class NewSessionIcon extends React.Component {
mergeProps (state, dispatchProps, ownProps) {
const currentWindow = state.get('currentWindow')
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey)
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map()
const partition = frame.get('partitionNumber')

const props = {}
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

const React = require('react')
const {StyleSheet, css} = require('aphrodite')
const Immutable = require('immutable')

// Components
const ReduxComponent = require('../reduxComponent')
Expand Down Expand Up @@ -230,7 +231,7 @@ class Tab extends React.Component {

mergeProps (state, dispatchProps, ownProps) {
const currentWindow = state.get('currentWindow')
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey)
const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map()
const notifications = state.get('notifications')
const notificationOrigins = notifications ? notifications.map(bar => bar.get('frameOrigin')) : false
const notificationBarActive = frame.get('location') && notificationOrigins &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require('../../../../../braveUnit')

const tabId = 1
const frameKey = 1
const invalidFrameKey = 71

const fakeAppStoreRenderer = {
state: Immutable.fromJS({
Expand Down Expand Up @@ -95,6 +96,12 @@ describe('Tabs content - AudioTabIcon', function () {
const wrapper = mount(<Tab frameKey={frameKey} />)
assert.equal(wrapper.find('AudioTabIcon TabIcon').props().symbol, globalStyles.appIcons.volumeOff)
})
it('passing in a frame key which does not exist does not fail', function () {
windowStore.state = defaultWindowStore
const wrapper = mount(<Tab frameKey={invalidFrameKey} />)
// No audio icon is rendered in this case so just check for Tab
assert(wrapper.find('Tab'))
})
})

describe('should not show', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require('../../../../../braveUnit')

const tabId = 1
const frameKey = 1
const invalidFrameKey = 71

const fakeAppStoreRenderer = {
state: Immutable.fromJS({
Expand Down Expand Up @@ -135,6 +136,12 @@ describe('Tabs content - CloseTabIcon', function () {
const wrapper = mount(<CloseTabIcon frameKey={frameKey} />)
assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-on')
})

it('passing in a frame key which does not exist does not fail', function () {
windowStore.state = defaultWindowStore
const wrapper = mount(<CloseTabIcon frameKey={invalidFrameKey} />)
assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-off')
})
})

describe('should not show icon', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require('../../../../../braveUnit')

const tabId = 1
const frameKey = 1
const invalidFrameKey = 71

const fakeAppStoreRenderer = {
state: Immutable.fromJS({
Expand Down Expand Up @@ -145,6 +146,11 @@ describe('Tabs content - NewSessionIcon', function () {
const wrapper = mount(<NewSessionIcon frameKey={frameKey} />)
assert.equal(wrapper.find('TabIcon').props().symbolContent, tabs.maxAllowedNewSessions)
})
it('passing in a frame key which does not exist does not fail', function () {
windowStore.state = defaultWindowStore
const wrapper = mount(<NewSessionIcon frameKey={invalidFrameKey} />)
assert(wrapper.find('TabIcon'))
})
})

describe('should not show icon', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const url1 = 'https://brave.com'
const pageTitle1 = 'Brave Software'
const tabId = 1
const frameKey = 1
const invalidFrameKey = 71

const fakeAppStoreRenderer = {
state: Immutable.fromJS({
Expand Down Expand Up @@ -138,6 +139,11 @@ describe('Tabs content - Title', function () {
const wrapper = mount(<Tab frameKey={frameKey} />)
assert.equal(wrapper.find('TabTitle div').text(), pageTitle1)
})
it('passing in a frame key which does not exist does not fail', function () {
windowStore.state = defaultWindowStore
const wrapper = mount(<Tab frameKey={invalidFrameKey} />)
assert.equal(wrapper.find('TabTitle div').text(), '')
})
})

describe('should not show text', function () {
Expand Down