2013-07-31 11:33:28 +04:00
|
|
|
/*globals casper, __utils__, url */
|
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
CasperTest.begin("Settings screen is correct", 15, function suite(test) {
|
|
|
|
casper.thenOpen(url + "ghost/settings/", function testTitleAndUrl() {
|
2013-09-28 18:21:59 +04:00
|
|
|
test.assertTitle("Ghost Admin", "Ghost admin has no title");
|
2013-09-15 15:13:06 +04:00
|
|
|
test.assertUrlMatch(/ghost\/settings\/general\/$/, "Ghost doesn't require login this time");
|
2013-10-08 05:39:33 +04:00
|
|
|
});
|
2013-07-31 11:33:28 +04:00
|
|
|
|
|
|
|
casper.then(function testViews() {
|
|
|
|
test.assertExists(".wrapper", "Settings main view is present");
|
2013-08-02 02:33:06 +04:00
|
|
|
test.assertExists(".settings-sidebar", "Settings sidebar view is present");
|
|
|
|
test.assertExists(".settings-menu", "Settings menu is present");
|
|
|
|
test.assertExists(".wrapper", "Settings main view is present");
|
|
|
|
test.assertExists(".settings-content", "Settings content view is present");
|
|
|
|
test.assertEval(function testGeneralIsActive() {
|
|
|
|
return document.querySelector('.settings-menu .general').classList.contains('active');
|
|
|
|
}, "general tab is marked active");
|
|
|
|
test.assertEval(function testContentIsGeneral() {
|
|
|
|
return document.querySelector('.settings-content').id === 'general';
|
|
|
|
}, "loaded content is general screen");
|
|
|
|
});
|
2013-07-31 11:33:28 +04:00
|
|
|
|
2013-08-21 14:50:49 +04:00
|
|
|
// test the user tab
|
2013-08-29 21:55:39 +04:00
|
|
|
casper.thenClick('.settings-menu .users');
|
|
|
|
casper.waitForSelector('#user', function then() {
|
2013-08-21 14:50:49 +04:00
|
|
|
test.assertEval(function testGeneralIsNotActive() {
|
|
|
|
return !document.querySelector('.settings-menu .general').classList.contains('active');
|
|
|
|
}, "general tab is not marked active");
|
|
|
|
test.assertEval(function testUserIsActive() {
|
|
|
|
return document.querySelector('.settings-menu .users').classList.contains('active');
|
|
|
|
}, "user tab is marked active");
|
|
|
|
test.assertEval(function testContentIsUser() {
|
|
|
|
return document.querySelector('.settings-content').id === 'user';
|
|
|
|
}, "loaded content is user screen");
|
2013-08-29 21:55:39 +04:00
|
|
|
}, function onTimeOut() {
|
|
|
|
test.fail('User screen failed to load');
|
2013-08-21 14:50:49 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
function handleUserRequest(requestData, request) {
|
|
|
|
// make sure we only get requests from the user pane
|
|
|
|
if (requestData.url.indexOf('settings/') !== -1) {
|
2013-10-08 05:39:33 +04:00
|
|
|
test.fail("Saving the user pane triggered another settings pane to save");
|
2013-08-21 14:50:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSettingsRequest(requestData, request) {
|
|
|
|
// make sure we only get requests from the user pane
|
|
|
|
if (requestData.url.indexOf('users/') !== -1) {
|
2013-10-08 05:39:33 +04:00
|
|
|
test.fail("Saving a settings pane triggered the user pane to save");
|
2013-08-21 14:50:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
casper.then(function listenForRequests() {
|
|
|
|
casper.on('resource.requested', handleUserRequest);
|
|
|
|
});
|
|
|
|
|
2013-08-29 21:55:39 +04:00
|
|
|
casper.thenClick('#user .button-save');
|
|
|
|
casper.waitFor(function successNotification() {
|
2013-08-21 14:50:49 +04:00
|
|
|
return this.evaluate(function () {
|
|
|
|
return document.querySelectorAll('.js-bb-notification section').length > 0;
|
|
|
|
});
|
|
|
|
}, function doneWaiting() {
|
|
|
|
|
|
|
|
}, function waitTimeout() {
|
2013-10-08 05:39:33 +04:00
|
|
|
test.fail("Saving the user pane did not result in a notification");
|
2013-08-21 14:50:49 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function checkUserWasSaved() {
|
|
|
|
casper.removeListener('resource.requested', handleUserRequest);
|
2013-08-27 01:28:41 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.waitForSelector('.notification-success', function onSuccess() {
|
|
|
|
test.assert(true, 'Got success notification');
|
|
|
|
}, function onTimeout() {
|
|
|
|
test.assert(false, 'No success notification :(');
|
2013-08-21 14:50:49 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.thenClick('#main-menu .settings a').then(function testOpeningSettingsTwice() {
|
|
|
|
casper.on('resource.requested', handleSettingsRequest);
|
|
|
|
test.assertEval(function testUserIsActive() {
|
|
|
|
return document.querySelector('.settings-menu .general').classList.contains('active');
|
|
|
|
}, "general tab is marked active");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.thenClick('#general .button-save').waitFor(function successNotification() {
|
|
|
|
return this.evaluate(function () {
|
|
|
|
return document.querySelectorAll('.js-bb-notification section').length > 0;
|
|
|
|
});
|
|
|
|
}, function doneWaiting() {
|
|
|
|
|
|
|
|
}, function waitTimeout() {
|
2013-10-08 05:39:33 +04:00
|
|
|
test.fail("Saving the general pane did not result in a notification");
|
2013-08-21 14:50:49 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function checkSettingsWereSaved() {
|
|
|
|
casper.removeListener('resource.requested', handleSettingsRequest);
|
2013-08-27 01:28:41 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.waitForSelector('.notification-success', function onSuccess() {
|
|
|
|
test.assert(true, 'Got success notification');
|
|
|
|
}, function onTimeout() {
|
|
|
|
test.assert(false, 'No success notification :(');
|
2013-07-31 11:33:28 +04:00
|
|
|
});
|
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
CasperTest.beforeDone(function () {
|
2013-08-21 14:50:49 +04:00
|
|
|
casper.removeListener('resource.requested', handleUserRequest);
|
|
|
|
casper.removeListener('resource.requested', handleSettingsRequest);
|
2013-07-31 11:33:28 +04:00
|
|
|
});
|
2013-08-25 14:49:31 +04:00
|
|
|
});
|
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
CasperTest.begin("User settings screen validates email", 6, function suite(test) {
|
2013-08-25 14:49:31 +04:00
|
|
|
var email, brokenEmail;
|
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
casper.thenOpen(url + "ghost/settings/user/", function testTitleAndUrl() {
|
2013-09-28 18:21:59 +04:00
|
|
|
test.assertTitle("Ghost Admin", "Ghost admin has no title");
|
2013-09-15 15:13:06 +04:00
|
|
|
test.assertUrlMatch(/ghost\/settings\/user\/$/, "Ghost doesn't require login this time");
|
2013-10-08 05:39:33 +04:00
|
|
|
});
|
2013-08-25 14:49:31 +04:00
|
|
|
|
|
|
|
casper.then(function setEmailToInvalid() {
|
|
|
|
email = casper.getElementInfo('#user-email').attributes.value;
|
|
|
|
brokenEmail = email.replace('.', '-');
|
|
|
|
|
2013-09-16 01:42:30 +04:00
|
|
|
casper.fillSelectors('.user-profile', {
|
2013-08-27 01:28:41 +04:00
|
|
|
'#user-email': brokenEmail
|
2013-08-25 14:49:31 +04:00
|
|
|
}, false);
|
|
|
|
});
|
|
|
|
|
2013-08-27 01:28:41 +04:00
|
|
|
casper.thenClick('#user .button-save');
|
|
|
|
|
|
|
|
casper.waitForResource('/users/');
|
|
|
|
|
|
|
|
casper.waitForSelector('.notification-error', function onSuccess() {
|
|
|
|
test.assert(true, 'Got error notification');
|
2013-08-25 14:49:31 +04:00
|
|
|
test.assertSelectorDoesntHaveText('.notification-error', '[object Object]');
|
2013-08-27 01:28:41 +04:00
|
|
|
}, function onTimeout() {
|
|
|
|
test.assert(false, 'No error notification :(');
|
2013-08-25 14:49:31 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function resetEmailToValid() {
|
2013-09-16 01:42:30 +04:00
|
|
|
casper.fillSelectors('.user-profile', {
|
2013-08-27 01:28:41 +04:00
|
|
|
'#user-email': email
|
2013-08-25 14:49:31 +04:00
|
|
|
}, false);
|
|
|
|
});
|
|
|
|
|
2013-08-27 01:28:41 +04:00
|
|
|
casper.thenClick('#user .button-save');
|
|
|
|
|
2013-08-29 21:55:39 +04:00
|
|
|
casper.waitForResource(/users/);
|
2013-08-27 01:28:41 +04:00
|
|
|
|
|
|
|
casper.waitForSelector('.notification-success', function onSuccess() {
|
|
|
|
test.assert(true, 'Got success notification');
|
2013-08-25 14:49:31 +04:00
|
|
|
test.assertSelectorDoesntHaveText('.notification-success', '[object Object]');
|
2013-08-27 01:28:41 +04:00
|
|
|
}, function onTimeout() {
|
|
|
|
test.assert(false, 'No success notification :(');
|
2013-08-25 14:49:31 +04:00
|
|
|
});
|
2013-07-31 11:33:28 +04:00
|
|
|
});
|