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

Commit

Permalink
unit test fixes after reworking active tab code (no longer using acti…
Browse files Browse the repository at this point in the history
…veKey)

Auditor: @bridiver
  • Loading branch information
bsclifton authored and bridiver committed May 25, 2017
1 parent 0391096 commit 1a76ade
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 231 deletions.
25 changes: 25 additions & 0 deletions test/unit/app/browser/reducers/tabsReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ describe('tabsReducer', function () {
pinned: false,
windowId: 2,
active: true
}, {
tabId: 4,
pinned: false,
windowId: 2,
active: false
}],
tabsInternal: {
index: {
1: 0,
2: 1,
3: 2,
4: 3
}
},
windows: [{
windowId: 1,
windowUUID: 'uuid'
}, {
windowId: 2,
windowUUID: 'uuid2'
}]
})
mockery.registerMock('electron', fakeElectron)
Expand All @@ -47,8 +67,13 @@ describe('tabsReducer', function () {
moveTo: sinon.mock()
}

this.windowsAPI = {
closeWindow: sinon.mock()
}

mockery.registerMock('tabs', this.tabsAPI)
mockery.registerMock('../tabs', this.tabsAPI)
mockery.registerMock('../windows', this.windowsAPI)
tabsReducer = require('../../../../../app/browser/reducers/tabsReducer')
})

Expand Down
18 changes: 12 additions & 6 deletions test/unit/app/common/state/basicAuthStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ const sampleAppState = {
index: {}
}
}

sampleAppState.tabsInternal.index[defaultTabId] = 0

const defaultAppState = Immutable.fromJS(sampleAppState)

