2014-07-01 03:26:08 +04:00
|
|
|
/*globals casper */
|
2013-07-31 11:33:28 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Casper Tests
|
|
|
|
*
|
|
|
|
* Functional browser tests for checking that the Ghost Admin UI is working as expected
|
|
|
|
* The setup of these tests is a little hacky for now, which is why they are not wired in to grunt
|
|
|
|
* Requires that you are running Ghost locally and have already registered a single user
|
|
|
|
*
|
|
|
|
* Usage (from test/functional):
|
|
|
|
*
|
2013-08-05 13:31:04 +04:00
|
|
|
* casperjs test admin/ --includes=base.js [--host=localhost --port=2368 --noPort=false --email=ghost@tryghost.org --password=Sl1m3r]
|
2013-07-31 11:33:28 +04:00
|
|
|
*
|
|
|
|
* --host - your local host address e.g. localhost or local.tryghost.org
|
|
|
|
* --port - port number of your local Ghost
|
|
|
|
* --email - the email address your admin user is registered with
|
|
|
|
* --password - the password your admin user is registered with
|
2013-08-05 13:31:04 +04:00
|
|
|
* --noPort - don't include a port number
|
2013-07-31 11:33:28 +04:00
|
|
|
*
|
|
|
|
* Requirements:
|
|
|
|
* you must have phantomjs 1.9.1 and casperjs 1.1.0-DEV installed in order for these tests to work
|
|
|
|
*/
|
|
|
|
|
2014-01-01 18:31:29 +04:00
|
|
|
var DEBUG = false, // TOGGLE THIS TO GET MORE SCREENSHOTS
|
|
|
|
host = casper.cli.options.host || 'localhost',
|
2013-08-05 13:31:04 +04:00
|
|
|
noPort = casper.cli.options.noPort || false,
|
2013-07-31 11:33:28 +04:00
|
|
|
port = casper.cli.options.port || '2368',
|
2013-11-24 18:29:36 +04:00
|
|
|
email = casper.cli.options.email || 'jbloggs@example.com',
|
2013-08-27 01:28:41 +04:00
|
|
|
password = casper.cli.options.password || 'Sl1m3rson',
|
2014-06-17 01:44:09 +04:00
|
|
|
url = 'http://' + host + (noPort ? '/' : ':' + port + '/'),
|
2013-09-12 12:59:58 +04:00
|
|
|
newUser = {
|
2014-06-17 01:44:09 +04:00
|
|
|
name: 'Test User',
|
2014-07-02 07:44:39 +04:00
|
|
|
slug: 'test-user',
|
2013-09-12 12:59:58 +04:00
|
|
|
email: email,
|
|
|
|
password: password
|
|
|
|
},
|
2014-06-25 16:12:48 +04:00
|
|
|
newSetup = {
|
|
|
|
'blog-title': 'Test Blog',
|
|
|
|
name: 'Test User',
|
|
|
|
email: email,
|
|
|
|
password: password
|
|
|
|
},
|
2013-07-31 11:33:28 +04:00
|
|
|
user = {
|
2014-06-30 16:58:10 +04:00
|
|
|
identification: email,
|
2013-07-31 11:33:28 +04:00
|
|
|
password: password
|
|
|
|
},
|
2013-08-22 23:48:36 +04:00
|
|
|
falseUser = {
|
2014-06-30 16:58:10 +04:00
|
|
|
identification: email,
|
2013-08-22 23:48:36 +04:00
|
|
|
password: 'letmethrough'
|
|
|
|
},
|
2013-08-05 13:31:04 +04:00
|
|
|
testPost = {
|
2014-06-17 01:44:09 +04:00
|
|
|
title: 'Bacon ipsum dolor sit amet',
|
|
|
|
html: 'I am a test post.\n#I have some small content'
|
2014-07-01 03:26:08 +04:00
|
|
|
},
|
|
|
|
screens;
|
|
|
|
|
|
|
|
screens = {
|
|
|
|
'root': {
|
|
|
|
url: 'ghost/',
|
|
|
|
linkSelector: '#main-menu > li.content a',
|
|
|
|
selector: '#main-menu .content.active'
|
|
|
|
},
|
|
|
|
'content': {
|
|
|
|
url: 'ghost/content/',
|
|
|
|
linkSelector: '#main-menu > li.content a',
|
|
|
|
selector: '#main-menu .content.active'
|
|
|
|
},
|
|
|
|
'editor': {
|
|
|
|
url: 'ghost/editor/',
|
|
|
|
linkSelector: '#main-menu > li.editor a',
|
|
|
|
selector: '#entry-title'
|
|
|
|
},
|
|
|
|
'settings': {
|
|
|
|
url: 'ghost/settings/',
|
|
|
|
linkSelector: '#main-menu > li.settings a',
|
|
|
|
selector: '.settings-content'
|
|
|
|
},
|
|
|
|
'settings.general': {
|
|
|
|
url: 'ghost/settings/general',
|
|
|
|
selector: '.settings-content .settings-general'
|
|
|
|
},
|
|
|
|
'settings.user': {
|
|
|
|
url: 'ghost/settings/user',
|
|
|
|
linkSelector: '#user-menu li.usermenu-profile a',
|
|
|
|
selector: '.settings-content .settings-user'
|
|
|
|
},
|
|
|
|
'signin': {
|
|
|
|
url: 'ghost/signin/',
|
|
|
|
selector: '.button-save'
|
|
|
|
},
|
2014-07-01 13:21:05 +04:00
|
|
|
'signin-authenticated': {
|
|
|
|
url: 'ghost/signin/',
|
|
|
|
//signin with authenticated user redirects to posts
|
2014-07-15 23:52:44 +04:00
|
|
|
selector: '#main-menu .content .active'
|
2014-07-01 13:21:05 +04:00
|
|
|
},
|
2014-07-01 03:26:08 +04:00
|
|
|
'signout': {
|
|
|
|
url: 'ghost/signout/',
|
2014-07-24 01:12:45 +04:00
|
|
|
linkSelector: '#user-menu li.usermenu-signout button',
|
2014-07-01 03:26:08 +04:00
|
|
|
// When no user exists we get redirected to setup which has button-add
|
|
|
|
selector: '.button-save, .button-add'
|
|
|
|
},
|
|
|
|
'signup': {
|
|
|
|
url: 'ghost/signup/',
|
|
|
|
selector: '.button-save'
|
|
|
|
},
|
|
|
|
'setup': {
|
|
|
|
url: 'ghost/setup/',
|
|
|
|
selector: '.button-add'
|
2014-07-01 14:57:44 +04:00
|
|
|
},
|
|
|
|
'setup-authenticated': {
|
|
|
|
url: 'ghost/setup/',
|
2014-07-15 23:52:44 +04:00
|
|
|
selector: '#main-menu .content a.active'
|
2014-07-01 03:26:08 +04:00
|
|
|
}
|
|
|
|
};
|
2013-07-31 11:33:28 +04:00
|
|
|
|
2013-08-05 13:31:04 +04:00
|
|
|
casper.writeContentToCodeMirror = function (content) {
|
2014-06-17 01:44:09 +04:00
|
|
|
var lines = content.split('\n');
|
2013-07-31 11:33:28 +04:00
|
|
|
|
2014-03-18 02:01:29 +04:00
|
|
|
casper.waitForSelector('.CodeMirror-wrap textarea', function onSuccess() {
|
|
|
|
casper.each(lines, function (self, line) {
|
|
|
|
self.sendKeys('.CodeMirror-wrap textarea', line, {keepFocus: true});
|
|
|
|
self.sendKeys('.CodeMirror-wrap textarea', casper.page.event.key.Enter, {keepFocus: true});
|
|
|
|
});
|
2013-08-05 13:31:04 +04:00
|
|
|
|
2014-03-18 02:01:29 +04:00
|
|
|
return this;
|
|
|
|
}, function onTimeout() {
|
|
|
|
casper.test.fail('CodeMirror was not found.');
|
|
|
|
}, 2000);
|
2013-08-05 13:31:04 +04:00
|
|
|
};
|
|
|
|
|
2014-06-23 21:23:46 +04:00
|
|
|
casper.waitForOpacity = function (classname, opacity, then, timeout) {
|
|
|
|
timeout = timeout || casper.failOnTimeout(casper.test, 'waitForOpacity failed on ' + classname + ' ' + opacity);
|
2014-06-23 12:27:07 +04:00
|
|
|
casper.waitForSelector(classname).then(function () {
|
|
|
|
casper.waitFor(function checkOpaque() {
|
2014-06-23 21:23:46 +04:00
|
|
|
var value = this.evaluate(function (element, opacity) {
|
2014-06-23 12:27:07 +04:00
|
|
|
var target = document.querySelector(element);
|
|
|
|
if (target === null) {
|
|
|
|
return null;
|
|
|
|
}
|
2014-06-23 21:23:46 +04:00
|
|
|
return window.getComputedStyle(target).getPropertyValue('opacity') === opacity;
|
|
|
|
}, classname, opacity);
|
2014-06-23 12:27:07 +04:00
|
|
|
if (value !== true && value !== false) {
|
|
|
|
casper.test.fail('Unable to find element: ' + classname);
|
2013-12-15 22:15:52 +04:00
|
|
|
}
|
2014-06-23 12:27:07 +04:00
|
|
|
return value;
|
|
|
|
}, then, timeout);
|
|
|
|
});
|
2013-09-12 12:59:58 +04:00
|
|
|
};
|
2013-08-30 13:50:42 +04:00
|
|
|
|
2014-06-23 21:23:46 +04:00
|
|
|
casper.waitForOpaque = function (classname, then, timeout) {
|
|
|
|
casper.waitForOpacity(classname, '1', then, timeout);
|
|
|
|
};
|
|
|
|
|
|
|
|
casper.waitForTransparent = function (classname, then, timeout) {
|
|
|
|
casper.waitForOpacity(classname, '0', then, timeout);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-17 01:44:09 +04:00
|
|
|
// ### Then Open And Wait For Page Load
|
|
|
|
// Always wait for the `#main` element as some indication that the ember app has loaded.
|
|
|
|
casper.thenOpenAndWaitForPageLoad = function (screen, then, timeout) {
|
|
|
|
then = then || function () {};
|
|
|
|
timeout = timeout || casper.failOnTimeout(casper.test, 'Unable to load ' + screen);
|
|
|
|
|
|
|
|
return casper.thenOpen(url + screens[screen].url).then(function () {
|
2014-06-23 12:27:07 +04:00
|
|
|
// Some screens fade in
|
|
|
|
return casper.waitForOpaque(screens[screen].selector, then, timeout, 10000);
|
2014-06-17 01:44:09 +04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-06-28 07:50:31 +04:00
|
|
|
casper.thenTransitionAndWaitForScreenLoad = function (screen, then, timeout) {
|
|
|
|
then = then || function () {};
|
|
|
|
timeout = timeout || casper.failOnTimeout(casper.test, 'Unable to load ' + screen);
|
|
|
|
|
|
|
|
return casper.thenClick(screens[screen].linkSelector).then(function () {
|
|
|
|
// Some screens fade in
|
|
|
|
return casper.waitForOpaque(screens[screen].selector, then, timeout, 10000);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-05-08 11:44:48 +04:00
|
|
|
casper.failOnTimeout = function (test, message) {
|
|
|
|
return function onTimeout() {
|
|
|
|
test.fail(message);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2014-06-17 01:44:09 +04:00
|
|
|
// ### Fill And Save
|
2014-06-25 16:12:48 +04:00
|
|
|
// With Ember in place, we don't want to submit forms, rather press the button which always has a class of
|
2014-06-17 01:44:09 +04:00
|
|
|
// 'button-save'. This method handles that smoothly.
|
|
|
|
casper.fillAndSave = function (selector, data) {
|
2014-06-24 15:17:40 +04:00
|
|
|
casper.then(function doFill() {
|
|
|
|
casper.fill(selector, data, false);
|
|
|
|
casper.thenClick('.button-save');
|
|
|
|
});
|
2014-06-17 01:44:09 +04:00
|
|
|
};
|
|
|
|
|
2014-06-25 16:12:48 +04:00
|
|
|
// ### Fill And Add
|
|
|
|
// With Ember in place, we don't want to submit forms, rather press the green button which always has a class of
|
|
|
|
// 'button-add'. This method handles that smoothly.
|
|
|
|
casper.fillAndAdd = function (selector, data) {
|
|
|
|
casper.then(function doFill() {
|
|
|
|
casper.fill(selector, data, false);
|
|
|
|
casper.thenClick('.button-add');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-06-21 17:56:30 +04:00
|
|
|
// ## Debugging
|
|
|
|
var jsErrors = [],
|
|
|
|
pageErrors = [],
|
|
|
|
resourceErrors = [];
|
|
|
|
|
2014-06-17 01:44:09 +04:00
|
|
|
// ## Echo Concise
|
|
|
|
// Does casper.echo but checks for the presence of the --concise flag
|
2014-06-18 00:53:56 +04:00
|
|
|
casper.echoConcise = function (message, style) {
|
|
|
|
if (!casper.cli.options.concise) {
|
|
|
|
casper.echo(message, style);
|
|
|
|
}
|
2014-06-17 01:44:09 +04:00
|
|
|
};
|
2014-06-18 00:53:56 +04:00
|
|
|
|
2014-06-21 17:56:30 +04:00
|
|
|
// pass through all console.logs
|
2013-08-30 13:50:42 +04:00
|
|
|
casper.on('remote.message', function (msg) {
|
2014-06-21 17:56:30 +04:00
|
|
|
casper.echoConcise('CONSOLE LOG: ' + msg, 'INFO');
|
2013-08-30 13:50:42 +04:00
|
|
|
});
|
|
|
|
|
2014-06-21 17:56:30 +04:00
|
|
|
// output any errors
|
|
|
|
casper.on('error', function (msg, trace) {
|
|
|
|
casper.echoConcise('ERROR, ' + msg, 'ERROR');
|
|
|
|
if (trace) {
|
|
|
|
casper.echoConcise('file: ' + trace[0].file, 'WARNING');
|
|
|
|
casper.echoConcise('line: ' + trace[0].line, 'WARNING');
|
|
|
|
casper.echoConcise('function: ' + trace[0]['function'], 'WARNING');
|
|
|
|
}
|
|
|
|
jsErrors.push(msg);
|
2013-08-30 13:50:42 +04:00
|
|
|
});
|
|
|
|
|
2014-06-21 17:56:30 +04:00
|
|
|
// output any page errors
|
|
|
|
casper.on('page.error', function (msg, trace) {
|
|
|
|
casper.echoConcise('PAGE ERROR: ' + msg, 'ERROR');
|
|
|
|
if (trace) {
|
|
|
|
casper.echoConcise('file: ' + trace[0].file, 'WARNING');
|
|
|
|
casper.echoConcise('line: ' + trace[0].line, 'WARNING');
|
|
|
|
casper.echoConcise('function: ' + trace[0]['function'], 'WARNING');
|
|
|
|
}
|
|
|
|
pageErrors.push(msg);
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.on('resource.received', function(resource) {
|
|
|
|
var status = resource.status;
|
|
|
|
if(status >= 400) {
|
|
|
|
casper.echoConcise('RESOURCE ERROR: ' + resource.url + ' failed to load (' + status + ')', 'ERROR');
|
|
|
|
|
|
|
|
resourceErrors.push({
|
|
|
|
url: resource.url,
|
|
|
|
status: resource.status
|
|
|
|
});
|
|
|
|
}
|
2013-08-30 13:50:42 +04:00
|
|
|
});
|
|
|
|
|
2014-01-01 18:31:29 +04:00
|
|
|
casper.captureScreenshot = function (filename, debugOnly) {
|
|
|
|
debugOnly = debugOnly !== false;
|
|
|
|
// If we are in debug mode, OR debugOnly is false
|
|
|
|
if (DEBUG || debugOnly === false) {
|
2014-06-17 01:44:09 +04:00
|
|
|
filename = filename || 'casper_test_fail.png';
|
2014-06-04 16:21:56 +04:00
|
|
|
casper.then(function () {
|
|
|
|
casper.capture(new Date().getTime() + '_' + filename);
|
|
|
|
});
|
2014-01-01 18:31:29 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-21 17:56:30 +04:00
|
|
|
// on failure, grab a screenshot
|
|
|
|
casper.test.on('fail', function captureFailure() {
|
2014-06-17 01:44:09 +04:00
|
|
|
casper.captureScreenshot(casper.test.filename || 'casper_test_fail.png', false);
|
|
|
|
casper.then(function () {
|
|
|
|
console.log(casper.getHTML());
|
|
|
|
casper.exit(1);
|
|
|
|
});
|
2013-10-08 05:39:33 +04:00
|
|
|
});
|
|
|
|
|
2014-06-21 17:56:30 +04:00
|
|
|
// on exit, output any errors
|
|
|
|
casper.test.on('exit', function() {
|
|
|
|
if (jsErrors.length > 0) {
|
|
|
|
casper.echo(jsErrors.length + ' Javascript errors found', 'WARNING');
|
|
|
|
} else {
|
|
|
|
casper.echo(jsErrors.length + ' Javascript errors found', 'INFO');
|
|
|
|
}
|
|
|
|
if (pageErrors.length > 0) {
|
|
|
|
casper.echo(pageErrors.length + ' Page errors found', 'WARNING');
|
|
|
|
} else {
|
|
|
|
casper.echo(pageErrors.length + ' Page errors found', 'INFO');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resourceErrors.length > 0) {
|
|
|
|
casper.echo(resourceErrors.length + ' Resource errors found', 'WARNING');
|
|
|
|
} else {
|
|
|
|
casper.echo(resourceErrors.length + ' Resource errors found', 'INFO');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-28 20:04:30 +04:00
|
|
|
var CasperTest = (function () {
|
2013-10-08 05:39:33 +04:00
|
|
|
|
|
|
|
var _beforeDoneHandler,
|
|
|
|
_noop = function noop() { },
|
|
|
|
_isUserRegistered = false;
|
|
|
|
|
|
|
|
// Always log out at end of test.
|
|
|
|
casper.test.tearDown(function (done) {
|
|
|
|
casper.then(_beforeDoneHandler);
|
|
|
|
|
2014-06-26 17:06:38 +04:00
|
|
|
CasperTest.Routines.signout.run();
|
2014-01-01 18:31:29 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
casper.run(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Wrapper around `casper.test.begin`
|
2014-06-26 17:06:38 +04:00
|
|
|
function begin(testName, expect, suite, doNotAutoLogin) {
|
2014-06-17 01:44:09 +04:00
|
|
|
_beforeDoneHandler = _noop;
|
|
|
|
|
|
|
|
var runTest = function (test) {
|
|
|
|
test.filename = testName.toLowerCase().replace(/ /g, '-').concat('.png');
|
|
|
|
|
|
|
|
casper.start('about:blank').viewport(1280, 1024);
|
|
|
|
|
|
|
|
if (!doNotAutoLogin) {
|
|
|
|
// Only call register once for the lifetime of CasperTest
|
|
|
|
if (!_isUserRegistered) {
|
|
|
|
|
2014-06-26 17:06:38 +04:00
|
|
|
CasperTest.Routines.signout.run();
|
|
|
|
CasperTest.Routines.setup.run();
|
2014-06-17 01:44:09 +04:00
|
|
|
|
|
|
|
_isUserRegistered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure we're logged out at the start of every test or we may get
|
|
|
|
unexpected failures. */
|
2014-06-26 17:06:38 +04:00
|
|
|
CasperTest.Routines.signout.run();
|
|
|
|
CasperTest.Routines.signin.run();
|
2014-06-17 01:44:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
suite.call(casper, test);
|
|
|
|
|
|
|
|
casper.run(function () {
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof expect === 'function') {
|
|
|
|
doNotAutoLogin = suite;
|
|
|
|
suite = expect;
|
|
|
|
|
|
|
|
casper.test.begin(testName, runTest);
|
|
|
|
} else {
|
|
|
|
casper.test.begin(testName, expect, runTest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
// Sets a handler to be invoked right before `test.done` is invoked
|
|
|
|
function beforeDone(fn) {
|
|
|
|
if (fn) {
|
|
|
|
_beforeDoneHandler = fn;
|
2013-10-28 20:04:30 +04:00
|
|
|
} else {
|
2013-10-08 05:39:33 +04:00
|
|
|
_beforeDoneHandler = _noop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
begin: begin,
|
|
|
|
beforeDone: beforeDone
|
|
|
|
};
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
CasperTest.Routines = (function () {
|
|
|
|
|
2014-06-26 17:06:38 +04:00
|
|
|
function setup() {
|
2014-06-25 16:12:48 +04:00
|
|
|
casper.thenOpenAndWaitForPageLoad('setup', function then() {
|
2014-07-01 03:26:08 +04:00
|
|
|
casper.captureScreenshot('setting_up1.png');
|
2014-06-17 01:44:09 +04:00
|
|
|
|
2014-06-25 16:12:48 +04:00
|
|
|
casper.waitForOpaque('.setup-box', function then() {
|
|
|
|
this.fillAndAdd('#setup', newSetup);
|
2014-06-17 01:44:09 +04:00
|
|
|
});
|
|
|
|
|
2014-07-01 03:26:08 +04:00
|
|
|
casper.captureScreenshot('setting_up2.png');
|
2014-06-17 01:44:09 +04:00
|
|
|
|
|
|
|
casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
|
|
|
|
var errorText = casper.evaluate(function () {
|
|
|
|
return document.querySelector('.notification-error').innerText;
|
|
|
|
});
|
2014-07-15 23:52:44 +04:00
|
|
|
casper.echoConcise('Setup failed. Error text: ' + errorText);
|
2014-06-17 01:44:09 +04:00
|
|
|
}, function onTimeout() {
|
2014-07-15 23:52:44 +04:00
|
|
|
casper.echoConcise('Setup completed.');
|
2014-06-17 01:44:09 +04:00
|
|
|
}, 2000);
|
|
|
|
|
2014-07-01 03:26:08 +04:00
|
|
|
casper.captureScreenshot('setting_up3.png');
|
2014-06-17 01:44:09 +04:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:06:38 +04:00
|
|
|
function signin() {
|
2014-06-17 01:44:09 +04:00
|
|
|
casper.thenOpenAndWaitForPageLoad('signin', function then() {
|
|
|
|
|
|
|
|
casper.waitForOpaque('.login-box', function then() {
|
2014-07-01 03:26:08 +04:00
|
|
|
casper.captureScreenshot('signing_in.png');
|
2014-06-17 01:44:09 +04:00
|
|
|
this.fillAndSave('#login', user);
|
2014-07-01 03:26:08 +04:00
|
|
|
casper.captureScreenshot('signing_in2.png');
|
2014-06-17 01:44:09 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.waitForResource(/posts\/\?status=all&staticPages=all/, function then() {
|
2014-07-01 03:26:08 +04:00
|
|
|
casper.captureScreenshot('signing_in.png');
|
2014-06-17 01:44:09 +04:00
|
|
|
}, function timeout() {
|
|
|
|
casper.test.fail('Unable to signin and load admin panel');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-26 17:06:38 +04:00
|
|
|
function signout() {
|
2014-06-17 01:44:09 +04:00
|
|
|
casper.thenOpenAndWaitForPageLoad('signout', function then() {
|
|
|
|
casper.captureScreenshot('ember_signing_out.png');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will need switching over to ember once settings general is working properly.
|
2014-01-01 15:17:35 +04:00
|
|
|
function togglePermalinks(state) {
|
2014-06-26 17:06:38 +04:00
|
|
|
casper.thenOpenAndWaitForPageLoad('settings.general', function then() {
|
2014-01-01 15:17:35 +04:00
|
|
|
var currentState = this.evaluate(function () {
|
|
|
|
return document.querySelector('#permalinks') && document.querySelector('#permalinks').checked ? 'on' : 'off';
|
2013-12-30 11:03:29 +04:00
|
|
|
});
|
2014-01-01 15:17:35 +04:00
|
|
|
if (currentState !== state) {
|
|
|
|
casper.thenClick('#permalinks');
|
|
|
|
casper.thenClick('.button-save');
|
2014-01-01 18:31:29 +04:00
|
|
|
|
2014-06-17 01:44:09 +04:00
|
|
|
casper.captureScreenshot('saving.png');
|
2014-01-01 18:31:29 +04:00
|
|
|
|
|
|
|
casper.waitForSelector('.notification-success', function () {
|
2014-06-17 01:44:09 +04:00
|
|
|
casper.captureScreenshot('saved.png');
|
2014-01-01 15:17:35 +04:00
|
|
|
});
|
|
|
|
}
|
2013-12-30 11:03:29 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-17 01:44:09 +04:00
|
|
|
function createTestPost(publish) {
|
|
|
|
casper.thenOpenAndWaitForPageLoad('editor', function createTestPost() {
|
|
|
|
casper.sendKeys('#entry-title', testPost.title);
|
|
|
|
casper.writeContentToCodeMirror(testPost.html);
|
|
|
|
casper.sendKeys('#entry-tags input.tag-input', 'TestTag');
|
|
|
|
casper.sendKeys('#entry-tags input.tag-input', casper.page.event.key.Enter);
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.waitForSelectorTextChange('.entry-preview .rendered-markdown');
|
|
|
|
|
|
|
|
if (publish) {
|
|
|
|
// Open the publish options menu;
|
|
|
|
casper.thenClick('.js-publish-splitbutton .options.up');
|
|
|
|
|
|
|
|
casper.waitForOpaque('.js-publish-splitbutton .open');
|
|
|
|
|
|
|
|
// Select the publish post button
|
|
|
|
casper.thenClick('.js-publish-splitbutton li:first-child a');
|
|
|
|
|
|
|
|
casper.waitForSelectorTextChange('.js-publish-button', function onSuccess() {
|
|
|
|
casper.thenClick('.js-publish-button');
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
casper.thenClick('.js-publish-button');
|
|
|
|
}
|
|
|
|
|
2014-06-27 06:35:25 +04:00
|
|
|
casper.waitForResource(/posts\/\?include=tags$/);
|
2014-06-17 01:44:09 +04:00
|
|
|
}
|
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
function _createRunner(fn) {
|
|
|
|
fn.run = function run(test) {
|
|
|
|
var routine = this;
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
routine.call(casper, test);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2014-06-26 17:06:38 +04:00
|
|
|
setup: _createRunner(setup),
|
|
|
|
signin: _createRunner(signin),
|
|
|
|
signout: _createRunner(signout),
|
2014-07-01 03:26:08 +04:00
|
|
|
createTestPost: _createRunner(createTestPost),
|
|
|
|
togglePermalinks: _createRunner(togglePermalinks)
|
2013-10-08 05:39:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}());
|