From d3a61b93e9432af7c242faf5b288e4cc2c2e256b Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 28 Oct 2013 16:04:30 +0000 Subject: [PATCH] Wait for menu to open in editor test issue #1287 - also contains some misc cleanup --- core/test/functional/admin/editor_test.js | 28 +++++++++++++++-------- core/test/functional/base.js | 18 +++++++-------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/core/test/functional/admin/editor_test.js b/core/test/functional/admin/editor_test.js index 9489bba44d..b8d0f5885e 100644 --- a/core/test/functional/admin/editor_test.js +++ b/core/test/functional/admin/editor_test.js @@ -25,6 +25,8 @@ CasperTest.begin("Ghost editor is correct", 10, function suite(test) { casper.waitForSelectorTextChange('.entry-preview .rendered-markdown', function onSuccess() { test.assertSelectorHasText('.entry-preview .rendered-markdown', 'test', 'Editor value is correct.'); + }, function onTimeout() { + test.assert('false', 'markdown did not re-render'); }); casper.thenClick('.js-publish-button'); @@ -36,6 +38,8 @@ CasperTest.begin("Ghost editor is correct", 10, function suite(test) { test.assertEvalEquals(function () { return document.querySelector('#entry-title').value; }, testPost.title, 'Title is correct'); + }, function onTimeout() { + test.assert('false', 'post was not created'); }); }); @@ -54,6 +58,8 @@ CasperTest.begin("Haunted markdown in editor works", 3, function suite(test) { }, '![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'); }); }); @@ -72,7 +78,7 @@ CasperTest.begin("Word count and plurality", 4, function suite(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 @@ -114,7 +120,7 @@ CasperTest.begin('Publish menu - new post', 10, function suite(test) { test.assertExists('.js-publish-button'); test.assertExists('.js-publish-button.button-save'); test.assertSelectorHasText('.js-publish-button', 'Save Draft'); - test.assertEval(function() { + test.assertEval(function () { return (__utils__.findOne('.js-publish-button').getAttribute('data-status') === 'draft'); }, 'Publish button\'s initial status should be "draft"'); }); @@ -130,7 +136,7 @@ CasperTest.begin('Publish menu - new post', 10, function suite(test) { 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'); - test.assertEval(function() { + test.assertEval(function () { return (__utils__.findOne('.js-publish-button').getAttribute('data-status') === 'published'); }, 'Publish button\'s updated status should be "published"'); }, function onTimeout() { @@ -168,7 +174,7 @@ CasperTest.begin('Publish menu - existing post', 22, function suite(test) { test.assertExists('.js-publish-button'); test.assertExists('.js-publish-button.button-save'); test.assertSelectorHasText('.js-publish-button', 'Save Draft'); - test.assertEval(function() { + test.assertEval(function () { return (__utils__.findOne('.js-publish-button').getAttribute('data-status') === 'draft'); }, 'Publish button\'s initial status should be "draft"'); }); @@ -183,7 +189,7 @@ CasperTest.begin('Publish menu - existing post', 22, function suite(test) { 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'); - test.assertEval(function() { + test.assertEval(function () { return (__utils__.findOne('.js-publish-button').getAttribute('data-status') === 'published'); }, 'Publish button\'s updated status should be "published"'); }, function onTimeout() { @@ -205,7 +211,7 @@ CasperTest.begin('Publish menu - existing post', 22, function suite(test) { test.assertExists('.js-publish-button'); test.assertExists('.js-publish-button.button-save'); test.assertSelectorHasText('.js-publish-button', 'Update Post'); - test.assertEval(function() { + test.assertEval(function () { return (__utils__.findOne('.js-publish-button').getAttribute('data-status') === 'published'); }, 'Publish button\'s initial status on an already published post should be "published"'); }); @@ -213,14 +219,18 @@ CasperTest.begin('Publish menu - existing post', 22, function suite(test) { // Open the publish options menu casper.thenClick('.js-publish-splitbutton .options.up'); - // Click the 'unpublish' option - casper.thenClick('.js-publish-splitbutton li[data-set-status="draft"]'); + casper.waitForOpaque('.js-publish-splitbutton .editor-options.overlay', function onSuccess() { + // Click the 'unpublish' option + casper.thenClick('.js-publish-splitbutton li[data-set-status="draft"]'); + }, function onTimeout() { + test.assert(false, 'Publish split button menu should have opened'); + }); // ... 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'); - test.assertEval(function() { + test.assertEval(function () { return (__utils__.findOne('.js-publish-button').getAttribute('data-status') === 'draft'); }, 'Publish button\'s updated status should be "draft"'); }, function onTimeout() { diff --git a/core/test/functional/base.js b/core/test/functional/base.js index e9dd04ecc2..46933d131d 100644 --- a/core/test/functional/base.js +++ b/core/test/functional/base.js @@ -1,4 +1,4 @@ -/*globals casper, __utils__ */ +/*globals Ghost, casper, __utils__ */ /** * Casper Tests @@ -71,11 +71,11 @@ casper.on('remote.message', function (msg) { casper.echo('GOT CONSOLE LOG: ' + msg); }); -casper.on('error', function (msg, trace) { +casper.on('error', function (msg) { casper.echo('GOT ERROR, ' + msg); }); -casper.on("page.error", function (msg, trace) { +casper.on("page.error", function (msg) { this.echo("GOT PAGE ERROR: " + msg, "ERROR"); }); @@ -85,7 +85,7 @@ casper.test.on("fail", function captureFailure() { casper.capture(new Date().getTime() + '_' + filename); }); -var CasperTest = (function() { +var CasperTest = (function () { var _beforeDoneHandler, _noop = function noop() { }, @@ -98,7 +98,7 @@ var CasperTest = (function() { casper.thenOpen(url + 'signout/'); casper.waitForResource(/ghost\/sign/); - + casper.run(done); }); @@ -119,7 +119,7 @@ var CasperTest = (function() { _isUserRegistered = true; } - + /* Ensure we're logged out at the start of every test or we may get unexpected failures. */ CasperTest.Routines.logout.run(test); @@ -138,8 +138,7 @@ var CasperTest = (function() { suite = expect; casper.test.begin(testName, runTest); - } - else { + } else { casper.test.begin(testName, expect, runTest); } } @@ -148,8 +147,7 @@ var CasperTest = (function() { function beforeDone(fn) { if (fn) { _beforeDoneHandler = fn; - } - else { + } else { _beforeDoneHandler = _noop; } }