Adds acceptance test for user preferences

This commit is contained in:
Robin Ward 2015-05-13 10:42:36 -04:00
parent d90e0fe66b
commit ea51095ef9
7 changed files with 50 additions and 8 deletions

View File

@ -1,6 +1,7 @@
// A base route that allows us to redirect when access is restricted import DiscourseRoute from 'discourse/routes/discourse';
export default Discourse.Route.extend({ // A base route that allows us to redirect when access is restricted
export default DiscourseRoute.extend({
afterModel() { afterModel() {
if (!this.modelFor('user').get('can_edit')) { if (!this.modelFor('user').get('can_edit')) {

View File

@ -1,4 +1,4 @@
<section class='user-content'> <section class='user-content user-preferences'>
<form class="form-horizontal"> <form class="form-horizontal">
@ -154,7 +154,7 @@
<div class="control-group pref-location"> <div class="control-group pref-location">
<label class="control-label">{{i18n 'user.location'}}</label> <label class="control-label">{{i18n 'user.location'}}</label>
<div class="controls"> <div class="controls">
{{input type="text" value=location class="input-xxlarge"}} {{input type="text" value=location class="input-xxlarge" id='edit-location'}}
</div> </div>
</div> </div>

View File

@ -1,2 +1,4 @@
<button {{action "save"}} {{bind-attr disabled="saving"}} class="btn btn-primary">{{saveButtonText}}</button> <button {{action "save"}} {{bind-attr disabled="saving"}} class="btn btn-primary save-user">{{saveButtonText}}</button>
{{#if saved}}{{i18n 'saved'}}{{/if}} {{#if saved}}
<span class='saved-user'>{{i18n 'saved'}}</span>
{{/if}}

View File

@ -39,3 +39,11 @@ test("Filters", () => {
visit("/users/eviltrout/activity/edits"); visit("/users/eviltrout/activity/edits");
hasStream(); hasStream();
}); });
test("Restricted Routes", () => {
visit("/users/eviltrout/preferences");
andThen(() => {
equal(currentURL(), '/users/eviltrout/activity', "it redirects from preferences");
});
});

View File

@ -0,0 +1,19 @@
import { acceptance } from "helpers/qunit-helpers";
acceptance("User Preferences", { loggedIn: true });
test("update some fields", () => {
visit("/users/eviltrout/preferences");
andThen(() => {
equal(currentURL(), '/users/eviltrout/preferences', "it doesn't redirect");
ok(exists('.user-preferences'), 'it shows the preferences');
});
fillIn("#edit-location", "Westeros");
click('.save-user');
ok(!exists('.saved-user'), "it hasn't been saved yet");
andThen(() => {
ok(exists('.saved-user'), 'it displays the saved message');
});
});

File diff suppressed because one or more lines are too long

View File

@ -87,6 +87,18 @@ export default function() {
return response(json); return response(json);
}); });
this.get('/users/eviltrout.json', () => {
const json = fixturesByUrl['/users/eviltrout.json'];
if (loggedIn()) {
json.user.can_edit = true;
}
return response(json);
});
this.put('/users/eviltrout', () => {
return response({ user: {} });
});
this.get("/t/280.json", function() { this.get("/t/280.json", function() {
return response(fixturesByUrl['/t/280/1.json']); return response(fixturesByUrl['/t/280/1.json']);
}); });