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

Commit

Permalink
Fixes unit tests2
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed May 22, 2017
1 parent 76a6c1c commit ad1decb
Show file tree
Hide file tree
Showing 24 changed files with 1,087 additions and 958 deletions.
44 changes: 0 additions & 44 deletions app/common/lib/faviconUtil.js

This file was deleted.

31 changes: 31 additions & 0 deletions app/common/lib/tabContentUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const locale = require('../../../js/l10n')
const frameStateUtil = require('../../../js/state/frameStateUtil.js')

module.exports.iconSize = 16

module.exports.getDisplayTitle = (state, frameKey) => {
const frame = frameStateUtil.getFrameByKey(state, frameKey)

if (!frame) {
return ''
}

// For renderer initiated navigation, make sure we show Untitled
// until we know what we're loading. We should probably do this for
// all about: pages that we already know the title for so we don't have
// to wait for the title to be parsed.
if (frame.get('location') === 'about:blank') {
return locale.translation('aboutBlankTitle')
} else if (frame.get('location') === 'about:newtab') {
return locale.translation('newTab')
}

// YouTube tries to change the title to add a play icon when
// there is audio. Since we have our own audio indicator we get
// rid of it.
return (frame.get('title') || frame.get('location') || '').replace('▶ ', '')
}
2 changes: 1 addition & 1 deletion app/renderer/components/bookmarks/bookmarkToolbarButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const dragTypes = require('../../../../js/constants/dragTypes')
const siteUtil = require('../../../../js/state/siteUtil')
const {getCurrentWindowId} = require('../../currentWindow')
const dnd = require('../../../../js/dnd')
const iconSize = require('../../../common/lib/faviconUtil').iconSize
const iconSize = require('../../../common/lib/tabContentUtil').iconSize
const cx = require('../../../../js/lib/classSet')

// Styles
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/bookmarks/bookmarksToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const cx = require('../../../../js/lib/classSet')
const dnd = require('../../../../js/dnd')
const dndData = require('../../../../js/dndData')
const calculateTextWidth = require('../../../../js/lib/textCalculator').calculateTextWidth
const iconSize = require('../../../common/lib/faviconUtil').iconSize
const iconSize = require('../../../common/lib/tabContentUtil').iconSize

// Styles
const globalStyles = require('../styles/global')
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/tabs/content/closeTabIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class CloseTabIcon extends React.Component {

render () {
return <TabIcon
ref={(node) => { this.iconNode = node }}
data-test-id='closeTabIcon'
data-test2-id={this.props.showCloseIcon ? 'close-icon-on' : 'close-icon-off'}
className={css(this.props.showCloseIcon && styles.closeTab)}
l10nId='closeTabButton'
onClick={this.onClick}
Expand Down
1 change: 1 addition & 0 deletions app/renderer/components/tabs/content/tabIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TabIcon extends ImmutableComponent {
[css(styles.icon)]: true
})}
data-test-id={this.props['data-test-id']}
data-test2-id={this.props['data-test2-id']}
data-l10n-id={this.props.l10nId}
data-l10n-args={JSON.stringify(this.props.l10nArgs || {})}
>{this.props.symbolContent}</span>
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/tabs/content/tabTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const frameStateUtil = require('../../../../../js/state/frameStateUtil')

// Styles
const globalStyles = require('../../styles/global')
const tabContentUtil = require('../../../../common/lib/tabContentUtil.js')

