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

Commit

Permalink
Updated unit tests for argument parsing for window creation; fixed bu…
Browse files Browse the repository at this point in the history
…g w/ height

Auditors: @petemill

Test Plan: `npm run unittest -- --grep="APP_NEW_WINDOW"`
  • Loading branch information
bsclifton authored and petemill committed Nov 22, 2017
1 parent 8cf0919 commit ca54c13
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 52 deletions.
2 changes: 1 addition & 1 deletion app/browser/reducers/windowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const setWindowDimensions = (browserOpts, defaults, immutableWindowState) => {
const windowInfoState = immutableWindowState.get('windowInfo')
if (windowInfoState) {
browserOpts.width = firstDefinedValue(browserOpts.width, windowInfoState.get('width'))
browserOpts.height = firstDefinedValue(browserOpts.height, windowInfoState.get('windowInfo'))
browserOpts.height = firstDefinedValue(browserOpts.height, windowInfoState.get('height'))
} else {
browserOpts.width = firstDefinedValue(browserOpts.width, browserOpts.innerWidth, defaults.width)
// height and innerHeight are the frame webview size
Expand Down
177 changes: 126 additions & 51 deletions test/unit/app/browser/reducers/windowsReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,63 +115,138 @@ describe('windowsReducer unit test', function () {
assert.deepEqual(fakeDisplay.workAreaSize, { width, height })
})

it('allows a window size to be exactly specified', function () {
const expectedDimensions = { width: 600, outerHeight: 700 }
const action = {
actionType: appConstants.APP_NEW_WINDOW,
browserOpts: Object.assign({}, expectedDimensions)
}
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'width', expectedDimensions.width)
assert.propertyVal(windowOptions, 'height', expectedDimensions.outerHeight)
})
describe('when specifying window size', function () {
const exampleDimensions = { width: 600, height: 700 }

it('allows a window size to be specified, ignoring navBar height', function () {
const expectedDimensions = { width: 600, height: 700 }
const action = {
actionType: appConstants.APP_NEW_WINDOW,
browserOpts: Object.assign({}, expectedDimensions)
}
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
// width should be exact
assert.propertyVal(windowOptions, 'width', expectedDimensions.width)
// height should have 'navBar' added on to it
assert.isAbove(windowOptions.height, expectedDimensions.height)
// but should not be larger than screen height
assert.isBelow(windowOptions.height, new FakeElectronDisplay().workAreaSize.height)
})
it('allows a window size to be exactly specified', function () {
const expectedDimensions = { width: exampleDimensions.width, outerHeight: exampleDimensions.height }
const action = {
actionType: appConstants.APP_NEW_WINDOW,
browserOpts: Object.assign({}, expectedDimensions)
}
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'width', expectedDimensions.width)
assert.propertyVal(windowOptions, 'height', expectedDimensions.outerHeight)
})

it('positions the window by the mouse cursor when asked', function () {
const expectedPosition = fakeElectron.screen.getCursorScreenPoint()
const action = {
actionType: appConstants.APP_NEW_WINDOW,
browserOpts: { positionByMouseCursor: true }
}
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'x', expectedPosition.x)
assert.propertyVal(windowOptions, 'y', expectedPosition.y)
it('allows a window size to be specified, ignoring navBar height', function () {
const action = {
actionType: appConstants.APP_NEW_WINDOW,
browserOpts: Object.assign({}, exampleDimensions)
}
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
// width should be exact
assert.propertyVal(windowOptions, 'width', exampleDimensions.width)
// height should have 'navBar' added on to it
assert.isAbove(windowOptions.height, exampleDimensions.height)
// but should not be larger than screen height
assert.isBelow(windowOptions.height, new FakeElectronDisplay().workAreaSize.height)
})

it('allows size to be specified via `restoredState`', function () {
const action = {
actionType: appConstants.APP_NEW_WINDOW,
restoredState: {
windowInfo: exampleDimensions
}
}
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'width', exampleDimensions.width)
assert.propertyVal(windowOptions, 'height', exampleDimensions.height)
})

it('falls back to the defaults if size is not provided', function () {
const stateWithDefault = state.mergeIn(['defaultWindowParams'], exampleDimensions)
const action = {
actionType: appConstants.APP_NEW_WINDOW
}
windowsReducer(stateWithDefault, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'width', exampleDimensions.width)
assert.propertyVal(windowOptions, 'height', exampleDimensions.height)
})

it('falls back to the deprecated defaults if no other size is provided', function () {
const stateWithDefault = state
.set('defaultWindowWidth', exampleDimensions.width)
.set('defaultWindowHeight', exampleDimensions.height)
const action = {
actionType: appConstants.APP_NEW_WINDOW
}
windowsReducer(stateWithDefault, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'width', exampleDimensions.width)
assert.propertyVal(windowOptions, 'height', exampleDimensions.height)
})
})

it('positions the window to an exact point when asked', function () {
describe('when specifying the window position', function () {
const expectedPosition = { x: 500, y: 600 }
const action = {
actionType: appConstants.APP_NEW_WINDOW,
browserOpts: {
x: expectedPosition.x,
y: expectedPosition.y

it('positions the window by the mouse cursor when asked', function () {
const expectedPosition = fakeElectron.screen.getCursorScreenPoint()
const action = {
actionType: appConstants.APP_NEW_WINDOW,
browserOpts: { positionByMouseCursor: true }
}
}
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'x', expectedPosition.x)
assert.propertyVal(windowOptions, 'y', expectedPosition.y)
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'x', expectedPosition.x)
assert.propertyVal(windowOptions, 'y', expectedPosition.y)
})

it('positions the window to an exact point when asked', function () {
const action = {
actionType: appConstants.APP_NEW_WINDOW,
browserOpts: {
x: expectedPosition.x,
y: expectedPosition.y
}
}
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'x', expectedPosition.x)
assert.propertyVal(windowOptions, 'y', expectedPosition.y)
})

it('allows size to be specified via `restoredState`', function () {
const action = {
actionType: appConstants.APP_NEW_WINDOW,
restoredState: {
windowInfo: {
left: expectedPosition.x,
top: expectedPosition.y
}
}
}
windowsReducer(state, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'x', expectedPosition.x)
assert.propertyVal(windowOptions, 'y', expectedPosition.y)
})

it('falls back to the defaults if size is not provided', function () {
const stateWithDefault = state.mergeIn(['defaultWindowParams'], expectedPosition)
const action = {
actionType: appConstants.APP_NEW_WINDOW
}
windowsReducer(stateWithDefault, action)
fakeTimers.tick(0)
const windowOptions = spy.args[0][0]
assert.propertyVal(windowOptions, 'x', expectedPosition.x)
assert.propertyVal(windowOptions, 'y', expectedPosition.y)
})
})

it('restores a maximized window', function () {
Expand Down

0 comments on commit ca54c13

Please sign in to comment.