const defaultTab = Immutable.fromJS({
tabId: defaultTabId,
index: 0,
windowId: 1,
windowUUID: 'uuid',
loginRequiredDetail: {
Expand Down Expand Up @@ -51,7 +53,11 @@ describe('basicAuthState unit tests', function () {

describe('`tabId` exists in appState with no loginRequiredDetail', function () {
before(function () {
this.appState = defaultAppState.set('tabs', Immutable.fromJS([{ tabId: defaultTabId }]))
this.appState = defaultAppState.set('tabs', Immutable.fromJS([{
tabId: defaultTabId,
index: 0,
windowId: 1
}]))
this.appState = basicAuthState.setLoginResponseDetail(this.appState, {tabId: defaultTabId,
detail: {
username: 'username',
Expand Down Expand Up @@ -113,11 +119,11 @@ describe('basicAuthState unit tests', function () {

describe('`tabId` exists in appState', function () {
before(function () {
this.appState = defaultAppState.set('tabs', Immutable.fromJS([
{
tabId: defaultTabId
}
]))
this.appState = defaultAppState.set('tabs', Immutable.fromJS([{
tabId: defaultTabId,
index: 0,
windowId: 1
}]))
this.appState = basicAuthState.setLoginRequiredDetail(this.appState, {tabId: defaultTabId,
detail: {
request: { url: 'someurl' },
Expand Down
2 changes: 2 additions & 0 deletions test/unit/app/common/state/tabMessageBoxStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const sampleAppState = {
index: {}
}
}

sampleAppState.tabsInternal.index[defaultTabId] = 0

const defaultAppState = Immutable.fromJS(sampleAppState)
Expand All @@ -32,6 +33,7 @@ const exampleMessageBox = Immutable.fromJS({

const defaultTab = Immutable.fromJS({
tabId: defaultTabId,
index: 0,
windowId: 1,
windowUUID: 'uuid',
url: 'https://brave.com',
Expand Down
74 changes: 43 additions & 31 deletions test/unit/app/common/state/tabStateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ const AssertionError = require('assert').AssertionError
const defaultAppState = Immutable.fromJS({
tabs: [],
windows: [],
otherProp: true
otherProp: true,
tabsInternal: {
index: {
1: 0,
2: 1
}
}
})

const twoTabsAppState = defaultAppState
.set('tabs', Immutable.fromJS([
{ tabId: 1, windowId: 1, frameKey: 2 },
{ tabId: 2, windowId: 1, frameKey: 1 }
{ tabId: 1, index: 0, windowId: 1, frameKey: 2 },
{ tabId: 2, index: 1, windowId: 1, frameKey: 1 }
]))
.set('tabsInternal', Immutable.fromJS({
index: {
1: 0,
2: 1
}
}))

// NOTE: null check can be optional since resolveTabId sets a default if null
const shouldValidateId = function (cb, skipNullCheck) {
Expand Down Expand Up @@ -124,7 +124,7 @@ const shouldValidateTabValue = function (cb) {
it('throws an AssertionError if `tabValue` does not contain a valid `tabId`', function () {
assert.doesNotThrow(
() => {
cb({ tabId: 1 })
cb({ tabId: 1, index: 0, windowId: 1 })
},
AssertionError
)
Expand All @@ -147,8 +147,8 @@ const shouldValidateAction = function (cb) {
it('throws an AssertionError if action does not contain a `tabValue` that is convertable to an Immutable.Map', function () {
assert.doesNotThrow(
() => {
cb(Immutable.fromJS({ tabValue: { tabId: 1 } }))
cb({ tabValue: { tabId: 1 } })
cb(Immutable.fromJS({ tabValue: { tabId: 1, index: 0, windowId: 1 } }))
cb({ tabValue: { tabId: 1, index: 0, windowId: 1 } })
},
AssertionError
)
Expand All @@ -169,7 +169,7 @@ const shouldValidateAction = function (cb) {
it('throws an AssertionError if `action` is not convertable to an Immutable.Map', function () {
assert.doesNotThrow(
() => {
cb({ tabValue: { tabId: 1 } })
cb({ tabValue: { tabId: 1, index: 0, windowId: 1 } })
},
AssertionError
)
Expand Down Expand Up @@ -295,20 +295,20 @@ describe('tabState unit tests', function () {
describe('insertTab', function () {
before(function () {
this.appState = defaultAppState
.set('tabs', Immutable.fromJS([ { tabId: 1 } ]))
.set('tabsInternal', Immutable.fromJS({ index: { 1: 0 } }))
.set('tabs', Immutable.fromJS([ { tabId: 1, index: 0, windowId: 1 } ]))
.set('tabsInternal', Immutable.fromJS({index: { 1: 0 }}))
})

it('returns a new immutable state with the tabValue appended to the end of the list', function () {
assert.deepEqual(
tabState.insertTab(this.appState, { tabValue: { tabId: 2 } }).get('tabs').toJS(),
[{ tabId: 1 }, { tabId: 2 }])
tabState.insertTab(this.appState, { tabValue: { tabId: 2, index: 1, windowId: 1 } }).get('tabs').toJS(),
[{ tabId: 1, index: 0, windowId: 1 }, { tabId: 2, index: 1, windowId: 1 }])
})

it('throws an AssertionError if there is already a tab with the tabId', function () {
assert.throws(
() => {
tabState.insertTab(this.appState, { tabValue: { tabId: 1 } })
tabState.insertTab(this.appState, { tabValue: { tabId: 1, index: 0, windowId: 1 } })
},
AssertionError
)
Expand All @@ -323,7 +323,7 @@ describe('tabState unit tests', function () {
})

shouldValidateTabState((state) => {
tabState.insertTab(state, { tabValue: { tabId: 1 } })
tabState.insertTab(state, { tabValue: { tabId: 1, index: 0, windowId: 1 } })
})
})

Expand All @@ -335,19 +335,24 @@ describe('tabState unit tests', function () {
windowId: 1,
frameKey: 1,
tabId: 1,
index: 0,
myProp: 'test1',
myProp2: 'blah'
},
{
windowId: 1,
frameKey: 1,
tabId: 2,
index: 1,
myProp: 'test2',
myProp2: 'blah'
}
]))
.set('tabsInternal', Immutable.fromJS({
index: { 1: 0, 2: 1 }
index: {
1: 0,
2: 1
}
}))
})

Expand All @@ -356,6 +361,7 @@ describe('tabState unit tests', function () {
tabState.updateTab(this.appState, { tabValue: { tabId: 1, test: 'blue', myProp: 'test2' } }).get('tabs').toJS(), [
{
tabId: 1,
index: 0,
test: 'blue',
windowId: 1,
frameKey: 1,
Expand All @@ -366,6 +372,7 @@ describe('tabState unit tests', function () {
windowId: 1,
frameKey: 1,
tabId: 2,
index: 1,
myProp: 'test2',
myProp2: 'blah'
}
Expand All @@ -374,16 +381,19 @@ describe('tabState unit tests', function () {

it('returns a new immutable state with the tabValue replaced if it already exists and `replace` is true', function () {
assert.deepEqual(
tabState.updateTab(this.appState, { replace: true, tabValue: { tabId: 1, test: 'blue', myProp: 'test2' } }).get('tabs').toJS(), [
tabState.updateTab(this.appState, { replace: true, tabValue: { tabId: 1, index: 0, windowId: 1, test: 'blue', myProp: 'test2' } }).get('tabs').toJS(), [
{
tabId: 1,
index: 0,
windowId: 1,
test: 'blue',
myProp: 'test2'
},
{
windowId: 1,
frameKey: 1,
tabId: 2,
index: 1,
myProp: 'test2',
myProp2: 'blah'
}
Expand Down Expand Up @@ -471,23 +481,21 @@ describe('tabState unit tests', function () {
before(function () {
this.appState = defaultAppState
.set('tabs', Immutable.fromJS([
{ tabId: 1 }
{ tabId: 1, index: 0, windowId: 1 }
]))
.set('tabsInternal', Immutable.fromJS({
index: { 1: 0 }
}))
.setIn(['tabsInternal', 'index', 1], 0)
})

it('returns a new immutable state with the tabValue appended to the end of the list if it does not already exist', function () {
assert.deepEqual(
tabState.maybeCreateTab(this.appState, { tabValue: { tabId: 2 } }).get('tabs').toJS(),
[{ tabId: 1 }, { tabId: 2 }])
tabState.maybeCreateTab(this.appState, { tabValue: { tabId: 2, index: 1, windowId: 1 } }).get('tabs').toJS(),
[{ tabId: 1, index: 0, windowId: 1 }, { tabId: 2, index: 1, windowId: 1 }])
})

it('returns a new immutable state with the tabValue updated if it already exists', function () {
assert.deepEqual(
tabState.maybeCreateTab(this.appState, { tabValue: { tabId: 1, test: 'blue' } }).get('tabs').toJS(),
[{ tabId: 1, test: 'blue' }])
tabState.maybeCreateTab(this.appState, { tabValue: { tabId: 1, index: 0, windowId: 1, test: 'blue' } }).get('tabs').toJS(),
[{ tabId: 1, index: 0, windowId: 1, test: 'blue' }])
})

shouldValidateAction((action) => {
Expand All @@ -499,7 +507,7 @@ describe('tabState unit tests', function () {
})

shouldValidateTabState((state) => {
tabState.maybeCreateTab(state, { tabValue: { tabId: 1 } })
tabState.maybeCreateTab(state, { tabValue: { tabId: 1, index: 0, windowId: 1 } })
})
})

Expand Down Expand Up @@ -658,7 +666,11 @@ describe('tabState unit tests', function () {
{ tabId: 3, prop2: 'test4' }
]))
.set('tabsInternal', Immutable.fromJS({
index: { 1: 0, 2: 1, 3: 2 }
index: {
1: 0,
2: 1,
3: 2
}
}))
})

Expand Down
Loading

0 comments on commit 1a76ade

Please sign in to comment.