mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Fix unwanted clearing of social inputs on blur with no edits
no issue - updates the logic to expect `null` scratch values as the scratch values won't be set until the input value has changed - adds tests for initial value display and regression tests for the cleared input bug
This commit is contained in:
parent
01e52013e7
commit
64a85ced32
5 changed files with 101 additions and 8 deletions
|
@ -125,13 +125,18 @@ export default Controller.extend(SettingsSaveMixin, {
|
|||
let oldUrl = this.get('model.facebook');
|
||||
let errMessage = '';
|
||||
|
||||
if (!newUrl) {
|
||||
if (newUrl === '') {
|
||||
// Clear out the Facebook url
|
||||
this.set('model.facebook', '');
|
||||
this.get('model.errors').remove('facebook');
|
||||
return;
|
||||
}
|
||||
|
||||
// _scratchFacebook will be null unless the user has input something
|
||||
if (!newUrl) {
|
||||
newUrl = oldUrl;
|
||||
}
|
||||
|
||||
// If new url didn't change, exit
|
||||
if (newUrl === oldUrl) {
|
||||
this.get('model.errors').remove('facebook');
|
||||
|
@ -187,13 +192,18 @@ export default Controller.extend(SettingsSaveMixin, {
|
|||
let oldUrl = this.get('model.twitter');
|
||||
let errMessage = '';
|
||||
|
||||
if (!newUrl) {
|
||||
// Clear out the Facebook url
|
||||
if (newUrl === '') {
|
||||
// Clear out the Twitter url
|
||||
this.set('model.twitter', '');
|
||||
this.get('model.errors').remove('twitter');
|
||||
return;
|
||||
}
|
||||
|
||||
// _scratchTwitter will be null unless the user has input something
|
||||
if (!newUrl) {
|
||||
newUrl = oldUrl;
|
||||
}
|
||||
|
||||
// If new url didn't change, exit
|
||||
if (newUrl === oldUrl) {
|
||||
this.get('model.errors').remove('twitter');
|
||||
|
|
|
@ -249,13 +249,18 @@ export default Controller.extend({
|
|||
let oldUrl = this.get('user.facebook');
|
||||
let errMessage = '';
|
||||
|
||||
if (!newUrl) {
|
||||
if (newUrl === '') {
|
||||
// Clear out the Facebook url
|
||||
this.set('user.facebook', '');
|
||||
this.get('user.errors').remove('facebook');
|
||||
return;
|
||||
}
|
||||
|
||||
// _scratchFacebook will be null unless the user has input something
|
||||
if (!newUrl) {
|
||||
newUrl = oldUrl;
|
||||
}
|
||||
|
||||
// If new url didn't change, exit
|
||||
if (newUrl === oldUrl) {
|
||||
this.get('user.errors').remove('facebook');
|
||||
|
@ -313,13 +318,18 @@ export default Controller.extend({
|
|||
let oldUrl = this.get('user.twitter');
|
||||
let errMessage = '';
|
||||
|
||||
if (!newUrl) {
|
||||
if (newUrl === '') {
|
||||
// Clear out the Twitter url
|
||||
this.set('user.twitter', '');
|
||||
this.get('user.errors').remove('twitter');
|
||||
return;
|
||||
}
|
||||
|
||||
// _scratchTwitter will be null unless the user has input something
|
||||
if (!newUrl) {
|
||||
newUrl = oldUrl;
|
||||
}
|
||||
|
||||
// If new url didn't change, exit
|
||||
if (newUrl === oldUrl) {
|
||||
this.get('user.errors').remove('twitter');
|
||||
|
|
|
@ -188,7 +188,7 @@ export default [
|
|||
updated_at: '2016-05-08T15:20:25.953Z',
|
||||
updated_by: 1,
|
||||
uuid: 'd4387e5c-3230-46dd-a89b-0d8a40365c35',
|
||||
value: ''
|
||||
value: 'test'
|
||||
},
|
||||
{
|
||||
created_at: '2016-05-05T15:40:12.134Z',
|
||||
|
@ -199,7 +199,7 @@ export default [
|
|||
updated_at: '2016-05-08T15:20:25.954Z',
|
||||
updated_by: 1,
|
||||
uuid: '5130441f-e4c7-4750-9692-a22d841ab049',
|
||||
value: ''
|
||||
value: '@test'
|
||||
},
|
||||
{
|
||||
key: 'availableThemes',
|
||||
|
|
|
@ -163,6 +163,23 @@ describe('Acceptance: Settings - General', function () {
|
|||
});
|
||||
|
||||
// validates a facebook url correctly
|
||||
|
||||
andThen(() => {
|
||||
// loads fixtures and performs transform
|
||||
expect(find('input[name="general[facebook]"]').val(), 'initial facebook value')
|
||||
.to.equal('https://www.facebook.com/test');
|
||||
});
|
||||
|
||||
triggerEvent('#settings-general input[name="general[facebook]"]', 'focus');
|
||||
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
|
||||
|
||||
andThen(() => {
|
||||
// regression test: we still have a value after the input is
|
||||
// focused and then blurred without any changes
|
||||
expect(find('input[name="general[facebook]"]').val(), 'facebook value after blur with no change')
|
||||
.to.equal('https://www.facebook.com/test');
|
||||
});
|
||||
|
||||
fillIn('#settings-general input[name="general[facebook]"]', 'facebook.com/username');
|
||||
triggerEvent('#settings-general input[name="general[facebook]"]', 'blur');
|
||||
|
||||
|
@ -243,6 +260,23 @@ describe('Acceptance: Settings - General', function () {
|
|||
});
|
||||
|
||||
// validates a twitter url correctly
|
||||
|
||||
andThen(() => {
|
||||
// loads fixtures and performs transform
|
||||
expect(find('input[name="general[twitter]"]').val(), 'initial twitter value')
|
||||
.to.equal('https://twitter.com/test');
|
||||
});
|
||||
|
||||
triggerEvent('#settings-general input[name="general[twitter]"]', 'focus');
|
||||
triggerEvent('#settings-general input[name="general[twitter]"]', 'blur');
|
||||
|
||||
andThen(() => {
|
||||
// regression test: we still have a value after the input is
|
||||
// focused and then blurred without any changes
|
||||
expect(find('input[name="general[twitter]"]').val(), 'twitter value after blur with no change')
|
||||
.to.equal('https://twitter.com/test');
|
||||
});
|
||||
|
||||
fillIn('#settings-general input[name="general[twitter]"]', 'twitter.com/username');
|
||||
triggerEvent('#settings-general input[name="general[twitter]"]', 'blur');
|
||||
|
||||
|
|
|
@ -239,7 +239,12 @@ describe('Acceptance: Team', function () {
|
|||
let user;
|
||||
|
||||
beforeEach(function () {
|
||||
server.create('user', {slug: 'test-1', name: 'Test User'});
|
||||
server.create('user', {
|
||||
slug: 'test-1',
|
||||
name: 'Test User',
|
||||
facebook: 'test',
|
||||
twitter: '@test'
|
||||
});
|
||||
|
||||
server.loadFixtures();
|
||||
});
|
||||
|
@ -314,6 +319,23 @@ describe('Acceptance: Team', function () {
|
|||
});
|
||||
|
||||
// Testing Facebook input
|
||||
|
||||
andThen(() => {
|
||||
// displays initial value
|
||||
expect(find('#user-facebook').val(), 'initial facebook value')
|
||||
.to.equal('https://www.facebook.com/test');
|
||||
});
|
||||
|
||||
triggerEvent('#user-facebook', 'focus');
|
||||
triggerEvent('#user-facebook', 'blur');
|
||||
|
||||
andThen(() => {
|
||||
// regression test: we still have a value after the input is
|
||||
// focused and then blurred without any changes
|
||||
expect(find('#user-facebook').val(), 'facebook value after blur with no change')
|
||||
.to.equal('https://www.facebook.com/test');
|
||||
});
|
||||
|
||||
fillIn('#user-facebook', '');
|
||||
fillIn('#user-facebook', ')(*&%^%)');
|
||||
triggerEvent('#user-facebook', 'blur');
|
||||
|
@ -376,6 +398,23 @@ describe('Acceptance: Team', function () {
|
|||
});
|
||||
|
||||
// Testing Twitter input
|
||||
|
||||
andThen(() => {
|
||||
// loads fixtures and performs transform
|
||||
expect(find('#user-twitter').val(), 'initial twitter value')
|
||||
.to.equal('https://twitter.com/test');
|
||||
});
|
||||
|
||||
triggerEvent('#user-twitter', 'focus');
|
||||
triggerEvent('#user-twitter', 'blur');
|
||||
|
||||
andThen(() => {
|
||||
// regression test: we still have a value after the input is
|
||||
// focused and then blurred without any changes
|
||||
expect(find('#user-twitter').val(), 'twitter value after blur with no change')
|
||||
.to.equal('https://twitter.com/test');
|
||||
});
|
||||
|
||||
fillIn('#user-twitter', '');
|
||||
fillIn('#user-twitter', ')(*&%^%)');
|
||||
triggerEvent('#user-twitter', 'blur');
|
||||
|
|
Loading…
Add table
Reference in a new issue