Adding more ember admin tests

- improving the implementation of thenOpenAndWaitForPageLoad
- adding a class into the settings templates to more easily test which pane we are on
- adding more, and updating more of the settings tests
- added the editor tests
This commit is contained in:
Hannah Wolfe 2014-06-23 09:27:07 +01:00
parent 79c2132905
commit f1c8cba799
7 changed files with 709 additions and 168 deletions

View File

@ -3,7 +3,7 @@
<h2 class="title">Apps</h2>
</header>
<section class="content fade-in">
<section class="content settings-apps fade-in">
<table class="js-apps">
<thead>
<th>App name</th>

View File

@ -6,7 +6,7 @@
</section>
</header>
<section class="content fade-in">
<section class="content settings-general fade-in">
<form id="settings-general" novalidate="novalidate">
<fieldset>

View File

@ -6,7 +6,7 @@
</section>
</header>
<section class="content no-padding fade-in">
<section class="content settings-user no-padding fade-in">
<header class="user-profile-header">
<img id="user-cover" class="cover-image" {{bind-attr src=cover title=coverTitle}} />

View File

@ -63,20 +63,21 @@ casper.writeContentToCodeMirror = function (content) {
casper.waitForOpaque = function (classname, then, timeout) {
timeout = timeout || casper.failOnTimeout(casper.test, 'waitForOpaque failed on ' + classname);
casper.waitFor(function checkOpaque() {
var value = this.evaluate(function (element) {
var target = document.querySelector(element);
if (target === null) {
return null;
casper.waitForSelector(classname).then(function () {
casper.waitFor(function checkOpaque() {
var value = this.evaluate(function (element) {
var target = document.querySelector(element);
if (target === null) {
return null;
}
return window.getComputedStyle(target).getPropertyValue('opacity') === '1';
}, classname);
if (value !== true && value !== false) {
casper.test.fail('Unable to find element: ' + classname);
}
return window.getComputedStyle(target).getPropertyValue('opacity') === '1';
}, classname);
if (value !== true && value !== false) {
casper.test.fail('Unable to find element: ' + classname);
}
return value;
}, then, timeout);
return value;
}, then, timeout);
});
};
// ### Then Open And Wait For Page Load
@ -104,11 +105,11 @@ casper.thenOpenAndWaitForPageLoad = function (screen, then, timeout) {
},
'settings.general': {
url: 'ghost/ember/settings/general',
selector: '.settings-content form#settings-general'
selector: '.settings-content .settings-general'
},
'settings.user': {
url: 'ghost/ember/settings/user',
selector: '.settings-content form.user-profile'
selector: '.settings-content .settings-user'
},
'signin': {
url: 'ghost/ember/signin/',
@ -125,7 +126,8 @@ casper.thenOpenAndWaitForPageLoad = function (screen, then, timeout) {
};
return casper.thenOpen(url + screens[screen].url).then(function () {
return casper.waitForSelector(screens[screen].selector, then, timeout, 15000);
// Some screens fade in
return casper.waitForOpaque(screens[screen].selector, then, timeout, 10000);
});
};

View File

@ -40,11 +40,11 @@ CasperTest.emberBegin("Content screen is correct", 17, function suite(test) {
});
casper.then(function postSettingsMenuItems() {
test.assertExists('.post-settings-menu #static-page', 'post settings static page exists');
test.assertExists('.post-settings-menu .post-setting-static-page', 'post settings static page exists');
test.assertExists('.post-settings-menu a.delete', 'post settings delete this post exists');
});
// A bug is causing this to not always be activated. Uncomment when fixed
// A bug is causing this to not always be activated. TODO: Uncomment when fixed #3008
// casper.then(function testActiveItem() {
// test.assertExists('.content-list-content li:first-of-type .active', 'first item is active');
// test.assertDoesntExist('.content-list-content li:nth-of-type(2) .active', 'second item is not active');
@ -87,7 +87,7 @@ CasperTest.emberBegin('Content list shows correct post status', 7, function test
test.assert(true, 'post settings menu should be visible after clicking post-settings icon');
});
casper.thenClick('.post-settings-menu #static-page');
casper.thenClick('.post-settings-menu .post-setting-static-page');
casper.waitForSelector('.content-list-content li .entry-meta .status .page', function waitForSuccess() {
test.assertSelectorHasText('.content-list-content li .entry-meta .status .page', 'Page', 'status is Page');
@ -143,7 +143,7 @@ CasperTest.emberBegin('Delete post modal', 7, function testDeleteModal(test) {
});
});
// Uncomment when test is implemented... much needed!
// TODO: Implement this test... much needed!
//CasperTest.emberBegin('Infinite scrolling', 2, function suite(test) {
// // Placeholder for infinite scrolling/pagination tests (will need to setup 16+ posts).
//

View File

@ -0,0 +1,541 @@
// # Editor Test
// Test the editor screen works as expected
/*globals casper, __utils__, url, testPost */
CasperTest.emberBegin("Ghost editor functions correctly", 14, function suite(test) {
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
test.assertExists(".entry-markdown", "Ghost editor is present");
test.assertExists(".entry-preview", "Ghost preview is present");
});
// Part 1: Test saving with no data - title is required
casper.waitForSelector('#entry-title', function then() {
test.assertEvalEquals(function() {
return document.getElementById('entry-title').value;
}, '', 'Title is empty');
});
casper.thenClick('.js-publish-button');
casper.waitForSelector('.notification-error', function onSuccess() {
test.assert(true, 'Save without title results in error notification as expected');
test.assertSelectorHasText('.notification-error', 'must specify a title', 'notification text is correct');
test.assertSelectorDoesntHaveText('.notification-error', '[object Object]');
}, function onTimeout() {
test.assert(false, 'Save without title did not result in an error notification');
});
this.thenClick('.js-bb-notification .close');
// Part 2: Test saving with data
casper.then(function createTestPost() {
casper.sendKeys('#entry-title', testPost.title);
casper.writeContentToCodeMirror(testPost.html);
});
casper.waitForSelectorTextChange('.entry-preview .rendered-markdown', function onSuccess() {
test.assertSelectorHasText('.entry-preview .rendered-markdown', 'test', 'Editor value is correct.');
}, casper.failOnTimeout(test, 'markdown did not re-render'));
casper.thenClick('.js-publish-button');
casper.waitForSelector('.notification-success', function onSuccess() {
test.assertUrlMatch(/ghost\/ember\/editor\/\d+\/$/, 'got an id on our URL');
test.assertEvalEquals(function () {
return document.querySelector('#entry-title').value;
}, testPost.title, 'Title is correct');
}, casper.failOnTimeout(test, 'Post was not successfully created'));
// TODO: uncomment when fixed in #3040
// Part 3: Test title trimming
// var untrimmedTitle = ' test title ',
// trimmedTitle = 'test title';
//
// casper.then(function populateTitle() {
// casper.sendKeys('#entry-title', untrimmedTitle);
//
// test.assertEvalEquals(function () {
// return $('#entry-title').val();
// }, trimmedTitle, 'Entry title should match expected value.');
// });
// Part 4: Word count and plurality
casper.then(function checkZeroPlural() {
test.assertSelectorHasText('.entry-word-count', '0 words', 'count of 0 produces plural "words".');
});
casper.then(function () {
casper.writeContentToCodeMirror('test');
});
casper.waitForSelectorTextChange('.entry-word-count', function onSuccess() {
test.assertSelectorHasText('.entry-word-count', '1 word', 'count of 1 produces singular "word".');
});
casper.then(function () {
casper.writeContentToCodeMirror('test'); // append another word, assumes newline
});
casper.waitForSelectorTextChange('.entry-word-count', function onSuccess() {
test.assertSelectorHasText('.entry-word-count', '2 words', 'count of 2 produces plural "words".');
});
});
// TODO: Expand markdown tests to cover more markdown, and keyboard shortcuts
CasperTest.emberBegin("Markdown in editor works", 4, function suite(test) {
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
});
casper.then(function testImage() {
casper.writeContentToCodeMirror("![sometext]()");
});
casper.waitForSelectorTextChange('.entry-preview .rendered-markdown', function onSuccess() {
test.assertEvalEquals(function () {
return document.querySelector('.CodeMirror-wrap textarea').value;
}, '![sometext]()', 'Editor value is correct');
test.assertSelectorHasText('.entry-preview .rendered-markdown', 'Add image of sometext', 'Editor value is correct');
}, function onTimeout() {
test.assert('false', 'markdown did not re-render');
});
});
CasperTest.emberBegin("Image Uploads", 17, function suite(test) {
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
});
// Test standard image upload modal
casper.then(function () {
casper.writeContentToCodeMirror("![]()");
});
function assertEmptyImageUploaderDisplaysCorrectly() {
test.assertExists(".entry-preview .js-upload-target", "Upload target exists");
test.assertExists(".entry-preview .js-fileupload", "File upload target exists");
test.assertExists(".entry-preview .image-url", "Image URL button exists");
}
casper.waitForSelector(".entry-preview .js-drop-zone.image-uploader", assertEmptyImageUploaderDisplaysCorrectly);
// Test image URL upload modal
casper.thenClick(".entry-preview .image-uploader a.image-url");
casper.waitForSelector(".image-uploader-url", function onSuccess() {
test.assertExists(".image-uploader-url .url.js-upload-url", "Image URL uploader exists")
test.assertExists(".image-uploader-url .button-save.js-button-accept", "Image URL accept button exists")
test.assertExists(".image-uploader-url .image-upload", "Back to normal image upload style button exists")
});
// Test image source location
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
});
var testFileLocation = "test/file/location";
casper.then(function () {
var markdownImageString = "![](" + testFileLocation + ")";
casper.writeContentToCodeMirror(markdownImageString);
});
casper.waitForSelector(".entry-preview .js-drop-zone.pre-image-uploader", function onSuccess() {
var imageJQuerySelector = ".entry-preview img.js-upload-target[src='" + testFileLocation + "']"
test.assertExists(imageJQuerySelector, "Uploaded image tag properly links to source location");
});
// Test cancel image button
casper.thenClick(".pre-image-uploader a.image-cancel.js-cancel");
casper.waitForSelector(".entry-preview .js-drop-zone.image-uploader", assertEmptyImageUploaderDisplaysCorrectly);
// Test image url source location
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
});
casper.then(function () {
casper.writeContentToCodeMirror("![]()");
});
casper.waitForSelector(".entry-preview .js-drop-zone.image-uploader", function onSuccess() {
casper.thenClick(".entry-preview .image-uploader a.image-url");
});
var imageURL = "random.url";
casper.waitForSelector(".image-uploader-url", function onSuccess() {
casper.sendKeys(".image-uploader-url input.url.js-upload-url", imageURL);
casper.thenClick(".js-button-accept.button-save");
});
casper.waitForSelector(".entry-preview .js-drop-zone.pre-image-uploader", function onSuccess() {
var imageJQuerySelector = ".entry-preview img.js-upload-target[src='" + imageURL + "']"
test.assertExists(imageJQuerySelector, "Uploaded image tag properly links to inputted image URL");
});
});
CasperTest.emberBegin("Tag editor", 7, function suite(test) {
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
});
var tagName = "someTagName";
casper.then(function () {
test.assertExists("#entry-tags", "should have tag label area");
test.assertExists("#entry-tags .tag-label", "should have tag label icon");
test.assertExists("#entry-tags input.tag-input", "should have tag input area");
casper.sendKeys("#entry-tags input.tag-input", tagName);
casper.sendKeys("#entry-tags input.tag-input", casper.page.event.key.Enter);
});
var createdTagSelector = "#entry-tags .tags .tag";
casper.waitForSelector(createdTagSelector, function onSuccess() {
test.assertSelectorHasText(createdTagSelector, tagName, "typing enter after tag name should create tag");
});
casper.thenClick(createdTagSelector);
casper.waitWhileSelector(createdTagSelector, function onSuccess() {
test.assert(true, "clicking the tag should delete the tag");
});
});
CasperTest.emberBegin("Post settings menu", 30, function suite(test) {
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
});
casper.then(function () {
test.assertExists("#publish-bar a.post-settings", "icon toggle should exist");
test.assertNotVisible("#publish-bar .post-settings-menu", "popup menu should not be visible at startup");
test.assertExists(".post-settings-menu input#url", "url field exists");
test.assertExists(".post-settings-menu input.post-setting-date", "publication date field exists");
test.assertExists(".post-settings-menu input.post-setting-static-page", "static page checkbox field exists");
test.assertExists(".post-settings-menu a.delete", "delete post button exists")
});
casper.thenClick("#publish-bar a.post-settings");
casper.waitUntilVisible("#publish-bar .post-settings-menu", function onSuccess() {
test.assert(true, "popup menu should be visible after clicking post-settings icon");
test.assertNotVisible(".post-settings-menu a.delete", "delete post btn shouldn't be visible on unsaved drafts");
});
casper.thenClick("#publish-bar a.post-settings");
casper.waitWhileVisible("#publish-bar .post-settings-menu", function onSuccess() {
test.assert(true, "popup menu should not be visible after clicking post-settings icon");
});
// Enter a title and save draft so converting to/from static post
// will result in notifications and 'Delete This Post' button appears
casper.then(function (){
casper.sendKeys("#entry-title", "aTitle");
casper.thenClick(".js-publish-button");
});
casper.waitForSelector('.notification-success', function waitForSuccess() {
test.assert(true, 'got success notification');
// TODO: Uncomment when the post save notifications are correct #2850
// test.assertSelectorHasText('.notification-success', 'Your post has been saved as a draft.');
casper.click('.notification-success a.close');
}, function onTimeout() {
test.assert(false, 'No success notification');
});
casper.waitWhileSelector('.notification-success');
casper.thenClick("#publish-bar a.post-settings");
casper.waitUntilVisible("#publish-bar .post-settings-menu", function onSuccess() {
test.assert(true, "post settings menu should be visible after clicking post-settings icon");
});
casper.waitUntilVisible(".post-settings-menu a.delete", function onSuccess() {
test.assert(true, "delete post button should be visible for saved drafts");
});
// Test change permalink
casper.then(function () {
this.fillSelectors('.post-settings-menu form', {
'#url': 'new-url-editor'
}, false);
this.click('#publish-bar a.post-settings')
});
casper.waitForSelector('.notification-success', function waitForSuccess() {
test.assert(true, 'got success notification');
test.assertSelectorHasText('.notification-success', 'Permalink successfully changed to new-url-editor.');
casper.click('.notification-success a.close');
}, function onTimeout() {
test.assert(false, 'No success notification');
});
casper.waitWhileSelector('.notification-success', function () {
test.assert(true, 'notification cleared.');
test.assertNotVisible('.notification-success', 'success notification should not still exist');
});
// Test change pub date
casper.thenClick('#publish-bar a.post-settings');
casper.waitUntilVisible('#publish-bar .post-settings-menu .post-setting-date', function onSuccess() {
test.assert(true, 'post settings menu should be visible after clicking post-settings icon');
});
casper.then(function () {
this.fillSelectors('.post-settings-menu form', {
'.post-setting-date': '10 May 14 @ 00:17'
}, false);
this.click('#publish-bar a.post-settings')
});
casper.waitForSelector('.notification-success', function waitForSuccess() {
test.assert(true, 'got success notification');
test.assertSelectorHasText('.notification-success', 'Publish date successfully changed to 10 May 14 @ 00:17.');
casper.thenClick('.notification-success a.close');
}, function onTimeout() {
test.assert(false, 'No success notification');
});
casper.waitWhileSelector('.notification-success');
// Test Static Page conversion
casper.thenClick("#publish-bar a.post-settings");
casper.waitUntilVisible("#publish-bar .post-settings-menu", function onSuccess() {
test.assert(true, "post settings menu should be visible after clicking post-settings icon");
});
casper.thenClick('.post-settings-menu .post-setting-static-page');
casper.waitForSelector('.notification-success', function waitForSuccess() {
test.assert(true, 'got success notification');
casper.click('.notification-success a.close');
}, function onTimeout() {
test.assert(false, 'No success notification');
});
casper.waitWhileSelector('.notification-success', function () {
test.assert(true, 'notification cleared.');
test.assertNotVisible('.notification-success', 'success notification should not still exist');
});
casper.thenClick('.post-settings-menu .post-setting-static-page');
casper.waitForSelector('.notification-success', function waitForSuccess() {
test.assert(true, 'got success notification');
casper.click('.notification-success a.close');
}, function onTimeout() {
test.assert(false, 'No success notification');
});
// Test Delete Post Modal
casper.thenClick(".post-settings-menu a.delete");
casper.waitUntilVisible("#modal-container", function onSuccess() {
test.assert(true, "delete post modal is visible after clicking delete");
test.assertSelectorHasText(
"#modal-container .modal-header",
"Are you sure you want to delete this post?",
"delete post modal header has correct text");
});
casper.thenClick("#modal-container .js-button-reject");
casper.waitWhileVisible("#modal-container", function onSuccess() {
test.assert(true, "clicking cancel should close the delete post modal");
});
casper.thenClick("#publish-bar a.post-settings");
casper.thenClick(".post-settings-menu a.delete");
casper.waitUntilVisible("#modal-container", function onSuccess() {
casper.thenClick("#modal-container .js-button-accept");
});
casper.waitForUrl(/ghost\/ember\/\d+\/$/, function onSuccess() {
test.assert(true, "clicking the delete post button should bring us to the content page");
});
});
CasperTest.emberBegin('Publish menu - new post', 11, function suite(test) {
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
});
// ... check default option status, label, class
casper.then(function () {
test.assertExists('.js-publish-splitbutton');
test.assertExists('.js-publish-splitbutton.splitbutton-save');
test.assertExists('.js-publish-button');
test.assertExists('.js-publish-button.button-save');
test.assertSelectorHasText('.js-publish-button', 'Save Draft');
});
casper.then(function switchMenuToPublish() {
// 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');
// ... check status, label, class
casper.waitForSelector('.js-publish-splitbutton.splitbutton-delete', function onSuccess() {
test.assertExists('.js-publish-button.button-delete', 'Publish button should have .button-delete');
test.assertSelectorHasText('.js-publish-button', 'Publish Now');
}, function onTimeout() {
test.assert(false, 'Publish split button should have .splitbutton-delete');
});
});
// Do publish
casper.thenClick('.js-publish-button');
// ... check status, label, class
casper.waitForSelector('.js-publish-splitbutton.splitbutton-save', function onSuccess() {
test.assertExists('.js-publish-button.button-save', 'Update button should have .button-save');
test.assertSelectorHasText('.js-publish-button', 'Update Post');
}, function onTimeout() {
test.assert(false, 'Publish split button should have .splitbutton-save');
});
});
CasperTest.emberBegin('Publish menu - existing post', 21, function suite(test) {
// Create a post, save it and test refreshed editor
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
});
casper.then(function createTestPost() {
casper.sendKeys('#entry-title', testPost.title);
casper.writeContentToCodeMirror(testPost.html);
});
casper.waitForSelectorTextChange('.entry-preview .rendered-markdown', function onSuccess() {
test.assertSelectorHasText('.entry-preview .rendered-markdown', 'test', 'Editor value is correct');
});
// Create a post in draft status
casper.thenClick('.js-publish-button');
casper.waitForSelector('.notification-success', function checkPostWasCreated() {
test.assertUrlMatch(/ghost\/ember\/editor\/\d+\/$/, 'got an id on our URL');
});
// ... check option status, label, class now that we're *saved* as 'draft'
casper.then(function () {
test.assertExists('.js-publish-splitbutton');
test.assertExists('.js-publish-splitbutton.splitbutton-save');
test.assertExists('.js-publish-button');
test.assertExists('.js-publish-button.button-save');
test.assertSelectorHasText('.js-publish-button', 'Save Draft');
});
casper.then(function switchMenuToPublish() {
// 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');
// ... check status, label, class
casper.waitForSelector('.js-publish-splitbutton.splitbutton-delete', function onSuccess() {
test.assertExists('.js-publish-button.button-delete', 'Publish button should have .button-delete');
test.assertSelectorHasText('.js-publish-button', 'Publish Now');
}, function onTimeout() {
test.assert(false, 'Publish split button should have .splitbutton-delete');
});
});
// Do publish
casper.thenClick('.js-publish-button');
casper.waitForSelector('.notification-success', function checkPostWasCreated() {
test.assertUrlMatch(/ghost\/ember\/editor\/\d+\/$/, 'got an id on our URL');
});
// ... check option status, label, class for saved as 'published'
casper.then(function () {
test.assertExists('.js-publish-splitbutton');
test.assertExists('.js-publish-splitbutton.splitbutton-save');
test.assertExists('.js-publish-button');
test.assertExists('.js-publish-button.button-save');
test.assertSelectorHasText('.js-publish-button', 'Update Post');
});
casper.then(function switchMenuToUnpublish() {
// 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:nth-child(2) a');
// ... check status, label, class
casper.waitForSelector('.js-publish-splitbutton.splitbutton-delete', function onSuccess() {
test.assertExists('.js-publish-button.button-delete', 'Publish button should have .button-delete');
test.assertSelectorHasText('.js-publish-button', 'Unpublish');
}, function onTimeout() {
test.assert(false, 'Publish split button should have .splitbutton-delete');
});
});
// Do unpublish
casper.thenClick('.js-publish-button');
casper.waitForSelector('.notification-success', function checkPostWasCreated() {
// ... check status, label, class
casper.waitForSelector('.js-publish-splitbutton.splitbutton-save', function onSuccess() {
test.assertExists('.js-publish-button.button-save', 'Publish button should have .button-save');
test.assertSelectorHasText('.js-publish-button', 'Save Draft');
}, function onTimeout() {
test.assert(false, 'Publish split button should have .splitbutton-save');
});
});
});
// test the markdown help modal
CasperTest.emberBegin('Markdown help modal', 5, function suite(test) {
casper.thenOpenAndWaitForPageLoad('editor', function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
test.assertUrlMatch(/ghost\/ember\/editor\/$/, 'Landed on the correct URL');
});
// open markdown help modal
casper.thenClick('a.markdown-help');
casper.waitUntilVisible('#modal-container', function onSuccess() {
test.assertSelectorHasText(
'.modal-content .modal-header',
'Markdown Help',
'delete modal has correct text');
test.assertExists('.modal-content .close');
});
casper.thenClick('.modal-content .close');
casper.waitWhileVisible('#modal-container', function onSuccess() {
test.assert(true, 'clicking close should remove the markdown help modal');
});
});

