From c4fb17d2d7f1fdd5003c5ef54f39ee020e86e60c Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Tue, 12 Aug 2014 17:00:09 +0000 Subject: [PATCH] Reset slug input text box after invalid input. No Issue - When an invalid, all whitespace slug is entered into the slug input in the post settings menu, it's rejected but the input's value still remains the same. This resets the input back to its original value. - Added test for the above behavior. - Only show success notification if slug was actually changed. - Convert whitespace from tabs to spaces in post-settings-menu.hbs --- core/client/controllers/post-settings-menu.js | 11 ++++- core/test/functional/client/psm_test.js | 42 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/core/client/controllers/post-settings-menu.js b/core/client/controllers/post-settings-menu.js index b20c5442af..de8e094c02 100644 --- a/core/client/controllers/post-settings-menu.js +++ b/core/client/controllers/post-settings-menu.js @@ -152,6 +152,9 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ // Ignore unchanged slugs or candidate slugs that are empty if (!newSlug || slug === newSlug) { + // reset the input to its previous state + this.set('slugValue', slug); + return; } @@ -176,6 +179,8 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ // for the incrementor then the existing slug should be used if (_.isNumber(check) && check > 0) { if (slug === slugTokens.join('-') && serverSlug !== newSlug) { + self.set('slugValue', slug); + return; } } @@ -193,9 +198,11 @@ var PostSettingsMenuController = Ember.ObjectController.extend({ } return self.get('model').save(self.get('saveOptions')); - }).then(function () { - self.showSuccess('Permalink successfully changed to ' + + }).then(function (changed) { + if (changed) { + self.showSuccess('Permalink successfully changed to ' + self.get('slug') + '.'); + } }).catch(function (errors) { self.showErrors(errors); self.get('model').rollback(); diff --git a/core/test/functional/client/psm_test.js b/core/test/functional/client/psm_test.js index 8b70c7e361..ec23ca4bcb 100644 --- a/core/test/functional/client/psm_test.js +++ b/core/test/functional/client/psm_test.js @@ -225,4 +225,46 @@ CasperTest.begin('Post can be changed to static page', 6, function suite(test) { test.assertDoesntExist('.post-setting-static-page:checked', 'can turn off static page'); }); +}); + +CasperTest.begin('Post url input is reset from all whitespace back to original value', 3, function suite(test) { + // Create a sample post + CasperTest.Routines.createTestPost.run(false); + + // Begin test + casper.thenOpenAndWaitForPageLoad('content', function testTitleAndUrl() { + test.assertTitle('Ghost Admin', 'Title is "Ghost Admin"'); + test.assertUrlMatch(/ghost\/\d+\/$/, 'Landed on the correct URL'); + }); + + // Transition to the editor + casper.thenClick('.post-edit'); + casper.waitForSelector('#entry-title'); + + casper.thenClick('.post-settings'); + casper.waitForOpaque('.post-settings-menu.open'); + + var originalSlug; + casper.then(function () { + originalSlug = casper.evaluate(function () { + return __utils__.getFieldValue('post-setting-slug'); + }); + }); + + // Test change permalink + casper.then(function () { + this.fillSelectors('.post-settings-menu form', { + '#url': ' ' + }, false); + + this.click('button.post-settings'); + }); + + casper.then(function checkValueMatches() { + //using assertField(name) checks the htmls initial "value" attribute, so have to hack around it. + var slugVal = this.evaluate(function () { + return __utils__.getFieldValue('post-setting-slug'); + }); + test.assertEqual(slugVal, originalSlug); + }); }); \ No newline at end of file