hyper/test/unit/window-utils.test.ts

89 lines
1.9 KiB
TypeScript
Raw Normal View History

import test from 'ava';
const proxyquire = require('proxyquire').noCallThru();
2020-03-25 02:15:08 -08:00
test('positionIsValid() returns true when window is on only screen', (t) => {
const position = [50, 50];
const windowUtils = proxyquire('../../app/utils/window-utils', {
electron: {
screen: {
getAllDisplays: () => {
return [
{
workArea: {
x: 0,
y: 0,
width: 500,
height: 500
}
}
];
}
}
}
});
const result = windowUtils.positionIsValid(position);
t.true(result);
});
2020-03-25 02:15:08 -08:00
test('positionIsValid() returns true when window is on second screen', (t) => {
const position = [750, 50];
const windowUtils = proxyquire('../../app/utils/window-utils', {
electron: {
screen: {
getAllDisplays: () => {
return [
{
workArea: {
x: 0,
y: 0,
width: 500,
height: 500
}
},
{
workArea: {
x: 500,
y: 0,
width: 500,
height: 500
}
}
];
}
}
}
});
const result = windowUtils.positionIsValid(position);
t.true(result);
});
2020-03-25 02:15:08 -08:00
test('positionIsValid() returns false when position isnt valid', (t) => {
const primaryDisplay = {
workArea: {
x: 0,
y: 0,
width: 500,
height: 500
}
};
const position = [600, 50];
const windowUtils = proxyquire('../../app/utils/window-utils', {
electron: {
screen: {
getAllDisplays: () => {
return [primaryDisplay];
},
getPrimaryDisplay: () => primaryDisplay
}
}
});
const result = windowUtils.positionIsValid(position);
t.false(result);
});