2021-03-28 11:54:27 -08:00
|
|
|
// eslint-disable-next-line eslint-comments/disable-enable-pair
|
|
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
2018-03-02 12:11:33 -09:00
|
|
|
import test from 'ava';
|
2020-07-13 05:05:34 -08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2018-03-02 12:11:33 -09:00
|
|
|
const proxyquire = require('proxyquire').noCallThru();
|
|
|
|
|
|
2020-03-25 02:15:08 -08:00
|
|
|
test('positionIsValid() returns true when window is on only screen', (t) => {
|
2018-03-02 12:11:33 -09:00
|
|
|
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) => {
|
2018-03-02 12:11:33 -09:00
|
|
|
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) => {
|
2018-03-02 12:11:33 -09:00
|
|
|
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);
|
|
|
|
|
});
|