2014-06-16 22:44:09 +01:00
|
|
|
// # Signin Test
|
|
|
|
// Test that signin works, including testing our spam prevention mechanisms
|
|
|
|
|
2014-09-03 17:42:55 +02:00
|
|
|
/*globals CasperTest, casper, url, user, falseUser */
|
2014-06-16 22:44:09 +01:00
|
|
|
|
2015-03-30 19:52:48 +02:00
|
|
|
CasperTest.begin('Ghost admin will load login page', 4, function suite(test) {
|
2014-07-17 14:22:32 +02:00
|
|
|
CasperTest.Routines.signout.run(test);
|
2014-06-16 22:44:09 +01:00
|
|
|
casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {
|
2014-11-25 12:56:08 -08:00
|
|
|
test.assertTitle('Sign In - Test Blog', 'Ghost admin has incorrect title');
|
2014-07-01 00:26:08 +01:00
|
|
|
test.assertUrlMatch(/ghost\/signin\/$/, 'We should be presented with the signin page.');
|
2014-06-16 22:44:09 +01:00
|
|
|
|
|
|
|
casper.then(function testLink() {
|
2015-03-30 19:52:48 +02:00
|
|
|
var text = this.evaluate(function (selector) {
|
|
|
|
return document.querySelector(selector).innerHTML;
|
|
|
|
}, '.forgotten-link');
|
2014-06-16 22:44:09 +01:00
|
|
|
|
2015-03-30 19:52:48 +02:00
|
|
|
casper.echoConcise('Text' + text);
|
2015-06-03 15:50:52 +01:00
|
|
|
test.assertExists('.forgotten-link', '.forgotten-link exists');
|
|
|
|
test.assertEquals(text, 'Forgot?', 'Forgotten text is correct');
|
2014-06-16 22:44:09 +01:00
|
|
|
});
|
|
|
|
});
|
2014-07-21 14:08:59 +01:00
|
|
|
}, true);
|
2014-06-16 22:44:09 +01:00
|
|
|
|
|
|
|
// Note, this test applies to a global redirect, which sends us to the standard admin.
|
|
|
|
// Once Ember becomes the standard admin, this test should still pass.
|
2014-06-26 14:06:38 +01:00
|
|
|
CasperTest.begin('Redirects login to signin', 2, function suite(test) {
|
2014-07-17 14:22:32 +02:00
|
|
|
CasperTest.Routines.signout.run(test);
|
2014-06-16 22:44:09 +01:00
|
|
|
casper.start(url + 'ghost/login/', function testRedirect(response) {
|
2015-06-03 15:50:52 +01:00
|
|
|
test.assertEquals(response.status, 200, 'Response status should be 200.');
|
2014-06-16 22:44:09 +01:00
|
|
|
test.assertUrlMatch(/ghost\/signin\//, 'Should be redirected to /signin/.');
|
|
|
|
});
|
2014-07-21 14:08:59 +01:00
|
|
|
}, true);
|
2014-07-17 14:22:07 +02:00
|
|
|
|
|
|
|
CasperTest.begin('Login limit is in place', 4, function suite(test) {
|
|
|
|
CasperTest.Routines.signout.run(test);
|
|
|
|
|
|
|
|
casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {
|
2014-11-25 12:56:08 -08:00
|
|
|
test.assertTitle('Sign In - Test Blog', 'Ghost admin has incorrect title');
|
2014-07-17 14:22:07 +02:00
|
|
|
test.assertUrlMatch(/ghost\/signin\/$/, 'Landed on the correct URL');
|
|
|
|
});
|
|
|
|
|
2015-05-19 14:21:39 +01:00
|
|
|
casper.waitForOpaque('.gh-signin',
|
2014-07-17 14:22:07 +02:00
|
|
|
function then() {
|
|
|
|
this.fillAndSave('#login', falseUser);
|
|
|
|
},
|
|
|
|
function onTimeout() {
|
|
|
|
test.fail('Sign in form didn\'t fade in.');
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.wait(2100, function doneWait() {
|
|
|
|
this.fillAndSave('#login', falseUser);
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.waitForText('remaining', function onSuccess() {
|
|
|
|
test.assert(true, 'The login limit is in place.');
|
|
|
|
test.assertSelectorDoesntHaveText('.notification-error', '[object Object]');
|
|
|
|
}, function onTimeout() {
|
|
|
|
test.assert(false, 'We did not trip the login limit.');
|
|
|
|
});
|
2014-07-21 14:08:59 +01:00
|
|
|
}, true);
|
2014-06-16 22:44:09 +01:00
|
|
|
|
2015-05-22 09:38:46 +01:00
|
|
|
CasperTest.begin('Can login to Ghost', 4, function suite(test) {
|
2014-07-17 14:22:07 +02:00
|
|
|
CasperTest.Routines.signout.run(test);
|
|
|
|
|
2014-06-16 22:44:09 +01:00
|
|
|
casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {
|
2014-11-25 12:56:08 -08:00
|
|
|
test.assertTitle('Sign In - Test Blog', 'Ghost admin has incorrect title');
|
2014-07-01 00:26:08 +01:00
|
|
|
test.assertUrlMatch(/ghost\/signin\/$/, 'Landed on the correct URL');
|
2014-06-16 22:44:09 +01:00
|
|
|
});
|
|
|
|
|
2015-05-19 14:21:39 +01:00
|
|
|
casper.waitForOpaque('.gh-signin', function then() {
|
2014-06-24 12:17:40 +01:00
|
|
|
this.fillAndSave('#login', user);
|
2014-06-16 22:44:09 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.wait(2000);
|
|
|
|
|
|
|
|
casper.waitForResource(/posts/, function testForDashboard() {
|
2014-07-01 00:26:08 +01:00
|
|
|
test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL');
|
2015-05-22 09:38:46 +01:00
|
|
|
test.assertExists('.gh-nav-main-content.active', 'Now we are on Content');
|
2014-06-16 22:44:09 +01:00
|
|
|
}, function onTimeOut() {
|
|
|
|
test.fail('Failed to signin');
|
|
|
|
});
|
2014-07-21 14:08:59 +01:00
|
|
|
}, true);
|
2014-06-16 22:44:09 +01:00
|
|
|
|
2015-05-22 09:38:46 +01:00
|
|
|
CasperTest.begin('Authenticated user is redirected', 6, function suite(test) {
|
2014-07-17 14:22:07 +02:00
|
|
|
CasperTest.Routines.signout.run(test);
|
|
|
|
|
2014-07-01 11:21:05 +02:00
|
|
|
casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {
|
2014-11-25 12:56:08 -08:00
|
|
|
test.assertTitle('Sign In - Test Blog', 'Ghost admin has incorrect title');
|
2014-07-01 11:21:05 +02:00
|
|
|
test.assertUrlMatch(/ghost\/signin\/$/, 'Landed on the correct URL');
|
|
|
|
});
|
|
|
|
|
2015-05-22 09:38:46 +01:00
|
|
|
casper.waitForOpaque('' +
|
|
|
|
'.gh-signin', function then() {
|
2014-07-01 11:21:05 +02:00
|
|
|
this.fillAndSave('#login', user);
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.wait(2000);
|
|
|
|
|
|
|
|
casper.waitForResource(/posts/, function testForDashboard() {
|
|
|
|
test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL');
|
2015-05-22 09:38:46 +01:00
|
|
|
test.assertExists('.gh-nav-main-content.active', 'Now we are on Content');
|
2014-07-01 11:21:05 +02:00
|
|
|
}, function onTimeOut() {
|
|
|
|
test.fail('Failed to signin');
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.thenOpenAndWaitForPageLoad('signin-authenticated', function testTitleAndUrl() {
|
|
|
|
test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL');
|
2015-05-22 09:38:46 +01:00
|
|
|
test.assertExists('.gh-nav-main-content.active', 'Now we are on Content');
|
2014-07-01 11:21:05 +02:00
|
|
|
}, function onTimeOut() {
|
|
|
|
test.fail('Failed to redirect');
|
|
|
|
});
|
2014-07-21 14:08:59 +01:00
|
|
|
}, true);
|
2014-07-01 11:21:05 +02:00
|
|
|
|
2014-07-17 14:22:07 +02:00
|
|
|
CasperTest.begin('Ensure email field form validation', 3, function suite(test) {
|
|
|
|
CasperTest.Routines.signout.run(test);
|
|
|
|
|
|
|
|
casper.thenOpenAndWaitForPageLoad('signin', function testTitleAndUrl() {
|
2014-11-25 12:56:08 -08:00
|
|
|
test.assertTitle('Sign In - Test Blog', 'Ghost admin has incorrect title');
|
2014-07-17 14:22:07 +02:00
|
|
|
test.assertUrlMatch(/ghost\/signin\/$/, 'Landed on the correct URL');
|
|
|
|
});
|
|
|
|
|
2015-05-22 09:38:46 +01:00
|
|
|
casper.waitForOpaque('.gh-signin',
|
2014-07-17 14:22:07 +02:00
|
|
|
function then() {
|
2015-05-22 09:38:46 +01:00
|
|
|
this.fillAndSave('form.gh-signin', {
|
2014-09-10 00:06:24 -04:00
|
|
|
identification: 'notanemail'
|
2014-07-17 14:22:07 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
function onTimeout() {
|
|
|
|
test.fail('Login form didn\'t fade in.');
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
|
2015-06-03 15:50:52 +01:00
|
|
|
test.assertSelectorHasText('.notification-error', 'Invalid Email', '.notification-error text is correct');
|
2014-07-17 14:22:07 +02:00
|
|
|
}, function onTimeout() {
|
|
|
|
test.fail('Email validation error did not appear');
|
|
|
|
}, 2000);
|
2014-09-10 00:06:24 -04:00
|
|
|
}, true);
|