2017-07-20 06:57:48 -05:00
|
|
|
const Application = require('./spectronSetup');
|
2018-02-18 23:27:15 -06:00
|
|
|
const { isMac } = require('../../js/utils/misc');
|
2018-03-13 05:20:32 -05:00
|
|
|
const robot = require('robotjs');
|
2018-02-18 23:27:15 -06:00
|
|
|
|
2017-07-11 09:51:47 -05:00
|
|
|
let configPath;
|
|
|
|
|
|
|
|
let app = new Application({});
|
|
|
|
|
|
|
|
describe('Tests for Zoom in and Zoom out', () => {
|
|
|
|
|
|
|
|
let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
2018-03-13 05:20:32 -05:00
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut();
|
2017-07-11 09:51:47 -05:00
|
|
|
|
|
|
|
beforeAll((done) => {
|
2018-03-13 05:20:32 -05:00
|
|
|
return app.startApplication().then((startedApp) => {
|
|
|
|
app = startedApp;
|
|
|
|
getConfigPath().then((config) => {
|
|
|
|
configPath = config;
|
2018-02-18 23:27:15 -06:00
|
|
|
done();
|
2018-03-13 05:20:32 -05:00
|
|
|
}).catch((err) => {
|
|
|
|
done.fail(new Error(`Unable to start application error: ${err}`));
|
2017-07-11 09:51:47 -05:00
|
|
|
});
|
2018-03-13 05:20:32 -05:00
|
|
|
}).catch((err) => {
|
|
|
|
done.fail(new Error(`Unable to start application error: ${err}`));
|
2017-07-11 09:51:47 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function getConfigPath() {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
app.client.addCommand('getUserDataPath', function () {
|
|
|
|
return this.execute(function () {
|
|
|
|
return require('electron').remote.app.getPath('userData');
|
|
|
|
})
|
|
|
|
});
|
2018-02-18 23:27:15 -06:00
|
|
|
app.client.getUserDataPath().then((userConfigPath) => {
|
|
|
|
resolve(userConfigPath.value)
|
2017-07-11 09:51:47 -05:00
|
|
|
}).catch((err) => {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
afterAll((done) => {
|
|
|
|
if (app && app.isRunning()) {
|
|
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
|
|
app.client.getWindowCount().then((count) => {
|
|
|
|
if (count > 0) {
|
|
|
|
app.stop().then(() => {
|
|
|
|
done();
|
|
|
|
}).catch((err) => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should launch the app', (done) => {
|
|
|
|
return app.client.waitUntilWindowLoaded().then(() => {
|
|
|
|
return app.client.getWindowCount().then((count) => {
|
|
|
|
expect(count === 1).toBeTruthy();
|
|
|
|
done();
|
|
|
|
}).catch((err) => {
|
2018-03-13 05:20:32 -05:00
|
|
|
done.fail(new Error(`zoom-in-zoom-out failed in getWindowCount with error: ${err}`));
|
2017-07-11 09:51:47 -05:00
|
|
|
});
|
|
|
|
}).catch((err) => {
|
2018-03-13 05:20:32 -05:00
|
|
|
done.fail(new Error(`zoom-in-zoom-out failed in waitUntilWindowLoaded with error: ${err}`));
|
2017-07-11 09:51:47 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-13 05:20:32 -05:00
|
|
|
it('should check window count', (done) => {
|
2017-07-11 09:51:47 -05:00
|
|
|
return app.client.getWindowCount().then((count) => {
|
|
|
|
expect(count === 1).toBeTruthy();
|
2018-03-13 05:20:32 -05:00
|
|
|
done();
|
2017-07-11 09:51:47 -05:00
|
|
|
}).catch((err) => {
|
2018-03-13 05:20:32 -05:00
|
|
|
done.fail(new Error(`zoom-in-zoom-out failed in waitUntilWindowLoaded with error: ${err}`));
|
2017-07-11 09:51:47 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-13 05:20:32 -05:00
|
|
|
it('should check browser window visibility', (done) => {
|
2017-07-11 09:51:47 -05:00
|
|
|
return app.browserWindow.isVisible().then((isVisible) => {
|
|
|
|
expect(isVisible).toBeTruthy();
|
2018-03-13 05:20:32 -05:00
|
|
|
done();
|
2017-07-11 09:51:47 -05:00
|
|
|
}).catch((err) => {
|
2018-03-13 05:20:32 -05:00
|
|
|
done.fail(new Error(`zoom-in-zoom-out failed in isVisible with error: ${err}`));
|
2017-07-11 09:51:47 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should bring the app to top', () => {
|
|
|
|
app.browserWindow.focus();
|
|
|
|
return app.browserWindow.setAlwaysOnTop(true).then(() => {
|
|
|
|
return app.browserWindow.isAlwaysOnTop().then((isOnTop) => {
|
|
|
|
expect(isOnTop).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-13 05:20:32 -05:00
|
|
|
it('should zoom in the app and check whether it is zoomed in', (done) => {
|
2017-07-11 09:51:47 -05:00
|
|
|
robot.setKeyboardDelay(500);
|
|
|
|
if (isMac) {
|
|
|
|
|
|
|
|
robot.keyToggle('0', 'down', ['command']);
|
|
|
|
robot.keyToggle('0', 'up');
|
|
|
|
robot.keyToggle('command', 'up');
|
|
|
|
|
2017-08-24 02:51:02 -05:00
|
|
|
for (let i = 0; i < 4; i++) {
|
2017-07-11 09:51:47 -05:00
|
|
|
robot.keyToggle('+', 'down', ['command']);
|
|
|
|
}
|
|
|
|
robot.keyToggle('+', 'up');
|
|
|
|
robot.keyToggle('command', 'up');
|
|
|
|
|
|
|
|
return app.electron.webFrame.getZoomFactor().then((zoomFactor) => {
|
|
|
|
expect(zoomFactor > 1).toBeTruthy();
|
2018-03-13 05:20:32 -05:00
|
|
|
done();
|
2017-07-11 09:51:47 -05:00
|
|
|
}).catch((err) => {
|
2018-03-13 05:20:32 -05:00
|
|
|
done.fail(new Error(`zoom-in-zoom-out failed in getZoomFactor with error: ${err}`));
|
2017-07-11 09:51:47 -05:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return app.browserWindow.getBounds().then((bounds) => {
|
|
|
|
robot.setMouseDelay(100);
|
|
|
|
let x = bounds.x + 200;
|
|
|
|
let y = bounds.y + 200;
|
|
|
|
robot.moveMouseSmooth(x, y);
|
|
|
|
robot.mouseClick();
|
|
|
|
|
|
|
|
robot.keyToggle('0', 'down', ['control']);
|
|
|
|
robot.keyToggle('0', 'up');
|
|
|
|
robot.keyToggle('control', 'up');
|
|
|
|
|
2017-08-24 02:51:02 -05:00
|
|
|
for (let i = 0; i < 4; i++) {
|
2017-07-11 09:51:47 -05:00
|
|
|
robot.keyToggle('+', 'down', ['control', 'shift']);
|
|
|
|
}
|
|
|
|
robot.keyToggle('+', 'up');
|
|
|
|
robot.keyToggle('control', 'up');
|
|
|
|
robot.keyToggle('shift', 'up');
|
|
|
|
|
|
|
|
return app.electron.webFrame.getZoomFactor().then((zoomFactor) => {
|
|
|
|
expect(zoomFactor > 1).toBeTruthy();
|
2018-03-13 05:20:32 -05:00
|
|
|
done();
|
2017-07-11 09:51:47 -05:00
|
|
|
}).catch((err) => {
|
2018-03-13 05:20:32 -05:00
|
|
|
done.fail(new Error(`zoom-in-zoom-out failed in getBounds with error: ${err}`));
|
2017-07-11 09:51:47 -05:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should zoom out the app and check whether it is zoomed out', () => {
|
|
|
|
robot.setKeyboardDelay(500);
|
|
|
|
if (isMac) {
|
|
|
|
|
|
|
|
robot.keyToggle('0', 'down', ['command']);
|
|
|
|
robot.keyToggle('0', 'up');
|
|
|
|
robot.keyToggle('command', 'up');
|
|
|
|
|
2017-08-24 02:51:02 -05:00
|
|
|
for (let i = 0; i < 4; i++) {
|
2017-07-11 09:51:47 -05:00
|
|
|
robot.keyToggle('-', 'down', ['command']);
|
|
|
|
}
|
|
|
|
robot.keyToggle('-', 'up');
|
|
|
|
robot.keyToggle('command', 'up');
|
|
|
|
|
|
|
|
return app.electron.webFrame.getZoomFactor().then((zoomFactor) => {
|
|
|
|
|
|
|
|
expect(zoomFactor < 1).toBeTruthy();
|
|
|
|
}).catch((err) => {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return app.browserWindow.getBounds().then((bounds) => {
|
|
|
|
robot.setMouseDelay(100);
|
|
|
|
let x = bounds.x + 200;
|
|
|
|
let y = bounds.y + 200;
|
|
|
|
robot.moveMouseSmooth(x, y);
|
|
|
|
robot.mouseClick();
|
|
|
|
|
|
|
|
robot.keyToggle('0', 'down', ['control']);
|
|
|
|
robot.keyToggle('0', 'up');
|
|
|
|
robot.keyToggle('control', 'up');
|
|
|
|
|
2017-08-24 02:51:02 -05:00
|
|
|
for (let i = 0; i < 4; i++) {
|
2017-07-11 09:51:47 -05:00
|
|
|
robot.keyToggle('-', 'down', ['control']);
|
|
|
|
}
|
|
|
|
robot.keyToggle('-', 'up');
|
|
|
|
robot.keyToggle('control', 'up');
|
|
|
|
|
|
|
|
return app.electron.webFrame.getZoomFactor().then((zoomFactor) => {
|
|
|
|
expect(zoomFactor < 1).toBeTruthy();
|
|
|
|
}).catch((err) => {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2018-03-13 05:20:32 -05:00
|
|
|
});
|