2017-01-08 22:38:12 +03:00
|
|
|
/* globals casper */
|
|
|
|
|
2017-01-08 20:15:04 +03:00
|
|
|
/**
|
|
|
|
* Collection of shared methods for casperjs integration tests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function evalLine(line) {
|
|
|
|
return casper.evaluate(
|
|
|
|
'function () {return ' + line + '}'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getValue(selector) {
|
|
|
|
return casper.evaluate(
|
|
|
|
'function () { \
|
|
|
|
return document.querySelector(\'' + selector + '\').value;\
|
|
|
|
}');
|
|
|
|
}
|
|
|
|
|
|
|
|
function isChecked(selector) {
|
|
|
|
return casper.evaluate(
|
|
|
|
'function () { \
|
|
|
|
return document.querySelector(\'' + selector + '\').checked;\
|
|
|
|
}');
|
|
|
|
}
|
|
|
|
|
2017-01-08 22:38:12 +03:00
|
|
|
function setPiskelFromGrid(grid) {
|
|
|
|
casper.evaluate(
|
|
|
|
'function () {\
|
|
|
|
var B = "#000000", T = Constants.TRANSPARENT_COLOR;\
|
|
|
|
var frame = pskl.model.Frame.fromPixelGrid(' + grid + ');\
|
|
|
|
var layer = pskl.model.Layer.fromFrames("l1", [frame]);\
|
|
|
|
var piskel = pskl.model.Piskel.fromLayers([layer], 12, {name : "test", description : ""});\
|
|
|
|
pskl.app.piskelController.setPiskel(piskel);\
|
|
|
|
}');
|
|
|
|
}
|
|
|
|
|
|
|
|
function piskelFrameEqualsGrid(grid, layer, frame) {
|
|
|
|
return casper.evaluate(
|
|
|
|
'function () {\
|
|
|
|
var B = "#000000", T = Constants.TRANSPARENT_COLOR;\
|
|
|
|
var piskel = pskl.app.piskelController.getPiskel();\
|
|
|
|
var frame = piskel.getLayerAt(' + layer +').getFrameAt(' + frame + ');\
|
|
|
|
var grid = ' + grid +';\
|
|
|
|
var isValid = true;\
|
|
|
|
frame.forEachPixel(function (color, col, row) {\
|
|
|
|
isValid = isValid && pskl.utils.colorToInt(color) === pskl.utils.colorToInt(grid[row][col]);\
|
|
|
|
});\
|
|
|
|
return isValid;\
|
|
|
|
}');
|
|
|
|
}
|
|
|
|
|
2017-01-08 20:15:04 +03:00
|
|
|
function isDrawerExpanded() {
|
|
|
|
return casper.evaluate(function () {
|
|
|
|
var settingsElement = document.querySelector('[data-pskl-controller="settings"]');
|
|
|
|
return settingsElement.classList.contains('expanded');
|
|
|
|
});
|
|
|
|
}
|