Skip to content

Commit

Permalink
Merge pull request TryGhost#2586 from jaswilli/issue-2273
Browse files Browse the repository at this point in the history
Added functional tests for admin content screen
  • Loading branch information
ErisDS committed Apr 13, 2014
2 parents 9560b6a + 7f8bc50 commit 0806c31
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 7 deletions.
202 changes: 198 additions & 4 deletions core/test/functional/admin/content_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*globals casper, __utils__, url, testPost */
/*globals casper, __utils__, url, testPost, newUser */

CasperTest.begin("Content screen is correct", 12, function suite(test) {
CasperTest.begin("Content screen is correct", 22, function suite(test) {
// Create a sample post
casper.thenOpen(url + 'ghost/editor/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
Expand Down Expand Up @@ -30,9 +30,32 @@ CasperTest.begin("Content screen is correct", 12, function suite(test) {
casper.then(function testViews() {
test.assertExists(".content-view-container", "Content main view is present");
test.assertExists(".content-list-content", "Content list view is present");
test.assertExists('.content-list .floatingheader a.button.button-add', 'add new post button exists');
test.assertEquals(this.getElementAttribute('.content-list .floatingheader a.button.button-add', 'href'), '/ghost/editor/', 'add new post href is correct');
test.assertExists(".content-list-content li .entry-title", "Content list view has at least one item");
test.assertSelectorHasText(".content-list-content li:first-child h3", testPost.title, "title is present and has content");
test.assertSelectorHasText(".content-list-content li:first-child .entry-meta .status .draft", 'Draft', "status is present has content");
test.assertExists(".content-preview", "Content preview is present");
test.assertSelectorHasText(".content-list-content li:first-child h3", testPost.title, "item is present and has content");
test.assertSelectorHasText('.content-preview header .status', 'Written', 'preview header contains "Written" when post is a draft');
test.assertSelectorHasText('.content-preview header .author', newUser.name, 'preview header contains author name');
});

casper.then(function testEditPostButton() {
test.assertExists('.content-preview a.post-edit', 'edit post button exists');
});

casper.then(function testPostSettingsMenu() {
test.assertExists('.content-preview a.post-settings', 'post settings button exists');
this.click('.content-preview a.post-settings');
});

casper.waitUntilVisible('.post-settings-menu', function onSuccess() {
test.assert(true, 'post settings menu should be visible after clicking post-settings icon');
});

casper.then(function postSettingsMenuItems() {
test.assertExists('.post-settings-menu #static-page', 'post settings static page exists');
test.assertExists('.post-settings-menu a.delete', 'post settings delete this post exists');
});

casper.then(function testActiveItem() {
Expand All @@ -47,6 +70,177 @@ CasperTest.begin("Content screen is correct", 12, function suite(test) {
});
});

CasperTest.begin('Content list shows correct post status', 8, function testStaticPageStatus(test) {
// Make sure we have at least one post in the published state
casper.thenOpen(url + 'ghost/editor/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
});

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');
});

// Open the publish options menu;
casper.thenClick('.js-publish-splitbutton .options.up');

// Select the publish post button
casper.thenClick('.js-publish-splitbutton li[data-set-status="published"]');

casper.waitForSelectorTextChange('.js-publish-button', function onSuccess() {
this.click('.js-publish-button');
}, function onTimeout() {
test.assert(false, 'publish button did not change to published');
});

casper.waitForResource(/posts\/$/, function checkPostWasCreated() {
test.assertExists('.notification-success', 'got success notification');
});

// Begin test
casper.thenOpen(url + 'ghost/content/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
test.assertUrlMatch(/ghost\/content\/$/, "Ghost doesn't require login this time");
});

// Select first non-draft, non-static post. Should be second in the list
// at this stage of testing.
casper.thenClick('.content-list-content li:nth-child(2) a');

// Test for status of 'Published'
casper.then(function checkStatus() {
test.assertSelectorHasText('.content-list-content li.active .entry-meta .status time', 'Published', 'status is present and labeled as published');
});

// Change post to static page
casper.thenClick('a.post-settings');

casper.waitUntilVisible('.post-settings-menu', function onSuccess() {
test.assert(true, 'post settings menu should be visible after clicking post-settings icon');
});

casper.thenClick('.post-settings-menu #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');
}, function onTimeout() {
test.assert(false, 'status did not change');
});
});

CasperTest.begin('Preview shows correct header for published post', 7, function testPublishedHeader(test) {
// Make sure we have at least one post in the published state
casper.thenOpen(url + 'ghost/editor/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
});

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');
});

