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

Commit

Permalink
Fixes frame tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Apr 23, 2017
1 parent 8d65e15 commit cd44019
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
18 changes: 14 additions & 4 deletions app/renderer/components/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,33 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const ImmutableComponent = require('./immutableComponent')
const {StyleSheet, css} = require('aphrodite')

// Components
const ReduxComponent = require('./reduxComponent')
const Dialog = require('../../../js/components/dialog')
const Button = require('../../../js/components/button')
const SwitchControl = require('../../../js/components/switchControl')

// Actions
const appActions = require('../../../js/actions/appActions')

// Constants
const KeyCodes = require('../../common/constants/keyCodes')
const config = require('../../../js/constants/config')
const {makeImmutable} = require('../../common/state/immutableUtil')

// State
const tabState = require('../../common/state/tabState')
const tabMessageBoxState = require('../../common/state/tabMessageBoxState')

const {StyleSheet, css} = require('aphrodite')
// Utils
const {makeImmutable} = require('../../common/state/immutableUtil')

// Styles
const commonStyles = require('./styles/commonStyles')
const globalStyles = require('./styles/global')

class MessageBox extends ImmutableComponent {
class MessageBox extends React.Component {
constructor () {
super()
this.onKeyDown = this.onKeyDown.bind(this)
Expand Down
9 changes: 5 additions & 4 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
const React = require('react')
const Immutable = require('immutable')
const ipc = require('electron').ipcRenderer
const ImmutableComponent = require('../../app/renderer/components/immutableComponent')
const ReduxComponent = require('../../app/renderer/components/reduxComponent')

// Actions
const appActions = require('../actions/appActions')
Expand All @@ -15,12 +13,15 @@ const webviewActions = require('../actions/webviewActions')
const getSetting = require('../settings').getSetting

// Components
const ReduxComponent = require('../../app/renderer/components/reduxComponent')
const FullScreenWarning = require('../../app/renderer/components/fullScreenWarning')
const MessageBox = require('../../app/renderer/components/messageBox')

// State
// Store
const windowStore = require('../stores/windowStore')
const appStoreRenderer = require('../stores/appStoreRenderer')

// State
const siteSettings = require('../state/siteSettings')
const siteSettingsState = require('../../app/common/state/siteSettingsState')
const tabState = require('../../app/common/state/tabState')
Expand Down Expand Up @@ -65,7 +66,7 @@ function isTorrentViewerURL (url) {
return isEnabled && isSourceMagnetUrl(url)
}

class Frame extends ImmutableComponent {
class Frame extends React.Component {
constructor () {
super()
this.onCloseFrame = this.onCloseFrame.bind(this)
Expand Down
4 changes: 4 additions & 0 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class WindowStore extends EventEmitter {
return windowState
}

set state (newWindowState) {
windowState = newWindowState
}

getFrames () {
return frameStateUtil.getFrames(this.state)
}
Expand Down
47 changes: 41 additions & 6 deletions test/unit/js/components/frameTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,43 @@
/* global describe, before, after, it */

const mockery = require('mockery')
const {shallow} = require('enzyme')
const {mount} = require('enzyme')
const sinon = require('sinon')
const assert = require('assert')
let Frame
const Immutable = require('immutable')
let Frame, windowStore
require('../../braveUnit')

const tabId = 1
const frameKey = 0

const fakeAppStoreRenderer = {
state: Immutable.fromJS({
windows: [{
windowId: 1,
windowUUID: 'uuid'
}],
tabs: [{
tabId: tabId,
windowId: 1,
windowUUID: 'uuid',
url: 'https://brave.com'
}]
})
}

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

describe('Frame component unit tests', function () {
const fakeWindowActions = {
frameShortcutChanged: () => {},
Expand All @@ -30,16 +61,19 @@ describe('Frame component unit tests', function () {
mockery.registerMock('../../extensions/brave/img/caret_down_grey.svg', 'caret_down_grey.svg')
mockery.registerMock('electron', require('../../lib/fakeElectron'))
mockery.registerMock('../actions/windowActions', fakeWindowActions)
mockery.registerMock('../stores/appStoreRenderer', fakeAppStoreRenderer)
Frame = require('../../../../js/components/frame')
windowStore = require('../../../../js/stores/windowStore')
})

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

const expectCall = (shortcut, expectedCall, expectedArgs) => {
const wrapper = shallow(
<Frame activeShortcut={shortcut} />
windowStore.state = defaultWindowStore.setIn(['frames', 0, 'activeShortcut'], shortcut)
const wrapper = mount(
<Frame frameKey={frameKey} />
)
const instance = wrapper.instance()
const expectedCallSpy = sinon.spy(instance, expectedCall)
Expand All @@ -53,8 +87,9 @@ describe('Frame component unit tests', function () {
}

const expectWindowActionCall = (shortcut, expectedCall, expectNoCalls) => {
const wrapper = shallow(
<Frame activeShortcut={shortcut} />
windowStore.state = defaultWindowStore.setIn(['frames', 0, 'activeShortcut'], shortcut)
const wrapper = mount(
<Frame frameKey={frameKey} />
)
const instance = wrapper.instance()
const expectedCallSpy = sinon.spy(fakeWindowActions, expectedCall)
Expand Down

0 comments on commit cd44019

Please sign in to comment.