diff --git a/app/assets/javascripts/admin/routes/admin-user-index.js.es6 b/app/assets/javascripts/admin/routes/admin-user-index.js.es6 index e2951ff2d80..6767e098b2e 100644 --- a/app/assets/javascripts/admin/routes/admin-user-index.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-user-index.js.es6 @@ -19,6 +19,7 @@ export default Discourse.Route.extend({ controller.setProperties({ originalPrimaryGroupId: model.get("primary_group_id"), availableGroups: this._availableGroups, + customGroupIdsBuffer: null, model }); } diff --git a/test/javascripts/acceptance/admin-user-index-test.js.es6 b/test/javascripts/acceptance/admin-user-index-test.js.es6 index 0e8ee0c6616..36e773f0a30 100644 --- a/test/javascripts/acceptance/admin-user-index-test.js.es6 +++ b/test/javascripts/acceptance/admin-user-index-test.js.es6 @@ -1,6 +1,37 @@ import { acceptance } from "helpers/qunit-helpers"; -acceptance("Admin - User Index", { loggedIn: true }); +acceptance("Admin - User Index", { + loggedIn: true, + pretend(server, helper) { + server.get("/groups/search.json", () => { + return helper.response([ + { + id: 42, + automatic: false, + name: "Macdonald", + user_count: 0, + alias_level: 99, + visible: true, + automatic_membership_email_domains: "", + automatic_membership_retroactive: false, + primary_group: false, + title: null, + grant_trust_level: null, + has_messages: false, + flair_url: null, + flair_bg_color: null, + flair_color: null, + bio_raw: null, + bio_cooked: null, + public_admission: false, + allow_membership_requests: true, + membership_request_template: "Please add me", + full_name: null + } + ]); + }); + } +}); QUnit.test("can edit username", async assert => { /* global server */ @@ -41,3 +72,41 @@ QUnit.test("can edit username", async assert => { "new-sam" ); }); + +QUnit.test("will clear unsaved groups when switching user", async assert => { + await visit("/admin/users/2/sam"); + + assert.equal( + find(".display-row.username .value") + .text() + .trim(), + "sam", + "the name should be correct" + ); + + await fillIn(".admin-group-selector .filter-input", "Macdonald"); + await click(".admin-group-selector .filter-input"); + await keyEvent(".admin-group-selector .filter-input", "keydown", 13); + + assert.equal( + find('.admin-group-selector span[title="Macdonald"]').length, + 1, + "group should be set" + ); + + await visit("/admin/users/1/eviltrout"); + + assert.equal( + find(".display-row.username .value") + .text() + .trim(), + "eviltrout", + "the name should be correct" + ); + + assert.equal( + find('.admin-group-selector span[title="Macdonald"]').length, + 0, + "group should not be set" + ); +}); diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6 index 08f530d839a..ab9b6a6b7dd 100644 --- a/test/javascripts/helpers/create-pretender.js.es6 +++ b/test/javascripts/helpers/create-pretender.js.es6 @@ -528,6 +528,14 @@ export default function() { }); }); + this.get("/admin/users/1.json", () => { + return response(200, { + id: 1, + username: "eviltrout", + admin: true + }); + }); + this.get("/admin/users/2.json", () => { return response(200, { id: 2,