Skip to content

Commit

Permalink
Merge pull request #10 from mateusmedeiros/state-valid-if-fullscreen-…
Browse files Browse the repository at this point in the history
…or-maximized

Consider a state without bounds still valid if fullscreen of maximized
  • Loading branch information
mawie81 committed Aug 23, 2016
2 parents a98cf0d + 8b03536 commit 57ac4b8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module.exports = function (options) {
}

function validateState() {
var isValid = state && hasBounds();
if (isValid && state.displayBounds) {
var isValid = state && (hasBounds() || state.isMaximized || state.isFullScreen);
if (hasBounds() && state.displayBounds) {
// Check if the display where the window was last open is still available
var displayBounds = screen.getDisplayMatching(state).bounds;
isValid = deepEqual(state.displayBounds, displayBounds, {strict: true});
Expand Down
46 changes: 46 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,52 @@ test('tries to read state file from the configured source', t => {
jsonfile.readFileSync.restore();
});

test('considers the state invalid if without bounds', t => {
const jsonfile = require('jsonfile');
sinon.stub(jsonfile, 'readFileSync').returns({
width: 100
});

const state = require('./')({
defaultWidth: 200
});

t.not(state.width, 100);
jsonfile.readFileSync.restore();
});

test('considers the state valid if without bounds but isMaximized is true', t => {
const jsonfile = require('jsonfile');
sinon.stub(jsonfile, 'readFileSync').returns({
isMaximized: true,
width: 100
});

const state = require('./')({
defaultWidth: 200
});

t.true(state.isMaximized);
t.is(state.width, 100);
jsonfile.readFileSync.restore();
});

test('considers the state valid if without bounds but isFullScreen is true', t => {
const jsonfile = require('jsonfile');
sinon.stub(jsonfile, 'readFileSync').returns({
isFullScreen: true,
width: 100
});

const state = require('./')({
defaultWidth: 200
});

t.true(state.isFullScreen);
t.is(state.width, 100);
jsonfile.readFileSync.restore();
});

test('returns the defaults if the state in the file is invalid', t => {
const jsonfile = require('jsonfile');
sinon.stub(jsonfile, 'readFileSync').returns({});
Expand Down

0 comments on commit 57ac4b8

Please sign in to comment.