add integration tests

This commit is contained in:
Julian Descottes 2017-01-08 16:09:03 +01:00
parent 76ae797a9e
commit d30f6a05d1
7 changed files with 396 additions and 18 deletions

View File

@ -32,8 +32,11 @@ module.exports = function(grunt) {
var stylePaths = require('./src/piskel-style-list.js').styles;
var piskelStyles = prefixPaths(stylePaths, "src/");
var casperTestPaths = require('./test/casperjs/TestSuite.js').tests;
var casperTests = prefixPaths(casperTestPaths, "test/casperjs/");
var drawingTestPaths = require('./test/casperjs/TestSuite.js').tests;
var drawingTests = prefixPaths(drawingTestPaths, "test/casperjs/");
var integrationTestPaths = require('./test/casperjs/integration/IntegrationSuite.js').tests;
var integrationTests = prefixPaths(integrationTestPaths, "test/casperjs/integration/");
var getConnectConfig = function (base, port, host) {
if (typeof base === 'string') {
@ -265,19 +268,36 @@ module.exports = function(grunt) {
},
casperjs : {
files : {
src: casperTests
},
options : {
casperjsOptions: [
'--baseUrl=http://' + hostname + ':' + PORT.TEST,
'--mode=?debug',
'--verbose=false',
'--log-level=info',
'--print-command=false',
'--print-file-paths=true',
]
drawing : {
files : {
src: drawingTests
},
options : {
casperjsOptions: [
'--baseUrl=http://' + hostname + ':' + PORT.TEST,
'--mode=?debug',
'--verbose=false',
'--log-level=info',
'--print-command=false',
'--print-file-paths=true',
]
}
},
integration : {
files : {
src: integrationTests
},
options : {
casperjsOptions: [
'--baseUrl=http://' + hostname + ':' + PORT.TEST,
'--mode=?debug',
'--verbose=false',
'--log-level=info',
'--print-command=false',
'--print-file-paths=true',
]
}
}
},
/**
@ -311,11 +331,14 @@ module.exports = function(grunt) {
grunt.registerTask('lint', ['jscs:js', 'leadingIndent:css', 'jshint']);
// Run unit-tests
grunt.registerTask('unit-test', ['karma']);
// Run linting, unit tests and drawing tests
grunt.registerTask('test', ['lint', 'unit-test', 'build-dev', 'connect:test', 'casperjs']);
// Run integration tests
grunt.registerTask('test-integration', ['build-dev', 'connect:test', 'casperjs:integration']);
// Run linting, unit tests, drawing tests and integration tests
grunt.registerTask('test', ['lint', 'unit-test', 'build-dev', 'connect:test', 'casperjs:drawing', 'casperjs:integration']);
// Run the tests, even if the linting fails
grunt.registerTask('test-nolint', ['unit-test', 'build-dev', 'connect:test', 'casperjs']);
grunt.registerTask('test-nolint', ['unit-test', 'build-dev', 'connect:test', 'casperjs:drawing', 'casperjs:integration']);
// Used by optional precommit hook
grunt.registerTask('precommit', ['test']);

View File

@ -61,7 +61,7 @@
<input type="text" class="textfield resize-size-field" autocomplete="off" name="default-height"/>
<span>px</span>
</div>
<input type="submit" class="button button-primary resize-button" value="Set default" />
<input type="submit" class="button button-primary default-size-button" value="Set default" />
</form>
</div>
</div>

View File

@ -0,0 +1,6 @@
(typeof exports != "undefined" ? exports : pskl_exports).tests = [
'settings/test-resize-default-size.js',
'settings/test-resize-input-synchronization.js',
'settings/test-resize.js',
'settings/test-settings-open-panels-on-click.js',
];

View File

@ -0,0 +1,74 @@
casper.test.begin('Test updating default size works', 14 , function(test) {
test.timeout = test.fail.bind(test, ['Test timed out']);
function getValue(selector) {
return casper.evaluate(
'function () { \
return document.querySelector(\'' + selector + '\').value;\
}');
};
function isDrawerExpanded() {
return casper.evaluate(function () {
var settingsElement = document.querySelector('[data-pskl-controller="settings"]');
return settingsElement.classList.contains('expanded');
});
}
function onTestStart() {
test.assertExists('#drawing-canvas-container canvas', 'Piskel ready, test starting');
test.assert(!isDrawerExpanded(), 'settings drawer is closed');
test.assertDoesntExist('.settings-section-resize', 'Check if resize settings drawer is closed');
// Open resize panel.
this.click('[data-setting="resize"]');
this.waitForSelector('.settings-section-resize', onResizePanelReady, test.timeout, 10000);
}
function onResizePanelReady() {
test.assert(isDrawerExpanded(), 'settings drawer is expanded');
test.assertExists('.settings-section-resize', 'Check if resize panel is opened');
testSetDefaultSize();
}
function testSetDefaultSize() {
test.assertExists('[name="default-width"]', 'Check if width input is available');
test.assertExists('[name="default-height"]', 'Check if height input is available');
test.assertEquals(getValue('[name="default-width"]'), "32", 'Default width is 32px');
test.assertEquals(getValue('[name="default-height"]'), "32", 'Default height is 32px');
// Update width/height
casper.sendKeys('[name="default-width"]', "1");
casper.sendKeys('[name="default-height"]', "2");
test.assertEquals(getValue('[name="default-width"]'), "321", 'Default width is 321px');
test.assertEquals(getValue('[name="default-height"]'), "322", 'Default height is 322px');
casper.click('.default-size-button');
// Changing the piskel default size should close the panel automatically
casper.waitForSelector('[data-pskl-controller="settings"]:not(.expanded)', onDrawerClosed, test.timeout, 10000);
}
function onDrawerClosed() {
test.assert(!isDrawerExpanded(), 'settings drawer is closed');
test.assertEquals(casper.evaluate(function () {
return pskl.UserSettings.get('DEFAULT_SIZE').width;
}), 321, 'Piskel width is now 321 pixels');
test.assertEquals(casper.evaluate(function () {
return pskl.UserSettings.get('DEFAULT_SIZE').height;
}), 322, 'Piskel default height is now 322 pixels');
}
casper
.start(casper.cli.get('baseUrl')+"/?debug")
.then(function () {
this.echo("URL loaded");
this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 10000);
})
.run(function () {
test.done();
});
});

View File

@ -0,0 +1,108 @@
casper.test.begin('Test resize panel width/height inputs are synchronized', 28 , function(test) {
test.timeout = test.fail.bind(test, ['Test timed out']);
function getValue(selector) {
return casper.evaluate(
'function () { \
return document.querySelector(\'' + selector + '\').value;\
}');
};
function isDrawerExpanded() {
return casper.evaluate(function () {
var settingsElement = document.querySelector('[data-pskl-controller="settings"]');
return settingsElement.classList.contains('expanded');
});
}
function onTestStart() {
test.assertExists('#drawing-canvas-container canvas', 'Piskel ready, test starting');
test.assert(!isDrawerExpanded(), 'settings drawer is closed');
test.assertDoesntExist('.settings-section-resize', 'Check if resize settings drawer is closed');
// Open resize panel.
this.click('[data-setting="resize"]');
this.waitForSelector('.settings-section-resize', onResizePanelReady, test.timeout, 10000);
}
function onResizePanelReady() {
test.assert(isDrawerExpanded(), 'settings drawer is expanded');
test.assertExists('.settings-section-resize', 'Check if resize panel is opened');
testInputSynchronization();
}
function testInputSynchronization() {
test.assertExists('[name="resize-width"]', 'Check if width input is available');
test.assertExists('[name="resize-height"]', 'Check if height input is available');
test.assertEquals(getValue('[name="resize-width"]'), "32", 'Resize width is 32px');
test.assertEquals(getValue('[name="resize-height"]'), "32", 'Resize height is 32px');
// Check that the resize ratio checkbox is available and checked.
test.assertExists('.resize-ratio-checkbox', 'Check if resize ratio checkbox is available');
test.assert(casper.evaluate(function () {
return document.querySelector('.resize-ratio-checkbox').checked;
}), 'Keep ratio checkbox is checked');
// Check inputs are synchronized
casper.sendKeys('[name="resize-width"]', casper.page.event.key.Backspace);
test.assertEquals(getValue('[name="resize-width"]'), "3", 'Resize width is 3px');
test.assertEquals(getValue('[name="resize-height"]'), "3", 'Resize height is 3px');
casper.sendKeys('[name="resize-width"]', "0");
test.assertEquals(getValue('[name="resize-width"]'), "30", 'Resize width is 30px');
test.assertEquals(getValue('[name="resize-height"]'), "30", 'Resize height is 30px');
// Check the synchronization also works when editing height field
casper.sendKeys('[name="resize-height"]', "0");
test.assertEquals(getValue('[name="resize-width"]'), "300", 'Resize width is 300px');
test.assertEquals(getValue('[name="resize-height"]'), "300", 'Resize height is 300px');
casper.sendKeys('[name="resize-height"]', casper.page.event.key.Backspace);
test.assertEquals(getValue('[name="resize-width"]'), "30", 'Resize width is 30px');
test.assertEquals(getValue('[name="resize-height"]'), "30", 'Resize height is 30px');
// Uncheck the resize ratio checkbox.
casper.click('.resize-ratio-checkbox');
// Check inputs are no longer synchronized
casper.sendKeys('[name="resize-width"]', casper.page.event.key.Backspace);
test.assertEquals(getValue('[name="resize-width"]'), "3", 'Resize width is 3px');
test.assertEquals(getValue('[name="resize-height"]'), "30", 'Resize height is 30px');
casper.sendKeys('[name="resize-width"]', "2");
test.assertEquals(getValue('[name="resize-width"]'), "32", 'Resize width is 32px');
test.assertEquals(getValue('[name="resize-height"]'), "30", 'Resize height is 30px');
casper.sendKeys('[name="resize-height"]', casper.page.event.key.Backspace);
test.assertEquals(getValue('[name="resize-width"]'), "32", 'Resize width is 32px');
test.assertEquals(getValue('[name="resize-height"]'), "3", 'Resize height is 3px');
casper.sendKeys('[name="resize-height"]', "2");
test.assertEquals(getValue('[name="resize-width"]'), "32", 'Resize width is 32px');
test.assertEquals(getValue('[name="resize-height"]'), "32", 'Resize height is 32px');
// Check the resize ratio checkbox again
casper.click('.resize-ratio-checkbox');
// Send ESCAPE to close the resize panel. (!!! does not work for some reason ...)
// casper.page.sendEvent('keydown', casper.page.event.key.Escape);
casper.click('[data-setting="resize"]');
casper.waitForSelector('[data-pskl-controller="settings"]:not(.expanded)', onDrawerClosed, test.timeout, 10000);
}
function onDrawerClosed() {
test.assert(!isDrawerExpanded(), 'settings drawer is closed');
}
casper
.start(casper.cli.get('baseUrl')+"/?debug")
.then(function () {
this.echo("URL loaded");
this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 10000);
})
.run(function () {
test.done();
});
});

View File

@ -0,0 +1,79 @@
casper.test.begin('Test resize feature works', 16 , function(test) {
test.timeout = test.fail.bind(test, ['Test timed out']);
function getValue(selector) {
return casper.evaluate(
'function () { \
return document.querySelector(\'' + selector + '\').value;\
}');
};
function isDrawerExpanded() {
return casper.evaluate(function () {
var settingsElement = document.querySelector('[data-pskl-controller="settings"]');
return settingsElement.classList.contains('expanded');
});
}
function onTestStart() {
test.assertExists('#drawing-canvas-container canvas', 'Piskel ready, test starting');
test.assert(!isDrawerExpanded(), 'settings drawer is closed');
test.assertDoesntExist('.settings-section-resize', 'Check if resize settings drawer is closed');
// Open resize panel.
this.click('[data-setting="resize"]');
this.waitForSelector('.settings-section-resize', onResizePanelReady, test.timeout, 10000);
}
function onResizePanelReady() {
test.assert(isDrawerExpanded(), 'settings drawer is expanded');
test.assertExists('.settings-section-resize', 'Check if resize panel is opened');
testResizePiskel();
}
function testResizePiskel() {
test.assertExists('[name="resize-width"]', 'Check if width input is available');
test.assertExists('[name="resize-height"]', 'Check if height input is available');
test.assertEquals(getValue('[name="resize-width"]'), "32", 'Resize width is 32px');
test.assertEquals(getValue('[name="resize-height"]'), "32", 'Resize height is 32px');
// Check that the resize ratio checkbox is available and checked.
test.assertExists('.resize-ratio-checkbox', 'Check if resize ratio checkbox is available');
test.assert(casper.evaluate(function () {
return document.querySelector('.resize-ratio-checkbox').checked;
}), 'Keep ratio checkbox is checked');
// Update width/height
casper.sendKeys('[name="resize-width"]', "0");
test.assertEquals(getValue('[name="resize-width"]'), "320", 'Resize width is 320px');
test.assertEquals(getValue('[name="resize-height"]'), "320", 'Resize height is 320px');
casper.click('.resize-button');
// Resizing the piskel should close the panel automatically
casper.waitForSelector('[data-pskl-controller="settings"]:not(.expanded)', onDrawerClosed, test.timeout, 10000);
}
function onDrawerClosed() {
test.assert(!isDrawerExpanded(), 'settings drawer is closed');
test.assertEquals(casper.evaluate(function () {
return pskl.app.piskelController.getPiskel().getWidth();
}), 320, 'Piskel width is now 320 pixels');
test.assertEquals(casper.evaluate(function () {
return pskl.app.piskelController.getPiskel().getHeight();
}), 320, 'Piskel height is now 320 pixels');
}
casper
.start(casper.cli.get('baseUrl')+"/?debug")
.then(function () {
this.echo("URL loaded");
this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 10000);
})
.run(function () {
test.done();
});
});

View File

@ -0,0 +1,88 @@
casper.test.begin('Settings Test', 18, function(test) {
test.timeout = test.fail.bind(test, ['Test timed out']);
function isDrawerExpanded() {
return casper.evaluate(function () {
var settingsElement = document.querySelector('[data-pskl-controller="settings"]');
return settingsElement.classList.contains('expanded');
});
}
function onTestStart() {
test.assertExists('#drawing-canvas-container canvas', 'Piskel ready, test starting');
test.assert(!isDrawerExpanded(), 'settings drawer is closed');
test.assertDoesntExist('.settings-section-resize', 'Check if resize settings drawer is closed');
// Open resize panel.
this.click('[data-setting="resize"]');
this.waitForSelector('.settings-section-resize', onResizePanelReady, test.timeout, 10000);
}
function onResizePanelReady() {
test.assert(isDrawerExpanded(), 'settings drawer is expanded');
test.assertExists('.settings-section-resize', 'Check if resize panel is opened');
// Open application settings panel.
test.assertDoesntExist('.settings-section-application', 'Check if application settings panel is closed');
this.click('[data-setting="user"]');
this.waitForSelector('.settings-section-application', onApplicationPanelReady, test.timeout, 10000);
}
function onApplicationPanelReady() {
test.assert(isDrawerExpanded(), 'settings drawer is expanded');
test.assertExists('.settings-section-application', 'Check if application settings panel is opened');
// Open save panel.
test.assertDoesntExist('.settings-section-save', 'Check if save panel is closed');
this.click('[data-setting="save"]');
this.waitForSelector('.settings-section-save', onSavePanelReady, test.timeout, 10000);
}
function onSavePanelReady() {
test.assert(isDrawerExpanded(), 'settings drawer is expanded');
test.assertExists('.settings-section-save', 'Check if save panel is opened');
// Open export panel.
test.assertDoesntExist('.settings-section-export', 'Check if export panel is closed');
this.click('[data-setting="export"]');
this.waitForSelector('.settings-section-export', onExportPanelReady, test.timeout, 10000);
}
function onExportPanelReady() {
test.assert(isDrawerExpanded(), 'settings drawer is expanded');
test.assertExists('.settings-section-export', 'Check if export panel is opened');
// Open import panel.
test.assertDoesntExist('.settings-section-import', 'Check if import panel is closed');
this.click('[data-setting="import"]');
this.waitForSelector('.settings-section-import', onImportPanelReady, test.timeout, 10000);
}
function onImportPanelReady() {
test.assert(isDrawerExpanded(), 'settings drawer is expanded');
test.assertExists('.settings-section-import', 'Check if import panel is opened');
// Click on import again to close the settings drawer.
this.click('[data-setting="import"]');
this.waitForSelector('[data-pskl-controller="settings"]:not(.expanded)', onDrawerClosed, test.timeout, 10000);
}
function onDrawerClosed() {
test.assert(!isDrawerExpanded(), 'settings drawer is closed');
}
casper
.start(casper.cli.get('baseUrl')+"/?debug")
.then(function () {
this.echo("URL loaded");
this.waitForSelector('#drawing-canvas-container canvas', onTestStart, test.timeout, 10000);
})
.run(function () {
test.done();
});
});