Remove some preferences views, add extra tests

This commit is contained in:
Robin Ward 2016-11-10 15:54:21 -05:00
parent a94f06ff78
commit d98aa48f0d
8 changed files with 61 additions and 70 deletions

View File

@ -205,6 +205,10 @@ export default Ember.Component.extend({
_readyNow() { _readyNow() {
this.set('ready', true); this.set('ready', true);
if (this.get('autofocus')) {
this.$('textarea').focus();
}
}, },
init() { init() {

View File

@ -39,18 +39,19 @@ export default Ember.Controller.extend({
}.property('saving'), }.property('saving'),
actions: { actions: {
changeUsername: function() { changeUsername() {
var self = this; if (this.get('saveDisabled')) { return; }
return bootbox.confirm(I18n.t("user.change_username.confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
return bootbox.confirm(I18n.t("user.change_username.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"), result => {
if (result) { if (result) {
self.set('saving', true); this.set('saving', true);
self.get('content').changeUsername(self.get('newUsername')).then(function() { this.get('content').changeUsername(this.get('newUsername')).then(() => {
DiscourseURL.redirectTo("/users/" + self.get('newUsername').toLowerCase() + "/preferences"); DiscourseURL.redirectTo("/users/" + this.get('newUsername').toLowerCase() + "/preferences");
}, function() { })
// error .catch(() => this.set('error', true))
self.set('error', true); .finally(() => this.set('saving', false));
self.set('saving', false);
});
} }
}); });
} }

View File

@ -0,0 +1,25 @@
<div class="user-preferences">
<form class="form-horizontal">
<div class="control-group">
<div class="controls">
<h3>{{i18n 'user.change_about.title'}}</h3>
</div>
</div>
<div class="control-group">
<label class="control-label">{{i18n 'user.bio'}}</label>
<div class="controls">
{{d-editor value=model.bio_raw class="raw-bio" autofocus="autofocus"}}
</div>
</div>
<div class="control-group">
<div class="controls">
{{#d-button action="changeAbout" class="btn btn-primary"}}
{{saveButtonText}}
{{/d-button}}
</div>
</div>
</form>
</div>

View File

@ -18,13 +18,15 @@
<div class="control-group"> <div class="control-group">
<label class="control-label">{{i18n 'user.username.title'}}</label> <label class="control-label">{{i18n 'user.username.title'}}</label>
<div class="controls"> <div class="controls">
{{text-field value=newUsername id="change_username" classNames="input-xxlarge" maxlength=maxLength}} {{text-field value=newUsername id="change_username" classNames="input-xxlarge" maxlength=maxLength autofocus="autofocus" insert-newline="changeUsername"}}
</div> </div>
<div class='instructions'> <div class='instructions controls'>
<p>
{{#if taken}} {{#if taken}}
{{i18n 'user.change_username.taken'}} {{i18n 'user.change_username.taken'}}
{{/if}} {{/if}}
<span>{{ errorMessage }}</span> <span>{{errorMessage}}</span>
</p>
</div> </div>
</div> </div>

View File

@ -1,24 +0,0 @@
<form class="form-horizontal">
<div class="control-group">
<div class="controls">
<h3>{{i18n 'user.change_about.title'}}</h3>
</div>
</div>
<div class="control-group">
<label class="control-label">{{i18n 'user.bio'}}</label>
<div class="controls">
{{d-editor value=model.bio_raw}}
</div>
</div>
<div class="control-group">
<div class="controls">
{{#d-button action="changeAbout" class="btn btn-primary"}}
{{saveButtonText}}
{{/d-button}}
</div>
</div>
</form>

View File

@ -1,11 +0,0 @@
export default Ember.View.extend({
templateName: 'user/about',
classNames: ['user-preferences'],
_focusAbout: function() {
var self = this;
Ember.run.schedule('afterRender', function() {
self.$('textarea').focus();
});
}.on('didInsertElement')
});

View File

@ -1,21 +0,0 @@
export default Ember.View.extend({
templateName: 'user/username',
classNames: ['user-preferences'],
_focusUsername: function() {
Em.run.schedule('afterRender', function() {
$('#change_username').focus();
});
}.on('didInsertElement'),
keyDown: function(e) {
if (e.keyCode === 13) {
if (!this.get('controller').get('saveDisabled')) {
return this.get('controller').send('changeUsername');
} else {
e.preventDefault();
return false;
}
}
}
});

View File

@ -18,3 +18,18 @@ test("update some fields", () => {
ok(exists('.saved-user'), 'it displays the saved message'); ok(exists('.saved-user'), 'it displays the saved message');
}); });
}); });
test("about me", () => {
visit("/users/eviltrout/preferences/username");
andThen(() => {
ok(exists("#change_username"), "it has the input element for the bio");
});
});
test("username", () => {
visit("/users/eviltrout/preferences/about-me");
andThen(() => {
ok(exists(".raw-bio"), "it has the input element for the bio");
});
});