View File

@ -7,7 +7,7 @@
// These are used to check that a switch to a tab is complete, or that we are on the right tab.
var generalTabDetector = '.settings-content form#settings-general',
userTabDetector = '.settings-content form.user-profile';
//
CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
casper.thenOpenAndWaitForPageLoad('settings', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
@ -34,9 +34,6 @@ CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
// assert that the right menu item is active
test.assertExists('.settings-menu .users.active', 'User tab is active');
test.assertDoesntExist('.settings-menu .general.active', 'General tab is not active');
// Check Elements on the page are correct?
}, casper.failOnTimeout(test, 'waitForSelector `userTabDetector` timed out'));
casper.thenClick('.settings-menu .general a');
@ -44,17 +41,139 @@ CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
// assert that the right menu item is active
test.assertExists('.settings-menu .general.active', 'General tab is active');
test.assertDoesntExist('.settings-menu .users.active', 'User tab is not active');
// Check Elements on the page are correct?
}, casper.failOnTimeout(test, 'waitForSelector `generalTabDetector` timed out'));
});
});
// ### Saving settings tests
// ## General settings tests
CasperTest.emberBegin('General settings pane is correct', 8, function suite(test) {
casper.thenOpenAndWaitForPageLoad('settings.general', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
test.assertUrlMatch(/ghost\/ember\/settings\/general\/$/, 'Landed on the correct URL');
});
function assertImageUploaderModalThenClose() {
test.assertSelectorHasText('.description', 'Add image');
casper.click('#modal-container .js-button-accept');
casper.waitForSelector('.notification-success', function onSuccess() {
test.assert(true, 'Got success notification');
}, casper.failOnTimeout(test, 'No success notification'));
}
// Ensure image upload modals display correctly
// Test Blog Logo Upload Button
casper.waitForSelector('.js-modal-logo', function () {
casper.click('.js-modal-logo');
});
casper.waitForSelector('#modal-container .modal-content .js-drop-zone .description', assertImageUploaderModalThenClose,
casper.failOnTimeout(test, 'No upload logo modal container appeared'));
// Test Blog Cover Upload Button
casper.waitForSelector('.js-modal-cover', function () {
casper.click('.js-modal-cover');
});
casper.waitForSelector('#modal-container .modal-content .js-drop-zone .description', assertImageUploaderModalThenClose,
casper.failOnTimeout(test, 'No upload cover modal container appeared'));
function handleSettingsRequest(requestData) {
// make sure we only get requests from the user pane
if (requestData.url.indexOf('users/') !== -1) {
test.fail('Saving a settings pane triggered the user pane to save');
}
}
casper.then(function listenForRequests() {
casper.on('resource.requested', handleSettingsRequest);
});
// Ensure can save
casper.waitForSelector('header .button-save').then(function () {
casper.thenClick('header .button-save').waitFor(function successNotification() {
return this.evaluate(function () {
return document.querySelectorAll('.js-bb-notification section').length > 0;
});
}, function doneWaiting() {
test.pass('Waited for notification');
}, casper.failOnTimeout(test, 'Saving the general pane did not result in a notification'));
});
casper.then(function checkSettingsWereSaved() {
casper.removeListener('resource.requested', handleSettingsRequest);
});
casper.waitForSelector('.notification-success', function onSuccess() {
test.assert(true, 'Got success notification');
}, casper.failOnTimeout(test, 'No success notification :('));
});
//// ## General settings validations tests
//CasperTest.emberBegin('General settings validation is correct', 3, function suite(test) {
// casper.thenOpenAndWaitForPageLoad('settings.general', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/general\/$/, 'Ghost doesn\'t require login this time');
// });
//
// // Ensure general blog title field length validation
// this.fillAndSave('form#settings-general', {
// 'general[title]': new Array(152).join('a')
// });
//
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'too long');
// }, casper.failOnTimeout(test, 'Blog title length error did not appear'), 2000);
//
// this.thenClick('.js-bb-notification .close');
//
// // Ensure general blog description field length validation
// this.fillAndSave('form#settings-general', {
// '#blog-description': new Array(202).join('a')
// });
//
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'too long');
// }, casper.failOnTimeout(test, 'Blog description length error did not appear'));
//
// this.thenClick('.js-bb-notification .close');
//
// // Ensure postsPerPage number field form validation
// this.fillAndSave('form#settings-general', {
// 'general[postsPerPage]': 'notaninteger'
// });
//
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'use a number');
// }, casper.failOnTimeout(test, 'postsPerPage error did not appear'), 2000);
//
// this.thenClick('.js-bb-notification .close');
//
// // Ensure postsPerPage max of 1000
// this.fillAndSave('form#settings-general', {
// 'general[postsPerPage]': '1001'
// });
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'use a number less than 1000');
// }, casper.failOnTimeout(test, 'postsPerPage max error did not appear', 2000));
//
// this.thenClick('.js-bb-notification .close');
//
// // Ensure postsPerPage min of 0
// this.fillAndSave('form#settings-general', {
// 'general[postsPerPage]': '-1'
// });
//
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'use a number greater than 0');
// }, casper.failOnTimeout(test, 'postsPerPage min error did not appear', 2000));
//});
// ### User settings tests
// Please uncomment and fix these as the functionality is implemented
//CasperTest.emberBegin('Can save settings', 6, function suite(test) {
// casper.thenOpenAndWaitForPageLoad(url + 'ghost/ember/settings/user/', function testTitleAndUrl() {
// casper.thenOpenAndWaitForPageLoad('settings.user', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/ember\/settings\/user\/$/, 'Landed on the correct URL');
// });
@ -99,7 +218,6 @@ CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
// 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() {
@ -122,81 +240,13 @@ CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
// casper.removeListener('resource.requested', handleUserRequest);
// casper.removeListener('resource.requested', handleSettingsRequest);
// });
});
//
//CasperTest.begin('Ensure general blog title field length validation', 3, function suite(test) {
// casper.thenOpen(url + 'ghost/settings/general/', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/general\/$/, 'Ghost doesn\'t require login this time');
// });
//
// casper.waitForSelector('#general', function then() {
// this.fill('form#settings-general', {
// 'general[title]': new Array(152).join('a')
// });
// }, casper.failOnTimeout(test, 'waitForSelector #general timed out'));
//
// casper.thenClick('#general .button-save');
//
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'too long');
// }, casper.failOnTimeout(test, 'Blog title length error did not appear'), 2000);
//});
//
//CasperTest.begin('Ensure general blog description field length validation', 3, function suite(test) {
// casper.thenOpen(url + 'ghost/settings/general/', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/general\/$/, 'Ghost doesn\'t require login this time');
// });
//
// casper.waitForSelector('#general', function then() {
// this.fillSelectors('form#settings-general', {
// '#blog-description': new Array(202).join('a')
// });
// }, casper.failOnTimeout(test, 'waitForSelector #general timed out'));
//
// casper.thenClick('#general .button-save');
//
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'too long');
// }, casper.failOnTimeout(test, 'Blog description length error did not appear'));
//});
//
//CasperTest.begin('Ensure image upload modals display correctly', 6, function suite(test) {
// casper.thenOpen(url + 'ghost/settings/general/', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/general\/$/, 'Ghost doesn\'t require login this time');
// });
//
// function assertImageUploaderModalThenClose() {
// test.assertSelectorHasText('.description', 'Add image');
// this.click('#modal-container .js-button-accept');
// casper.waitForSelector('.notification-success', function onSuccess() {
// test.assert(true, 'Got success notification');
// }, casper.failOnTimeout(test, 'No success notification'));
// }
//
// // Test Blog Logo Upload Button
// casper.waitForOpaque('#general', function then() {
// this.click('#general .js-modal-logo');
// }, casper.failOnTimeout(test, 'waitForOpaque #general timed out'));
//
// casper.waitForSelector('#modal-container .modal-content .js-drop-zone .description', assertImageUploaderModalThenClose,
// casper.failOnTimeout(test, 'No upload logo modal container appeared'));
//
// // Test Blog Cover Upload Button
// casper.waitForOpaque('#general', function then() {
// this.click('#general .js-modal-cover');
// }, casper.failOnTimeout(test, 'waitForOpaque #general timed out'));
//
// casper.waitForSelector('#modal-container .modal-content .js-drop-zone .description', assertImageUploaderModalThenClose,
// casper.failOnTimeout(test, 'No upload cover modal container appeared'));
//});
//
//CasperTest.begin('User settings screen validates email', 6, function suite(test) {
//CasperTest.emberBegin('User settings screen validates email', 6, function suite(test) {
// var email, brokenEmail;
//
// casper.thenOpen(url + 'ghost/settings/user/', function testTitleAndUrl() {
// casper.thenOpenAndWaitForPageLoad('settings.user', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/user\/$/, 'Ghost doesn\'t require login this time');
// });
@ -235,70 +285,18 @@ CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
// }, casper.failOnTimeout(test, 'No success notification :('));
//});
//
//CasperTest.begin('Ensure postsPerPage number field form validation', 3, function suite(test) {
// casper.thenOpen(url + 'ghost/settings/general/', function testTitleAndUrl() {
//
//CasperTest.emberBegin('User settings screen shows remaining characters for Bio properly', 4, function suite(test) {
// casper.thenOpenAndWaitForPageLoad('settings.user', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/general\/$/, 'Ghost doesn\'t require login this time');
// test.assertUrlMatch(/ghost\/settings\/user\/$/, 'Ghost doesn\'t require login this time');
// });
//
// casper.waitForSelector('#general', function then() {
// this.fill('form#settings-general', {
// 'general[postsPerPage]': 'notaninteger'
// });
// }, casper.failOnTimeout(test, 'waitForSelector #general timed out'));
//
// casper.thenClick('#general .button-save');
//
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'use a number');
// }, casper.failOnTimeout(test, 'postsPerPage error did not appear'), 2000);
//});
//
//CasperTest.begin('Ensure postsPerPage max of 1000', 3, function suite(test) {
// casper.thenOpen(url + 'ghost/settings/general/', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/general\/$/, 'Ghost doesn\'t require login this time');
// });
//
// casper.waitForSelector('#general', function then() {
// this.fill('form#settings-general', {
// 'general[postsPerPage]': '1001'
// });
// }, casper.failOnTimeout(test, 'waitForSelector #general timed out'));
//
// casper.thenClick('#general .button-save');
//
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'use a number less than 1000');
// }, casper.failOnTimeout(test, 'postsPerPage max error did not appear', 2000));
//});
//
//CasperTest.begin('Ensure postsPerPage min of 0', 3, function suite(test) {
// casper.thenOpen(url + 'ghost/settings/general/', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/general\/$/, 'Ghost doesn\'t require login this time');
// });
//
// casper.waitForSelector('#general', function then() {
// this.fill('form#settings-general', {
// 'general[postsPerPage]': '-1'
// });
// }, casper.failOnTimeout(test, 'waitForSelector #general timed out'));
//
// casper.thenClick('#general .button-save');
//
// casper.waitForSelectorTextChange('.notification-error', function onSuccess() {
// test.assertSelectorHasText('.notification-error', 'use a number greater than 0');
// }, casper.failOnTimeout(test, 'postsPerPage min error did not appear', 2000));
//});
//
//CasperTest.begin('User settings screen shows remaining characters for Bio properly', 4, function suite(test) {
//
// function getRemainingBioCharacterCount() {
// return casper.getHTML('.word-count');
// }
//
// casper.thenOpen(url + 'ghost/settings/user/', function testTitleAndUrl() {
// casper.thenOpenAndWaitForPageLoad(url + 'ghost/settings/user/', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/user\/$/, 'Ghost doesn\'t require login this time');
// });
@ -318,8 +316,8 @@ CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
// });
//});
//
//CasperTest.begin('Ensure user bio field length validation', 3, function suite(test) {
// casper.thenOpen(url + 'ghost/settings/user/', function testTitleAndUrl() {
//CasperTest.emberBegin('Ensure user bio field length validation', 3, function suite(test) {
// casper.thenOpenAndWaitForPageLoad('settings.user', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/user\/$/, 'Ghost doesn\'t require login this time');
// });
@ -337,8 +335,8 @@ CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
// }, casper.failOnTimeout(test, 'Bio field length error did not appear', 2000));
//});
//
//CasperTest.begin('Ensure user url field validation', 3, function suite(test) {
// casper.thenOpen(url + 'ghost/settings/user/', function testTitleAndUrl() {
//CasperTest.emberBegin('Ensure user url field validation', 3, function suite(test) {
// casper.thenOpenAndWaitForPageLoad('settings.user', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/user\/$/, 'Ghost doesn\'t require login this time');
// });
@ -356,8 +354,8 @@ CasperTest.emberBegin('Settings screen is correct', 17, function suite(test) {
// }, casper.failOnTimeout(test, 'Url validation error did not appear', 2000));
//});
//
//CasperTest.begin('Ensure user location field length validation', 3, function suite(test) {
// casper.thenOpen(url + 'ghost/settings/user/', function testTitleAndUrl() {
//CasperTest.emberBegin('Ensure user location field length validation', 3, function suite(test) {
// casper.thenOpenAndWaitForPageLoad('settings.user', function testTitleAndUrl() {
// test.assertTitle('Ghost Admin', 'Ghost admin has no title');
// test.assertUrlMatch(/ghost\/settings\/user\/$/, 'Ghost doesn\'t require login this time');
// });