diff --git a/app/common/lib/faviconUtil.js b/app/common/lib/faviconUtil.js deleted file mode 100644 index 7c95007b276..00000000000 --- a/app/common/lib/faviconUtil.js +++ /dev/null @@ -1,44 +0,0 @@ -/* 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 {isSourceAboutUrl} = require('../../../js/lib/appUrlUtil') -const UrlUtil = require('../../../js/lib/urlutil') - -module.exports.iconSize = 16 - -module.exports.getFavicon = (frameProps, iconHref) => { - return new Promise((resolve, reject) => { - if (!frameProps.get('location')) { - resolve(null) - } - - const size = window.devicePixelRatio * module.exports.iconSize - const resolution = '#-moz-resolution=' + size + ',' + size - - // Default to favicon.ico if we can't find an icon. - if (!iconHref) { - let loc = frameProps.get('location') - if (UrlUtil.isViewSourceUrl(loc)) { - loc = loc.substring('view-source:'.length) - } else if (UrlUtil.isImageDataUrl(loc)) { - resolve(loc) - } else if (isSourceAboutUrl(loc) || UrlUtil.isDataUrl(loc)) { - resolve('') - } - - try { - const defaultIcon = new window.URL('/favicon.ico' + resolution, loc) - iconHref = defaultIcon.toString() - } catch (e) { - resolve('') - } - } - - if (UrlUtil.isImageDataUrl(iconHref)) { - resolve(iconHref) - } else { - resolve(iconHref + resolution) - } - }) -} diff --git a/app/common/lib/tabContentUtil.js b/app/common/lib/tabContentUtil.js new file mode 100644 index 00000000000..ecac2d9650c --- /dev/null +++ b/app/common/lib/tabContentUtil.js @@ -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('▶ ', '') +} diff --git a/app/renderer/components/bookmarks/bookmarkToolbarButton.js b/app/renderer/components/bookmarks/bookmarkToolbarButton.js index b946b452a00..1c541ffc608 100644 --- a/app/renderer/components/bookmarks/bookmarkToolbarButton.js +++ b/app/renderer/components/bookmarks/bookmarkToolbarButton.js @@ -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 diff --git a/app/renderer/components/bookmarks/bookmarksToolbar.js b/app/renderer/components/bookmarks/bookmarksToolbar.js index 2a271c1d469..b33a1089991 100644 --- a/app/renderer/components/bookmarks/bookmarksToolbar.js +++ b/app/renderer/components/bookmarks/bookmarksToolbar.js @@ -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') diff --git a/app/renderer/components/tabs/content/closeTabIcon.js b/app/renderer/components/tabs/content/closeTabIcon.js index 7fce31a926c..ea58a51faa1 100644 --- a/app/renderer/components/tabs/content/closeTabIcon.js +++ b/app/renderer/components/tabs/content/closeTabIcon.js @@ -66,8 +66,8 @@ class CloseTabIcon extends React.Component { render () { return { 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} diff --git a/app/renderer/components/tabs/content/tabIcon.js b/app/renderer/components/tabs/content/tabIcon.js index 01250487c95..a3704504582 100644 --- a/app/renderer/components/tabs/content/tabIcon.js +++ b/app/renderer/components/tabs/content/tabIcon.js @@ -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} diff --git a/app/renderer/components/tabs/content/tabTitle.js b/app/renderer/components/tabs/content/tabTitle.js index 0bbe865b17f..34f8b736874 100644 --- a/app/renderer/components/tabs/content/tabTitle.js +++ b/app/renderer/components/tabs/content/tabTitle.js @@ -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) { @@ -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 diff --git a/app/renderer/components/tabs/tab.js b/app/renderer/components/tabs/tab.js index d33f7d9bc84..394834d4501 100644 --- a/app/renderer/components/tabs/tab.js +++ b/app/renderer/components/tabs/tab.js @@ -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') diff --git a/app/renderer/components/tabs/tabs.js b/app/renderer/components/tabs/tabs.js index bee20bd2529..91c669d2b22 100644 --- a/app/renderer/components/tabs/tabs.js +++ b/app/renderer/components/tabs/tabs.js @@ -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 diff --git a/app/renderer/lib/tabUtil.js b/app/renderer/lib/tabUtil.js index 1e89278981a..c6130d74d88 100644 --- a/app/renderer/lib/tabUtil.js +++ b/app/renderer/lib/tabUtil.js @@ -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) => { @@ -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 */ diff --git a/js/about/bookmarks.js b/js/about/bookmarks.js index 1c0659a0b35..8e4607e1690 100644 --- a/js/about/bookmarks.js +++ b/js/about/bookmarks.js @@ -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 diff --git a/js/state/frameStateUtil.js b/js/state/frameStateUtil.js index d2889ba571c..7d5504dd098 100644 --- a/js/state/frameStateUtil.js +++ b/js/state/frameStateUtil.js @@ -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') @@ -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) @@ -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']) ) } @@ -791,7 +766,6 @@ module.exports = { hasRelativeCloseIcon, hasFixedCloseIcon, getTabIconColor, - getDisplayTitle, isNarrowestView, isNarrowView, isMediumView, diff --git a/test/unit/app/common/lib/tabContentUtilTest.js b/test/unit/app/common/lib/tabContentUtilTest.js new file mode 100644 index 00000000000..f1c4f5214ae --- /dev/null +++ b/test/unit/app/common/lib/tabContentUtilTest.js @@ -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') + }) +}) diff --git a/test/unit/app/common/state/basicAuthStateTest.js b/test/unit/app/common/state/basicAuthStateTest.js index f6f3504ef19..fdc3cf691ed 100644 --- a/test/unit/app/common/state/basicAuthStateTest.js +++ b/test/unit/app/common/state/basicAuthStateTest.js @@ -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 @@ -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 () { diff --git a/test/unit/app/common/state/tabMessageBoxStateTest.js b/test/unit/app/common/state/tabMessageBoxStateTest.js index 9e9caa2d82a..9eaab60986f 100644 --- a/test/unit/app/common/state/tabMessageBoxStateTest.js +++ b/test/unit/app/common/state/tabMessageBoxStateTest.js @@ -1,10 +1,10 @@ /* global describe, it, before, after */ +const tabMessageBoxState = require('../../../../../app/common/state/tabMessageBoxState') +const tabState = require('../../../../../app/common/state/tabState') +const {makeImmutable} = require('../../../../../app/common/state/immutableUtil') const sinon = require('sinon') const Immutable = require('immutable') const assert = require('assert') -const mockery = require('mockery') -const {makeImmutable} = require('../../../../../app/common/state/immutableUtil') -const fakeElectron = require('../../../lib/fakeElectron') const defaultTabId = 1 @@ -39,23 +39,6 @@ const defaultTab = Immutable.fromJS({ }) describe('tabMessageBoxState unit tests', function () { - let tabMessageBoxState, tabState - - before(function () { - mockery.enable({ - warnOnReplace: false, - warnOnUnregistered: false, - useCleanCache: true - }) - mockery.registerMock('electron', fakeElectron) - tabMessageBoxState = require('../../../../../app/common/state/tabMessageBoxState') - tabState = require('../../../../../app/common/state/tabState') - }) - - after(function () { - mockery.disable() - }) - describe('show', function () { describe('when a detail object does not exist', function () { before(function () { diff --git a/test/unit/app/common/state/tabStateTest.js b/test/unit/app/common/state/tabStateTest.js index 1763c59cf12..03c3f32f9e3 100644 --- a/test/unit/app/common/state/tabStateTest.js +++ b/test/unit/app/common/state/tabStateTest.js @@ -1,10 +1,9 @@ /* global describe, it, before, after */ +const tabState = require('../../../../../app/common/state/tabState') const Immutable = require('immutable') const sinon = require('sinon') const assert = require('chai').assert const AssertionError = require('assert').AssertionError -const mockery = require('mockery') -const fakeElectron = require('../../../lib/fakeElectron') const defaultAppState = Immutable.fromJS({ tabs: [], @@ -196,22 +195,6 @@ const shouldValidateAction = function (cb) { } describe('tabState unit tests', function () { - let tabState - - before(function () { - mockery.enable({ - warnOnReplace: false, - warnOnUnregistered: false, - useCleanCache: true - }) - mockery.registerMock('electron', fakeElectron) - tabState = require('../../../../../app/common/state/tabState') - }) - - after(function () { - mockery.disable() - }) - describe('getByTabId', function () { before(function () { this.appState = twoTabsAppState diff --git a/test/unit/app/renderer/components/navigation/navigatorTest.js b/test/unit/app/renderer/components/navigation/navigatorTest.js index 7f007e79ada..1db7dd313eb 100644 --- a/test/unit/app/renderer/components/navigation/navigatorTest.js +++ b/test/unit/app/renderer/components/navigation/navigatorTest.js @@ -95,7 +95,7 @@ describe('Navigator component unit tests', function () { }) after(function () { - mockery.disable() + mockery.deregisterAll() }) describe('when user has history going forwards and backwards', function () { diff --git a/test/unit/app/renderer/components/tabs/content/audioTabIconTest.js b/test/unit/app/renderer/components/tabs/content/audioTabIconTest.js index 7a946a5be1f..1b4370e6f31 100644 --- a/test/unit/app/renderer/components/tabs/content/audioTabIconTest.js +++ b/test/unit/app/renderer/components/tabs/content/audioTabIconTest.js @@ -4,15 +4,55 @@ /* global describe, before, it, after */ const mockery = require('mockery') -const {shallow} = require('enzyme') +const {mount} = require('enzyme') const assert = require('assert') const Immutable = require('immutable') const globalStyles = require('../../../../../../../app/renderer/components/styles/global') const fakeElectron = require('../../../../../lib/fakeElectron') require('../../../../../braveUnit') +const tabId = 1 +const frameKey = 1 + +const fakeAppStoreRenderer = { + state: Immutable.fromJS({ + windows: [{ + windowId: 1, + windowUUID: 'uuid' + }], + tabs: [{ + tabId: tabId, + windowId: 1, + windowUUID: 'uuid', + url: 'https://brave.com' + }] + }), + addChangeListener: () => {}, + removeChangeListener: () => {} +} + +const defaultWindowStore = Immutable.fromJS({ + activeFrameKey: frameKey, + frames: [{ + key: frameKey, + tabId: tabId, + location: 'http://brave.com' + }], + tabs: [{ + key: frameKey + }], + framesInternal: { + index: { + 1: 0 + }, + tabIndex: { + 1: 0 + } + } +}) + describe('Tabs content - AudioTabIcon', function () { - let AudioTabIcon + let Tab, windowStore before(function () { mockery.enable({ @@ -21,75 +61,71 @@ describe('Tabs content - AudioTabIcon', function () { useCleanCache: true }) mockery.registerMock('electron', fakeElectron) - AudioTabIcon = require('../../../../../../../app/renderer/components/tabs/content/audioTabIcon') + mockery.registerMock('../../../js/stores/appStoreRenderer', fakeAppStoreRenderer) + mockery.registerMock('../../../../extensions/brave/img/tabs/loading.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/new_session.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/private.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_hover.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_normal.svg') + windowStore = require('../../../../../../../js/stores/windowStore') + Tab = require('../../../../../../../app/renderer/components/tabs/tab') }) after(function () { + mockery.deregisterAll() mockery.disable() }) - it('should not show any audio icon if page has audio disabled', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props().symbol, globalStyles.appIcons.volumeOn) - assert.notEqual(wrapper.props().symbol, globalStyles.appIcons.volumeOff) - }) - it('should show play icon if page has audio enabled', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props().symbol, globalStyles.appIcons.volumeOn) - }) - it('should not show play audio icon if tab size is different than default', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props().symbol, globalStyles.appIcons.volumeOn) - }) - it('should show mute icon if page has audio muted', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props().symbol, globalStyles.appIcons.volumeOff) + describe('should show', function () { + it('play icon if page has audio enabled', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + audioPlaybackActive: true, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('AudioTabIcon TabIcon').props().symbol, globalStyles.appIcons.volumeOn) + }) + + it('mute icon if page has audio muted', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + audioPlaybackActive: true, + audioMuted: true, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('AudioTabIcon TabIcon').props().symbol, globalStyles.appIcons.volumeOff) + }) }) - it('should not show mute icon if tab size is different than default', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props().symbol, globalStyles.appIcons.volumeOff) + + describe('should not show', function () { + it('any audio icon if page has audio disabled', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + audioPlaybackActive: false, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('AudioTabIcon').length, 0) + assert.equal(wrapper.find('AudioTabIcon').length, 0) + }) + + it('play audio icon if tab size is different than default', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + audioPlaybackActive: true, + audioMuted: false, + breakpoint: 'small' + }) + const wrapper = mount() + assert.equal(wrapper.find('AudioTabIcon').length, 0) + }) + + it('mute icon if tab size is different than default', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + audioPlaybackActive: true, + audioMuted: true, + breakpoint: 'small' + }) + const wrapper = mount() + assert.equal(wrapper.find('AudioTabIcon').length, 0) + }) }) }) diff --git a/test/unit/app/renderer/components/tabs/content/closeTabIconTest.js b/test/unit/app/renderer/components/tabs/content/closeTabIconTest.js index e5ae6095aba..ec2bd716238 100644 --- a/test/unit/app/renderer/components/tabs/content/closeTabIconTest.js +++ b/test/unit/app/renderer/components/tabs/content/closeTabIconTest.js @@ -4,14 +4,54 @@ /* global describe, before, after, it */ const mockery = require('mockery') -const {shallow} = require('enzyme') +const {mount} = require('enzyme') const assert = require('assert') const Immutable = require('immutable') const fakeElectron = require('../../../../../lib/fakeElectron') require('../../../../../braveUnit') +const tabId = 1 +const frameKey = 1 + +const fakeAppStoreRenderer = { + state: Immutable.fromJS({ + windows: [{ + windowId: 1, + windowUUID: 'uuid' + }], + tabs: [{ + tabId: tabId, + windowId: 1, + windowUUID: 'uuid', + url: 'https://brave.com' + }] + }), + addChangeListener: () => {}, + removeChangeListener: () => {} +} + +const defaultWindowStore = Immutable.fromJS({ + activeFrameKey: frameKey, + frames: [{ + key: frameKey, + tabId: tabId, + location: 'http://brave.com' + }], + tabs: [{ + key: frameKey + }], + framesInternal: { + index: { + 1: 0 + }, + tabIndex: { + 1: 0 + } + } +}) + describe('Tabs content - CloseTabIcon', function () { - let CloseTabIcon + let CloseTabIcon, windowStore before(function () { mockery.enable({ @@ -20,183 +60,161 @@ describe('Tabs content - CloseTabIcon', function () { useCleanCache: true }) mockery.registerMock('electron', fakeElectron) + mockery.registerMock('../../../js/stores/appStoreRenderer', fakeAppStoreRenderer) mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_hover.svg') mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_normal.svg') + windowStore = require('../../../../../../../js/stores/windowStore') CloseTabIcon = require('../../../../../../../app/renderer/components/tabs/content/closeTabIcon') }) after(function () { + mockery.deregisterAll() mockery.disable() }) - it('should show closeTab icon if mouse is over tab and breakpoint is default', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should show closeTab icon if mouse is over tab and breakpoint is large', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should not show closeTab icon if tab is pinned', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should show closeTab icon if tab size is largeMedium and tab is active', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should not show closeTab icon if tab size is largeMedium and tab is not active', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'closeTabIcon') - }) + describe('should show icon', function () { + it('if mouse is over tab and breakpoint is default', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + hoverState: true, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-on') + }) - it('should show closeTab icon if tab size is medium and tab is active', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should not show closeTab icon if tab size is medium and tab is not active', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'closeTabIcon') - }) + it('if mouse is over tab and breakpoint is large', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + hoverState: true, + breakpoint: 'large' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-on') + }) - it('should show closeTab icon if tab size is mediumSmall and tab is active', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should not show closeTab icon if tab size is mediumSmall and tab is not active', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should show closeTab icon if tab size is small and tab is active', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should not show closeTab icon if tab size is small and tab is not active', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should show closeTab icon if tab size is extraSmall and tab is active', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'closeTabIcon') - }) - it('should not show closeTab icon if tab size is extraSmall and tab is not active', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'closeTabIcon') + it('if tab size is largeMedium and tab is active', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + hoverState: false, + breakpoint: 'largeMedium' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-on') + }) + + it('if tab size is medium and tab is active', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + hoverState: false, + breakpoint: 'medium' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-on') + }) + + it('if tab size is mediumSmall and tab is active', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + hoverState: false, + breakpoint: 'mediumSmall' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-on') + }) + + it('if tab size is small and tab is active', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + hoverState: false, + breakpoint: 'small' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-on') + }) + + it('if tab size is extraSmall and tab is active', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + hoverState: false, + breakpoint: 'extraSmall' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-on') + }) }) - it('should not show closeTab icon if tab size is the smallest size', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'closeTabIcon') + + describe('should not show icon', function () { + it('if tab is pinned', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + hoverState: true, + pinnedLocation: true + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-off') + }) + + it('if tab size is largeMedium and tab is not active', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + hoverState: true, + breakpoint: 'largeMedium' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-off') + }) + + it('if tab size is medium and tab is not active', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + hoverState: true, + breakpoint: 'medium' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-off') + }) + + it('if tab size is mediumSmall and tab is not active', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + hoverState: true, + breakpoint: 'mediumSmall' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-off') + }) + + it('if tab size is small and tab is not active', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + hoverState: true, + breakpoint: 'small' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-off') + }) + + it('if tab size is extraSmall and tab is not active', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + hoverState: true, + breakpoint: 'extraSmall' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-off') + }) + + // TODO check what is going on + it.skip('if tab size is the smallest size', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + hoverState: true, + breakpoint: 'extraSmall' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props()['data-test2-id'], 'close-icon-off') + }) }) }) diff --git a/test/unit/app/renderer/components/tabs/content/favIconTest.js b/test/unit/app/renderer/components/tabs/content/favIconTest.js index e475a4af04e..268b845858b 100644 --- a/test/unit/app/renderer/components/tabs/content/favIconTest.js +++ b/test/unit/app/renderer/components/tabs/content/favIconTest.js @@ -4,7 +4,7 @@ /* global describe, before, after, it */ const mockery = require('mockery') -const {shallow} = require('enzyme') +const {mount} = require('enzyme') const Immutable = require('immutable') const assert = require('assert') const globalStyles = require('../../../../../../../app/renderer/components/styles/global') @@ -14,8 +14,48 @@ require('../../../../../braveUnit') const url1 = 'https://brave.com' const favicon1 = 'https://brave.com/favicon.ico' +const tabId = 1 +const frameKey = 1 + +const fakeAppStoreRenderer = { + state: Immutable.fromJS({ + windows: [{ + windowId: 1, + windowUUID: 'uuid' + }], + tabs: [{ + tabId: tabId, + windowId: 1, + windowUUID: 'uuid', + url: 'https://brave.com' + }] + }), + addChangeListener: () => {}, + removeChangeListener: () => {} +} + +const defaultWindowStore = Immutable.fromJS({ + activeFrameKey: frameKey, + frames: [{ + key: frameKey, + tabId: tabId, + location: 'http://brave.com' + }], + tabs: [{ + key: frameKey + }], + framesInternal: { + index: { + 1: 0 + }, + tabIndex: { + 1: 0 + } + } +}) + describe('Tabs content - Favicon', function () { - let Favicon + let Tab, windowStore before(function () { mockery.enable({ @@ -24,63 +64,60 @@ describe('Tabs content - Favicon', function () { useCleanCache: true }) mockery.registerMock('electron', fakeElectron) + mockery.registerMock('../../../../common/lib/tabContentUtil.js', { + getDisplayTitle: () => {} + }) + mockery.registerMock('../../../js/stores/appStoreRenderer', fakeAppStoreRenderer) mockery.registerMock('../../../../extensions/brave/img/tabs/loading.svg') - Favicon = require('../../../../../../../app/renderer/components/tabs/content/favIcon') + mockery.registerMock('../../../../extensions/brave/img/tabs/new_session.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/private.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_hover.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_normal.svg') + windowStore = require('../../../../../../../js/stores/windowStore') + Tab = require('../../../../../../../app/renderer/components/tabs/tab') }) after(function () { - mockery.disable() + mockery.deregisterAll() }) - it('should show favicon if page has one', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-favicon'], favicon1) - }) - it('should show a placeholder icon if page has no favicon', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props().symbol, globalStyles.appIcons.defaultIcon) - }) - it('should show a loading icon if page is still loading', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'loading') + describe('should show', function () { + it('favicon if page has one', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + icon: favicon1, + loading: false + }) + const wrapper = mount() + assert.equal(wrapper.find('Favicon').length, 1) + }) + + it('placeholder icon if page has no favicon', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + icon: null, + loading: false + }) + const wrapper = mount() + assert.equal(wrapper.find('Favicon TabIcon').props().symbol, globalStyles.appIcons.defaultIcon) + }) + + it('loading icon if page is still loading', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + icon: favicon1, + loading: true + }) + const wrapper = mount() + assert.equal(wrapper.find('Favicon TabIcon').props()['data-test-id'], 'loading') + }) }) + it('should not show favicon for new tab page', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props().favicon, favicon1, 'does not show favicon') - assert.notEqual(wrapper.props().symbol, globalStyles.appIcons.loading, 'does not show loading icon') - assert.notEqual(wrapper.props().symbol, globalStyles.appIcons.defaultIcon, 'does not show default icon') + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: 'about:newtab' + }) + const wrapper = mount() + assert.equal(wrapper.find('Favicon').length, 0) }) }) diff --git a/test/unit/app/renderer/components/tabs/content/newSessionIconTest.js b/test/unit/app/renderer/components/tabs/content/newSessionIconTest.js index 18c54ea1112..1e84052ce61 100644 --- a/test/unit/app/renderer/components/tabs/content/newSessionIconTest.js +++ b/test/unit/app/renderer/components/tabs/content/newSessionIconTest.js @@ -4,15 +4,55 @@ /* global describe, before, after, it */ const mockery = require('mockery') -const {shallow} = require('enzyme') +const {mount} = require('enzyme') const assert = require('assert') const Immutable = require('immutable') const {tabs} = require('../../../../../../../js/constants/config') const fakeElectron = require('../../../../../lib/fakeElectron') require('../../../../../braveUnit') +const tabId = 1 +const frameKey = 1 + +const fakeAppStoreRenderer = { + state: Immutable.fromJS({ + windows: [{ + windowId: 1, + windowUUID: 'uuid' + }], + tabs: [{ + tabId: tabId, + windowId: 1, + windowUUID: 'uuid', + url: 'https://brave.com' + }] + }), + addChangeListener: () => {}, + removeChangeListener: () => {} +} + +const defaultWindowStore = Immutable.fromJS({ + activeFrameKey: frameKey, + frames: [{ + key: frameKey, + tabId: tabId, + location: 'http://brave.com' + }], + tabs: [{ + key: frameKey + }], + framesInternal: { + index: { + 1: 0 + }, + tabIndex: { + 1: 0 + } + } +}) + describe('Tabs content - NewSessionIcon', function () { - let NewSessionIcon + let Tab, windowStore, NewSessionIcon before(function () { mockery.enable({ @@ -21,223 +61,192 @@ describe('Tabs content - NewSessionIcon', function () { useCleanCache: true }) mockery.registerMock('electron', fakeElectron) + mockery.registerMock('../../../js/stores/appStoreRenderer', fakeAppStoreRenderer) + mockery.registerMock('../../../../extensions/brave/img/tabs/loading.svg') mockery.registerMock('../../../../extensions/brave/img/tabs/new_session.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/private.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_hover.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_normal.svg') + windowStore = require('../../../../../../../js/stores/windowStore') + Tab = require('../../../../../../../app/renderer/components/tabs/tab') NewSessionIcon = require('../../../../../../../app/renderer/components/tabs/content/newSessionIcon') }) after(function () { - mockery.disable() + mockery.deregisterAll() }) - it('should show new session icon if current tab is a new session tab', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should not show new session icon if current tab is not private', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should not show new session icon if mouse is over tab and breakpoint is default', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should show new session icon if mouse is not over tab and breakpoint is default', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should not show new session icon if mouse is over tab and breakpoint is large', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should show new session icon if mouse is not over tab and breakpoint is large', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should not show new session icon if tab is active and breakpoint is largeMedium', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should show new session icon if tab is not active and breakpoint is largeMedium', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should not show new session icon if tab is active and breakpoint is medium', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should show new session icon if tab is not active and breakpoint is medium', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should not show new session icon if breakpoint is mediumSmall', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should not show new session icon if breakpoint is small', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should not show new session icon if breakpoint is extraSmall', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should not show new session icon if breakpoint is the smallest', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'newSessionIcon') - }) - it('should show partition number for new sessions', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props().symbolContent, 3) - }) - it('should read and show partition number for sessions with number set by opener (ex: clicking target=_blank)', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props().symbolContent, 3) + describe('should show', function () { + it('icon if current tab is a new session tab', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 1) + }) + + it('icon if mouse is not over tab and breakpoint is default', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: false, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 1) + }) + + it('icon if mouse is not over tab and breakpoint is large', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: false, + breakpoint: 'large' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 1) + }) + + it('icon if tab is not active and breakpoint is largeMedium', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + partitionNumber: 1, + hoverState: false, + breakpoint: 'largeMedium' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 1) + }) + + it('icon if tab is not active and breakpoint is medium', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + partitionNumber: 1, + hoverState: false, + breakpoint: 'medium' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 1) + }) + + it('partition number for new sessions', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 3, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props().symbolContent, 3) + }) + + it('partition number for sessions with number set by opener (ex: clicking target=_blank)', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 'partition-3', + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props().symbolContent, 3) + }) + + it('max partition number even if session is bigger', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1000, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabIcon').props().symbolContent, tabs.maxAllowedNewSessions) + }) }) - it('should show max partition number even if session is bigger', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props().symbolContent, tabs.maxAllowedNewSessions) + + describe('should not show icon', function () { + it('if current tab is not private', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: false + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 0) + }) + + it('if mouse is over tab and breakpoint is default', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: true, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 0) + }) + + it('if mouse is over tab and breakpoint is large', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: true, + breakpoint: 'large' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 0) + }) + + it('if tab is active and breakpoint is largeMedium', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: true, + breakpoint: 'largeMedium' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 0) + }) + + it('if tab is active and breakpoint is medium', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: true, + breakpoint: 'medium' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 0) + }) + + it('if breakpoint is mediumSmall', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: false, + breakpoint: 'mediumSmall' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 0) + }) + + it('if breakpoint is small', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: true, + breakpoint: 'small' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 0) + }) + + it('if breakpoint is extraSmall', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: true, + breakpoint: 'extraSmall' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 0) + }) + + it('if breakpoint is the smallest', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + partitionNumber: 1, + hoverState: true, + breakpoint: 'smallest' + }) + const wrapper = mount() + assert.equal(wrapper.find('NewSessionIcon').length, 0) + }) }) }) diff --git a/test/unit/app/renderer/components/tabs/content/privateIconTest.js b/test/unit/app/renderer/components/tabs/content/privateIconTest.js index 72e73c32f15..210dde4d042 100644 --- a/test/unit/app/renderer/components/tabs/content/privateIconTest.js +++ b/test/unit/app/renderer/components/tabs/content/privateIconTest.js @@ -4,14 +4,54 @@ /* global describe, before, after, it */ const mockery = require('mockery') -const {shallow} = require('enzyme') +const {mount} = require('enzyme') const Immutable = require('immutable') const assert = require('assert') const fakeElectron = require('../../../../../lib/fakeElectron') require('../../../../../braveUnit') +const tabId = 1 +const frameKey = 1 + +const fakeAppStoreRenderer = { + state: Immutable.fromJS({ + windows: [{ + windowId: 1, + windowUUID: 'uuid' + }], + tabs: [{ + tabId: tabId, + windowId: 1, + windowUUID: 'uuid', + url: 'https://brave.com' + }] + }), + addChangeListener: () => {}, + removeChangeListener: () => {} +} + +const defaultWindowStore = Immutable.fromJS({ + activeFrameKey: frameKey, + frames: [{ + key: frameKey, + tabId: tabId, + location: 'http://brave.com' + }], + tabs: [{ + key: frameKey + }], + framesInternal: { + index: { + 1: 0 + }, + tabIndex: { + 1: 0 + } + } +}) + describe('Tabs content - PrivateIcon', function () { - let PrivateIcon + let Tab, windowStore before(function () { mockery.enable({ @@ -20,190 +60,165 @@ describe('Tabs content - PrivateIcon', function () { useCleanCache: true }) mockery.registerMock('electron', fakeElectron) + mockery.registerMock('../../../js/stores/appStoreRenderer', fakeAppStoreRenderer) + mockery.registerMock('../../../../extensions/brave/img/tabs/loading.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/new_session.svg') mockery.registerMock('../../../../extensions/brave/img/tabs/private.svg') - PrivateIcon = require('../../../../../../../app/renderer/components/tabs/content/privateIcon') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_hover.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_normal.svg') + windowStore = require('../../../../../../../js/stores/windowStore') + Tab = require('../../../../../../../app/renderer/components/tabs/tab') }) after(function () { + mockery.deregisterAll() mockery.disable() }) - it('should show private icon if current tab is private', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should not show private icon if current tab is not private', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should not show private icon if mouse is over tab and breakpoint is default', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should show private icon if mouse is not over tab and breakpoint is default', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should not show private icon if mouse is over tab and breakpoint is large', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should show private icon if mouse is not over tab and breakpoint is large', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should not show private icon if tab is active and breakpoint is largeMedium', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should show private icon if tab is not active and breakpoint is largeMedium', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should not show private icon if tab is active and breakpoint is medium', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should show private icon if tab is not active and breakpoint is medium', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should not show private icon if breakpoint is mediumSmall', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should not show private icon if breakpoint is small', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'privateIcon') - }) - it('should not show private icon if breakpoint is extraSmall', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'privateIcon') + describe('should show icon', function () { + it('if current tab is private', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 1) + }) + + it('if tab is not active and breakpoint is largeMedium', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + isPrivate: true, + hoverState: false, + breakpoint: 'largeMedium' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 1) + }) + + it('if mouse is not over tab and breakpoint is large', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: false, + breakpoint: 'large' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 1) + }) + + it('if tab is not active and breakpoint is medium', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + isPrivate: true, + hoverState: false, + breakpoint: 'medium' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 1) + }) + + it('if mouse is not over tab and breakpoint is default', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: false, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 1) + }) }) - it('should not show private icon if breakpoint is the smallest', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.props()['data-test-id'], 'privateIcon') + + describe('should not show icon', function () { + it('if current tab is not private', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: false + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 0) + }) + + it('if mouse is over tab and breakpoint is default', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: true, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 0) + }) + + it('if mouse is over tab and breakpoint is large', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: true, + breakpoint: 'large' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 0) + }) + + it('if tab is active and breakpoint is largeMedium', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: true, + breakpoint: 'largeMedium' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 0) + }) + + it('if tab is active and breakpoint is medium', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: true, + breakpoint: 'medium' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 0) + }) + + it('if breakpoint is mediumSmall', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: false, + breakpoint: 'mediumSmall' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 0) + }) + + it('if breakpoint is small', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: true, + breakpoint: 'small' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 0) + }) + + it('if breakpoint is extraSmall', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: true, + breakpoint: 'extraSmall' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 0) + }) + + it('if breakpoint is the smallest', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + isPrivate: true, + hoverState: true, + breakpoint: 'smallest' + }) + const wrapper = mount() + assert.equal(wrapper.find('PrivateIcon').length, 0) + }) }) }) diff --git a/test/unit/app/renderer/components/tabs/content/tabTitleTest.js b/test/unit/app/renderer/components/tabs/content/tabTitleTest.js index ce7febf9528..603355b1376 100644 --- a/test/unit/app/renderer/components/tabs/content/tabTitleTest.js +++ b/test/unit/app/renderer/components/tabs/content/tabTitleTest.js @@ -5,7 +5,7 @@ /* global describe, before, it, after */ const mockery = require('mockery') -const {shallow} = require('enzyme') +const {mount} = require('enzyme') const assert = require('assert') const Immutable = require('immutable') const fakeElectron = require('../../../../../lib/fakeElectron') @@ -13,9 +13,49 @@ require('../../../../../braveUnit') const url1 = 'https://brave.com' const pageTitle1 = 'Brave Software' +const tabId = 1 +const frameKey = 1 + +const fakeAppStoreRenderer = { + state: Immutable.fromJS({ + windows: [{ + windowId: 1, + windowUUID: 'uuid' + }], + tabs: [{ + tabId: tabId, + windowId: 1, + windowUUID: 'uuid', + url: url1 + }] + }), + addChangeListener: () => {}, + removeChangeListener: () => {} +} + +const defaultWindowStore = Immutable.fromJS({ + activeFrameKey: frameKey, + frames: [{ + key: frameKey, + tabId: tabId, + location: url1, + title: pageTitle1 + }], + tabs: [{ + key: frameKey + }], + framesInternal: { + index: { + 1: 0 + }, + tabIndex: { + 1: 0 + } + } +}) describe('Tabs content - Title', function () { - let TabTitle + let Tab, windowStore before(function () { mockery.enable({ @@ -24,150 +64,116 @@ describe('Tabs content - Title', function () { useCleanCache: true }) mockery.registerMock('electron', fakeElectron) - TabTitle = require('../../../../../../../app/renderer/components/tabs/content/tabTitle') + mockery.registerMock('../../../js/stores/appStoreRenderer', fakeAppStoreRenderer) + mockery.registerMock('../../../../extensions/brave/img/tabs/loading.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/new_session.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/private.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_hover.svg') + mockery.registerMock('../../../../extensions/brave/img/tabs/close_btn_normal.svg') + windowStore = require('../../../../../../../js/stores/windowStore') + Tab = require('../../../../../../../app/renderer/components/tabs/tab') }) after(function () { - mockery.disable() + mockery.deregisterAll() }) - it('should show text if page has a title', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.text(), pageTitle1) - }) - it('should not show text if tab is pinned', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.text(), pageTitle1) - }) - it('should show text if breakpoint is default', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.text(), pageTitle1) - }) - it('should show text if breakpoint is large', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.text(), pageTitle1) - }) - it('should show text if breakpoint is medium', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.text(), pageTitle1) - }) - it('should show text if breakpoint is mediumSmall', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.text(), pageTitle1) - }) - it('should show text if breakpoint is small and tab is not active', function () { - const wrapper = shallow( - - ) - assert.equal(wrapper.text(), pageTitle1) - }) - it('should not show text if breakpoint is small and tab is active', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.text(), pageTitle1) - }) - it('should not show text if breakpoint is extraSmall', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.text(), pageTitle1) + describe('should show text', function () { + it('if page has a title', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + title: pageTitle1 + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle div').text(), pageTitle1) + }) + it('if breakpoint is default', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + title: pageTitle1, + breakpoint: 'default' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle div').text(), pageTitle1) + }) + it('if breakpoint is large', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + title: pageTitle1, + breakpoint: 'large' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle div').text(), pageTitle1) + }) + it('if breakpoint is medium', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + title: pageTitle1, + breakpoint: 'medium' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle div').text(), pageTitle1) + }) + it('if breakpoint is mediumSmall', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + title: pageTitle1, + breakpoint: 'mediumSmall' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle div').text(), pageTitle1) + }) + it('if breakpoint is small and tab is not active', function () { + windowStore.state = defaultWindowStore.merge({ + activeFrameKey: 0, + frames: [{ + location: url1, + title: pageTitle1, + breakpoint: 'small' + }] + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle div').text(), pageTitle1) + }) }) - it('should not show text if breakpoint is the smallest', function () { - const wrapper = shallow( - - ) - assert.notEqual(wrapper.text(), pageTitle1) + + describe('should not show text', function () { + it('if tab is pinned', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + title: pageTitle1, + pinnedLocation: true + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle').length, 0) + }) + + it('if breakpoint is small and tab is active', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + title: pageTitle1, + breakpoint: 'small' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle').length, 0) + }) + it('if breakpoint is extraSmall', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + title: pageTitle1, + breakpoint: 'extraSmall' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle').length, 0) + }) + it('if breakpoint is the smallest', function () { + windowStore.state = defaultWindowStore.mergeIn(['frames', 0], { + location: url1, + title: pageTitle1, + breakpoint: 'smallest' + }) + const wrapper = mount() + assert.equal(wrapper.find('TabTitle').length, 0) + }) }) }) diff --git a/test/unit/lib/fakeElectron.js b/test/unit/lib/fakeElectron.js index a0df159f1d1..cab1903b6fd 100644 --- a/test/unit/lib/fakeElectron.js +++ b/test/unit/lib/fakeElectron.js @@ -17,7 +17,8 @@ const fakeElectron = { }, ipcRenderer: { on: function () { }, - send: function () { } + send: function () { }, + sendSync: function () { } }, remote: { app: {