Refactor and add tests for category editing

This commit is contained in:
Robin Ward
2015-07-02 12:06:24 -04:00
parent 2d2e2b9924
commit 23daa9d8ce
6 changed files with 37 additions and 14 deletions

View File

@@ -2,7 +2,7 @@ import { acceptance } from "helpers/qunit-helpers";
acceptance("Category Edit", { loggedIn: true });
test("Can edit a category", (assert) => {
test("Can open the category modal", (assert) => {
visit("/c/bug");
click('.edit-category');
@@ -15,3 +15,15 @@ test("Can edit a category", (assert) => {
assert.ok(!visible('#discourse-modal'), 'it closes the modal');
});
});
test("Change the category color", (assert) => {
visit("/c/bug");
click('.edit-category');
fillIn('#edit-text-color', '#ff0000');
click('#save-category');
andThen(() => {
assert.ok(!visible('#discourse-modal'), 'it closes the modal');
assert.equal(Discourse.URL.redirectedTo, '/c/bug', 'it does one of the rare full page redirects');
});
});

View File

@@ -119,6 +119,11 @@ export default function() {
this.get('/users/:username/staff-info.json', () => response({}));
this.put('/categories/:category_id', function(request) {
const category = parsePostData(request.requestBody);
return response({category});
});
this.get('/draft.json', function() {
return response({});
});

View File

@@ -90,6 +90,12 @@ QUnit.testStart(function(ctx) {
Discourse.BaseUrl = "localhost";
Discourse.User.resetCurrent();
Discourse.Site.resetCurrent(Discourse.Site.create(fixtures['site.json'].site));
Discourse.URL.redirectedTo = null;
Discourse.URL.redirectTo = function(url) {
Discourse.URL.redirectedTo = url;
};
PreloadStore.reset();
window.sandbox = sinon.sandbox.create();