class TabTitle extends React.Component {
mergeProps (state, dispatchProps, ownProps) {
Expand All @@ -24,7 +25,7 @@ class TabTitle extends React.Component {
// used in renderer
props.enforceFontVisibilty = isDarwin() && tabIconColor === 'white'
props.tabIconColor = tabIconColor
props.displayTitle = frameStateUtil.getDisplayTitle(currentWindow, ownProps.frameKey)
props.displayTitle = tabContentUtil.getDisplayTitle(currentWindow, ownProps.frameKey)

// used in functions
props.frameKey = ownProps.frameKey
Expand Down
1 change: 0 additions & 1 deletion app/renderer/components/tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ class Tab extends React.Component {
props.isNarrowestView = frameStateUtil.isNarrowestView(currentWindow, props.frameKey)
props.isPlayIndicatorBreakpoint = frameStateUtil.isMediumView(currentWindow, props.frameKey) || props.isNarrowView
props.title = frame.get('title')
props.displayTitle = frameStateUtil.getDisplayTitle(currentWindow, props.frameKey)
props.showSessionIcon = partition && hasSeconardImage
props.showPrivateIcon = props.isPrivateTab && hasSeconardImage
props.showFavIcon = !((hasBreakpoint(breakpoint, 'extraSmall') && props.isActive) || frame.get('location') === 'about:newtab')
Expand Down
1 change: 1 addition & 0 deletions app/renderer/components/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class Tabs extends React.Component {

// used in other functions
props.tabPageIndex = currentWindow.getIn(['ui', 'tabs', 'tabPageIndex'])
props.dragData = state.getIn(['dragData', 'type']) === dragTypes.TAB && state.get('dragData')
props.totalPages = totalPages

return props
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/lib/tabUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const styles = require('../components/styles/global')

/**
* Get tab's breakpoint name for current tab size.
* @param {Number} The current tab size
* @param {Number} tabWidth current tab size
* @returns {String} The matching breakpoint.
*/
module.exports.getTabBreakpoint = (tabWidth) => {
Expand All @@ -28,7 +28,7 @@ module.exports.tabUpdateFrameRate = 66

/**
* Check whether or not current breakpoint match defined criteria
* @param {Object} props - Object that hosts the tab breakpoint
* @param {Object} breakpoint - Brake point value
* @param {Array} arr - Array of Strings including breakpoint names to check against
* @returns {Boolean} Whether or not the sizing criteria was match
*/
Expand Down
2 changes: 1 addition & 1 deletion js/about/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const cx = require('../lib/classSet')
const SortableTable = require('../../app/renderer/components/common/sortableTable')
const siteUtil = require('../state/siteUtil')
const formatUtil = require('../../app/common/lib/formatUtil')
const iconSize = require('../../app/common/lib/faviconUtil').iconSize
const iconSize = require('../../app/common/lib/tabContentUtil').iconSize

const ipc = window.chrome.ipcRenderer

Expand Down
32 changes: 3 additions & 29 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {makeImmutable} = require('../../app/common/state/immutableUtil')
const {getSetting} = require('../settings')
const {isIntermediateAboutPage} = require('../lib/appUrlUtil')
const urlParse = require('../../app/common/urlParse')
const locale = require('../l10n')
const {getTextColorForBackground} = require('../lib/color')
const {hasBreakpoint} = require('../../app/renderer/lib/tabUtil')

Expand Down Expand Up @@ -571,29 +570,6 @@ function isNarrowestView (state, frameKey) {
return sizes.includes(frame.get('breakpoint'))
}

function getDisplayTitle (state, frameKey) {
const frame = getFrameByKey(state, frameKey)

if (!frame) {
return ''
}

// For renderer initiated navigation, make sure we show Untitled
// until we know what we're loading. We should probably do this for
// all about: pages that we already know the title for so we don't have
// to wait for the title to be parsed.
if (frame.get('location') === 'about:blank') {
return locale.translation('aboutBlankTitle')
} else if (frame.get('location') === 'about:newtab') {
return locale.translation('newTab')
}

// YouTube tries to change the title to add a play icon when
// there is audio. Since we have our own audio indicator we get
// rid of it.
return (frame.get('title') || frame.get('location') || '').replace('▶ ', '')
}

function getTabIconColor (state, frameKey) {
const frame = getFrameByKey(state, frameKey)
const isActive = isFrameKeyActive(state, frameKey)
Expand Down Expand Up @@ -622,10 +598,9 @@ function hasFixedCloseIcon (state, frameKey) {

return (
isActive &&
// larger sizes still have a relative closeIcon
!hasBreakpoint(frame.get('breakpoint'), ['default', 'large']) &&
// We don't resize closeIcon as we do with favicon so don't show it
!hasBreakpoint(frame.get('breakpoint'), 'smallest')
// Larger sizes still have a relative closeIcon
// We don't resize closeIcon as we do with favicon so don't show it (smallest)
!hasBreakpoint(frame.get('breakpoint'), ['default', 'large', 'smallest'])
)
}

Expand Down Expand Up @@ -791,7 +766,6 @@ module.exports = {
hasRelativeCloseIcon,
hasFixedCloseIcon,
getTabIconColor,
getDisplayTitle,
isNarrowestView,
isNarrowView,
isMediumView,
Expand Down
95 changes: 95 additions & 0 deletions test/unit/app/common/lib/tabContentUtilTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

/* global describe, it, before, after */

const assert = require('assert')
const Immutable = require('immutable')
const mockery = require('mockery')
const fakeElectron = require('../../../lib/fakeElectron')

const frameKey = 1
const defaultWindowStore = Immutable.fromJS({
activeFrameKey: frameKey,
frames: [{
key: frameKey,
tabId: 1,
location: 'http://brave.com'
}],
tabs: [{
key: frameKey
}],
framesInternal: {
index: {
1: 0
},
tabIndex: {
1: 0
}
}
})

describe('tabContentUtil unit tests', function () {
let tabContentUtil

before(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
})
mockery.registerMock('electron', fakeElectron)
mockery.registerMock('../../../js/l10n', {
translation: () => 'translated'
})
tabContentUtil = require('../../../../../app/common/lib/tabContentUtil')
})

after(function () {
mockery.disable()
})

it('should return empty string if frame is not found', function * () {
const result = tabContentUtil.getDisplayTitle(defaultWindowStore, 0)
assert.equal(result, '')
})

it('should return translated title for about:blank', function * () {
const windowStore = defaultWindowStore.mergeIn(['frames', 0], {
location: 'about:blank'
})
const result = tabContentUtil.getDisplayTitle(windowStore, frameKey)
assert.equal(result, 'translated')
})

it('should return translated title for about:newtab', function * () {
const windowStore = defaultWindowStore.mergeIn(['frames', 0], {
location: 'about:blank'
})
const result = tabContentUtil.getDisplayTitle(windowStore, frameKey)
assert.equal(result, 'translated')
})

it('should return title', function * () {
const title = 'Brave'
const windowStore = defaultWindowStore.mergeIn(['frames', 0], {
title: title
})
const result = tabContentUtil.getDisplayTitle(windowStore, frameKey)
assert.equal(result, title)
})

it('should return location if title is not provided', function * () {
const result = tabContentUtil.getDisplayTitle(defaultWindowStore, frameKey)
assert.equal(result, defaultWindowStore.getIn(['frames', 0, 'location']))
})

it('should replace play indicator from the title (added by Youtube)', function * () {
const windowStore = defaultWindowStore.mergeIn(['frames', 0], {
title: '▶ Brave'
})
const result = tabContentUtil.getDisplayTitle(windowStore, frameKey)
assert.equal(result, 'Brave')
})
})
23 changes: 3 additions & 20 deletions test/unit/app/common/state/basicAuthStateTest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global describe, it, before, after */
/* global describe, it, before */
const basicAuthState = require('../../../../../app/common/state/basicAuthState')
const tabState = require('../../../../../app/common/state/tabState')
const Immutable = require('immutable')
const assert = require('assert')
const mockery = require('mockery')
const fakeElectron = require('../../../lib/fakeElectron')

const defaultTabId = 1

Expand Down Expand Up @@ -31,23 +31,6 @@ const defaultTab = Immutable.fromJS({
})

describe('basicAuthState unit tests', function () {
let basicAuthState, tabState

before(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
})
mockery.registerMock('electron', fakeElectron)
basicAuthState = require('../../../../../app/common/state/basicAuthState')
tabState = require('../../../../../app/common/state/tabState')
})

after(function () {
mockery.disable()
})

describe('setLoginResponseDetail', function () {
describe('`tabId` exists in appState with loginRequiredDetail', function () {
before(function () {
Expand Down
Loading

0 comments on commit ad1decb

Please sign in to comment.