// Open the publish options menu;
casper.thenClick('.js-publish-splitbutton .options.up');

// Select the publish post button
casper.thenClick('.js-publish-splitbutton li[data-set-status="published"]');

casper.waitForSelectorTextChange('.js-publish-button', function onSuccess() {
this.click('.js-publish-button');
}, function onTimeout() {
test.assert(false, 'publish button did not change to published');
});

casper.waitForResource(/posts\/$/, function checkPostWasCreated() {
test.assertExists('.notification-success', 'got success notification');
});

// Begin test
casper.thenOpen(url + 'ghost/content/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
test.assertUrlMatch(/ghost\/content\/$/, "Ghost doesn't require login this time");
});

// Select first non-draft, non-static post. Should be second in the list
// at this stage of testing.
casper.thenClick('.content-list-content li:nth-child(2) a');

casper.then(function testHeader() {
test.assertSelectorHasText('.content-preview header .status', 'Published', 'preview header contains "Published" when post is published');
test.assertSelectorHasText('.content-preview header .author', newUser.name, 'preview header contains author name');
});
});

CasperTest.begin('Delete post modal', 9, function testDeleteModal(test) {
// Create a post that can be deleted
casper.thenOpen(url + 'ghost/editor/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
});

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.thenClick('.js-publish-button');

casper.waitForResource(/posts\/$/, function checkPostWasCreated() {
test.assertExists('.notification-success', 'got success notification');
});

// Begin test
casper.thenOpen(url + 'ghost/content/', function testTitleAndUrl() {
test.assertTitle('Ghost Admin', 'Ghost admin has no title');
});

// Test cancel delete
casper.thenClick('.content-preview a.post-settings');
casper.thenClick('.post-settings-menu a.delete');

casper.waitUntilVisible('#modal-container', function onSuccess() {
test.assertSelectorHasText(
'.modal-content .modal-header',
'Are you sure you want to delete this post?',
'delete modal has correct text');
});

casper.thenClick('.js-button-reject');

casper.waitWhileVisible("#modal-container", function onSuccess() {
test.assert(true, "clicking cancel should close the delete post modal");
});

// Test delete
casper.thenClick('.content-preview a.post-settings');
casper.thenClick('.post-settings-menu a.delete');

casper.waitForSelector('#modal-container .modal-content', function onSuccess() {
test.assertExists('.modal-content .js-button-accept', 'delete button exists');

// Delete the post
this.click('.modal-content .js-button-accept');

casper.waitForSelector('.notification-success', function onSuccess() {
test.assert(true, 'Got success notification from delete post');
test.assertSelectorHasText('.notification-success', 'Your post has been deleted.');
}, function onTimeout() {
test.fail('No success notification from delete post');
});
});
});

CasperTest.begin('Infinite scrolling', 1, function suite(test) {
// Placeholder for infinite scrolling/pagination tests (will need to setup 16+ posts).

Expand Down Expand Up @@ -99,7 +293,7 @@ CasperTest.begin("Posts can be marked as featured", 12, function suite(test) {
test.assert(true, 'got a featured star');
this.click('.notification-success .close');
}, function onTimeout() {
test.assert(false, 'No featured star appeard in the left pane');
test.assert(false, 'No featured star appeared in the left pane');
});

// Mark as not featured
Expand Down
2 changes: 1 addition & 1 deletion core/test/functional/admin/editor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ CasperTest.begin("Post settings menu", 18, function suite(test) {
casper.waitForText(staticPageConversionText, function onSuccess() {
test.assertSelectorHasText(
".notification-success", staticPageConversionText, "correct static page conversion notification appears");
})
});

casper.thenClick(".post-settings-menu #static-page");

Expand Down
2 changes: 0 additions & 2 deletions core/test/functional/admin/settings_test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*globals casper, __utils__, url */

// var navTest = require('../partials/partial_test');

CasperTest.begin("Settings screen is correct", 18, function suite(test) {
casper.thenOpen(url + "ghost/settings/", function testTitleAndUrl() {
test.assertTitle("Ghost Admin", "Ghost admin has no title");
Expand Down

0 comments on commit 0806c31

Please sign in to comment.