mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
Merge pull request #4336 from ErisDS/reduce-tests
frontend functional tests -> frontend route tests
This commit is contained in:
commit
6f291fdb15
@ -633,12 +633,12 @@ var _ = require('lodash'),
|
||||
// Custom test runner for our Casper.js functional tests
|
||||
// This really ought to be refactored into a separate grunt task module
|
||||
grunt.registerTask('spawnCasperJS', function (target) {
|
||||
target = _.contains(['client', 'frontend', 'setup'], target) ? target + '/' : undefined;
|
||||
target = _.contains(['client', 'setup'], target) ? target + '/' : undefined;
|
||||
|
||||
var done = this.async(),
|
||||
options = ['host', 'noPort', 'port', 'email', 'password'],
|
||||
args = ['test']
|
||||
.concat(grunt.option('target') || target || ['client/', 'frontend/'])
|
||||
.concat(grunt.option('target') || target || ['client/'])
|
||||
.concat(['--includes=base.js', '--log-level=debug', '--port=2369']);
|
||||
|
||||
// Forward parameters from grunt to casperjs
|
||||
|
@ -1,24 +0,0 @@
|
||||
/**
|
||||
* Tests if RSS exists and is working
|
||||
*/
|
||||
/*globals CasperTest, casper, url */
|
||||
CasperTest.begin('Check post not found (404)', 2, function suite(test) {
|
||||
casper.thenOpen(url + 'asdf/', function (response) {
|
||||
test.assertEqual(response.status, 404, 'Response status should be 404.');
|
||||
test.assertSelectorHasText('.error-code', '404');
|
||||
});
|
||||
}, true);
|
||||
|
||||
CasperTest.begin('Check frontend route not found (404)', 2, function suite(test) {
|
||||
casper.thenOpen(url + 'asdf/asdf/', function (response) {
|
||||
test.assertEqual(response.status, 404, 'Response status should be 404.');
|
||||
test.assertSelectorHasText('.error-code', '404');
|
||||
});
|
||||
}, true);
|
||||
|
||||
CasperTest.begin('Check frontend tag route not found (404)', 2, function suite(test) {
|
||||
casper.thenOpen(url + 'tag/asdf/', function (response) {
|
||||
test.assertEqual(response.status, 404, 'Response status should be 404.');
|
||||
test.assertSelectorHasText('.error-code', '404');
|
||||
});
|
||||
}, true);
|
@ -1,66 +0,0 @@
|
||||
/**
|
||||
* Tests if RSS exists and is working
|
||||
*/
|
||||
/*globals url, CasperTest, casper */
|
||||
CasperTest.begin('Ensure that RSS is available', 11, function suite(test) {
|
||||
CasperTest.Routines.togglePermalinks.run('off');
|
||||
casper.thenOpen(url + 'rss/', function (response) {
|
||||
var content = this.getHTML(),
|
||||
siteTitle = '<title><![CDATA[Test Blog]]></title>',
|
||||
siteDescription = '<description><![CDATA[Thoughts, stories and ideas.]]></description>',
|
||||
siteUrl = '<link>http://127.0.0.1:2369/</link>',
|
||||
postTitle = '<![CDATA[Welcome to Ghost]]>',
|
||||
postStart = '<description><![CDATA[<p>You\'re live!',
|
||||
postEnd = 'you think :)</p>]]></description>',
|
||||
postLink = '<link>http://127.0.0.1:2369/welcome-to-ghost/</link>',
|
||||
postCreator = '<dc:creator><![CDATA[Test User]]>';
|
||||
|
||||
test.assertEqual(response.status, 200, 'Response status should be 200.');
|
||||
test.assert(content.indexOf('<rss') >= 0, 'Feed should contain <rss');
|
||||
test.assert(content.indexOf(siteTitle) >= 0, 'Feed should contain blog title.');
|
||||
test.assert(content.indexOf(siteDescription) >= 0, 'Feed should contain blog description.');
|
||||
test.assert(content.indexOf(siteUrl) >= 0, 'Feed should contain link to blog.');
|
||||
test.assert(content.indexOf(postTitle) >= 0, 'Feed should contain welcome post title.');
|
||||
test.assert(content.indexOf(postStart) >= 0, 'Feed should contain start of welcome post content.');
|
||||
test.assert(content.indexOf(postEnd) >= 0, 'Feed should contain end of welcome post content.');
|
||||
test.assert(content.indexOf(postLink) >= 0, 'Feed should have link to the welcome post.');
|
||||
test.assert(content.indexOf(postCreator) >= 0, 'Welcome post should have Test User as the creator.');
|
||||
test.assert(content.indexOf('</rss>') >= 0, 'Feed should contain </rss>');
|
||||
});
|
||||
}, false);
|
||||
|
||||
CasperTest.begin('Ensure that author element is not included. Only dc:creator', 3, function suite(test) {
|
||||
CasperTest.Routines.togglePermalinks.run('off');
|
||||
casper.thenOpen(url + 'rss/', function (response) {
|
||||
var content = this.getHTML(),
|
||||
author = '<author>',
|
||||
postCreator = '<dc:creator><![CDATA[Test User]]>';
|
||||
|
||||
test.assertEqual(response.status, 200, 'Response status should be 200.');
|
||||
test.assert(content.indexOf(author) < 0, 'Author element should not be included');
|
||||
test.assert(content.indexOf(postCreator) >= 0, 'Welcome post should have Test User as the creator.');
|
||||
});
|
||||
}, false);
|
||||
|
||||
CasperTest.begin('Ensures dated permalinks works with RSS', 2, function suite(test) {
|
||||
CasperTest.Routines.togglePermalinks.run('on');
|
||||
casper.thenOpen(url + 'rss/', function (response) {
|
||||
var content = this.getHTML(),
|
||||
today = new Date(),
|
||||
dd = ('0' + today.getDate()).slice(-2),
|
||||
mm = ('0' + (today.getMonth() + 1)).slice(-2),
|
||||
yyyy = today.getFullYear(),
|
||||
postLink = '/' + yyyy + '/' + mm + '/' + dd + '/welcome-to-ghost/';
|
||||
|
||||
test.assertEqual(response.status, 200, 'Response status should be 200.');
|
||||
test.assert(content.indexOf(postLink) >= 0, 'Feed should have dated permalink.');
|
||||
});
|
||||
CasperTest.Routines.togglePermalinks.run('off');
|
||||
}, false);
|
||||
|
||||
CasperTest.begin('Ensure that character set is UTF-8 for RSS feed', 1, function suite(test) {
|
||||
CasperTest.Routines.togglePermalinks.run('off');
|
||||
casper.thenOpen(url + 'rss/', function (response) {
|
||||
test.assertEqual(response.headers.get('Content-Type'), 'text/xml; charset=utf-8', 'Content type should include UTF-8 character set encoding.');
|
||||
});
|
||||
}, false);
|
@ -1,77 +0,0 @@
|
||||
/**
|
||||
* Tests the homepage
|
||||
*/
|
||||
|
||||
/*globals CasperTest, casper, url */
|
||||
CasperTest.begin('Home page loads', 3, function suite(test) {
|
||||
casper.start(url, function then() {
|
||||
test.assertTitle('Test Blog', 'The homepage should have a title and it should be "Test Blog"');
|
||||
test.assertExists('.content .post', 'There is at least one post on this page');
|
||||
test.assertSelectorHasText('.poweredby', 'Proudly published with Ghost');
|
||||
});
|
||||
}, true);
|
||||
|
||||
CasperTest.begin('Test helpers on homepage', 3, function suite(test) {
|
||||
casper.start(url, function then() {
|
||||
// body class
|
||||
test.assertExists('body.home-template', 'body_class outputs correct home-template class');
|
||||
// post class
|
||||
test.assertExists('article.post', 'post_class outputs correct post class');
|
||||
test.assertExists('article.tag-getting-started', 'post_class outputs correct tag class');
|
||||
});
|
||||
}, true);
|
||||
|
||||
CasperTest.begin('Test navigating to Post', 4, function suite(test) {
|
||||
casper.thenOpen(url, function then() {
|
||||
var lastPost = '.content article:last-of-type',
|
||||
lastPostLink = lastPost + ' .post-title a';
|
||||
|
||||
test.assertExists(lastPost, 'there is a last child on the page');
|
||||
test.assertSelectorHasText(lastPostLink, 'Welcome to Ghost', 'Is correct post');
|
||||
|
||||
casper.then(function testLink() {
|
||||
var link = this.evaluate(function (lastPostLink) {
|
||||
return document.querySelector(lastPostLink).getAttribute('href');
|
||||
}, lastPostLink);
|
||||
|
||||
test.assert(link === '/welcome-to-ghost/', 'Has correct link');
|
||||
});
|
||||
|
||||
casper.thenClick(lastPostLink);
|
||||
|
||||
casper.waitForResource(/welcome-to-ghost/).then(function (resource) {
|
||||
test.assert(resource.status === 200, 'resource got 200');
|
||||
});
|
||||
});
|
||||
}, true);
|
||||
|
||||
CasperTest.begin('Test navigating to Post with date permalink', 4, function suite(test) {
|
||||
CasperTest.Routines.togglePermalinks.run('on');
|
||||
casper.thenOpen(url, function then() {
|
||||
var lastPost = '.content article:last-of-type',
|
||||
lastPostLink = lastPost + ' .post-title a',
|
||||
today = new Date(),
|
||||
dd = ('0' + today.getDate()).slice(-2),
|
||||
mm = ('0' + (today.getMonth() + 1)).slice(-2),
|
||||
yyyy = today.getFullYear(),
|
||||
postLink = '/' + yyyy + '/' + mm + '/' + dd + '/welcome-to-ghost/';
|
||||
|
||||
test.assertExists(lastPost, 'there is a last child on the page');
|
||||
test.assertSelectorHasText(lastPostLink, 'Welcome to Ghost', 'Is correct post');
|
||||
|
||||
casper.then(function testLink() {
|
||||
var link = this.evaluate(function (lastPostLink) {
|
||||
return document.querySelector(lastPostLink).getAttribute('href');
|
||||
}, lastPostLink);
|
||||
|
||||
test.assert(link === postLink, 'Has correct link');
|
||||
});
|
||||
|
||||
casper.thenClick(lastPostLink);
|
||||
|
||||
casper.waitForResource(postLink).then(function (resource) {
|
||||
test.assert(resource.status === 200, 'resource got 200');
|
||||
});
|
||||
});
|
||||
CasperTest.Routines.togglePermalinks.run('off');
|
||||
}, false);
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Tests the default post page
|
||||
*/
|
||||
|
||||
/*globals CasperTest, casper, url */
|
||||
|
||||
// Tests when permalinks is set to date
|
||||
CasperTest.begin('Post page does not load as slug', 2, function suite(test) {
|
||||
CasperTest.Routines.togglePermalinks.run('on');
|
||||
casper.thenOpen(url + 'welcome-to-ghost', function then() {
|
||||
test.assertTitle('404 — Page Not Found', 'The post should return 404 page');
|
||||
test.assertElementCount('.content .post', 0, 'There is no post on this page');
|
||||
});
|
||||
CasperTest.Routines.togglePermalinks.run('off');
|
||||
}, false);
|
||||
|
||||
CasperTest.begin('Post page loads', 3, function suite(test) {
|
||||
casper.thenOpen(url + 'welcome-to-ghost', function then() {
|
||||
test.assertTitle('Welcome to Ghost', 'The post should have a title and it should be "Welcome to Ghost"');
|
||||
test.assertElementCount('.content .post', 1, 'There is exactly one post on this page');
|
||||
test.assertSelectorHasText('.poweredby', 'Proudly published with Ghost');
|
||||
});
|
||||
}, true);
|
||||
|
||||
CasperTest.begin('Test helpers on welcome post', 4, function suite(test) {
|
||||
casper.start(url + 'welcome-to-ghost', function then() {
|
||||
// body class
|
||||
test.assertExists('body.post-template', 'body_class outputs correct post-template class');
|
||||
test.assertExists('body.tag-getting-started', 'body_class outputs correct tag class');
|
||||
// post class
|
||||
test.assertExists('article.post', 'post_class outputs correct post class');
|
||||
test.assertExists('article.tag-getting-started', 'post_class outputs correct tag class');
|
||||
});
|
||||
}, true);
|
@ -1,10 +0,0 @@
|
||||
/**
|
||||
* Tests archive page routing
|
||||
*/
|
||||
|
||||
/*globals CasperTest, casper, url */
|
||||
CasperTest.begin('Redirects page 1 request', 1, function suite(test) {
|
||||
casper.thenOpen(url + 'page/1/', function then() {
|
||||
test.assertEqual(casper.getCurrentUrl().indexOf('page/'), -1, 'Should be redirected to "/".');
|
||||
});
|
||||
}, true);
|
File diff suppressed because it is too large
Load Diff
@ -21,6 +21,8 @@ var Promise = require('bluebird'),
|
||||
teardown,
|
||||
setup,
|
||||
doAuth,
|
||||
login,
|
||||
togglePermalinks,
|
||||
|
||||
initFixtures,
|
||||
initData,
|
||||
@ -462,7 +464,6 @@ setup = function setup() {
|
||||
doAuth = function doAuth() {
|
||||
var options = arguments,
|
||||
request = arguments[0],
|
||||
user = DataGenerator.forModel.users[0],
|
||||
fixtureOps;
|
||||
|
||||
// Remove request from this list
|
||||
@ -474,16 +475,52 @@ doAuth = function doAuth() {
|
||||
|
||||
fixtureOps = getFixtureOps(options);
|
||||
|
||||
return sequence(fixtureOps).then(function () {
|
||||
return login(request);
|
||||
});
|
||||
};
|
||||
|
||||
login = function login(request) {
|
||||
var user = DataGenerator.forModel.users[0];
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
return sequence(fixtureOps).then(function () {
|
||||
request.post('/ghost/api/v0.1/authentication/token/')
|
||||
.send({grant_type: 'password', username: user.email, password: user.password, client_id: 'ghost-admin'})
|
||||
request.post('/ghost/api/v0.1/authentication/token/')
|
||||
.send({grant_type: 'password', username: user.email, password: user.password, client_id: 'ghost-admin'})
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
resolve(res.body.access_token);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
togglePermalinks = function togglePermalinks(request, toggle) {
|
||||
var permalinkString = toggle === 'date' ? '/:year/:month/:day/:slug/' : '/:slug/';
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
doAuth(request).then(function (token) {
|
||||
request.put('/ghost/api/v0.1/settings/')
|
||||
.set('Authorization', 'Bearer ' + token)
|
||||
.send({settings: [
|
||||
{
|
||||
uuid: '75e994ae-490e-45e6-9207-0eab409c1c04',
|
||||
key: 'permalinks',
|
||||
value: permalinkString,
|
||||
type: 'blog',
|
||||
created_at: '2014-10-16T17:39:16.005Z',
|
||||
created_by: 1,
|
||||
updated_at: '2014-10-20T19:44:18.077Z',
|
||||
updated_by: 1
|
||||
}
|
||||
]})
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
resolve(res.body.access_token);
|
||||
resolve(res.body);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -499,6 +536,8 @@ module.exports = {
|
||||
teardown: teardown,
|
||||
setup: setup,
|
||||
doAuth: doAuth,
|
||||
login: login,
|
||||
togglePermalinks: togglePermalinks,
|
||||
|
||||
initFixtures: initFixtures,
|
||||
initData: initData,
|
||||
|
Loading…
Reference in New Issue
Block a user