FIX: Only assign when suggestion is clicked (#334)
This commit is contained in:
parent
4065b29f69
commit
6db2e0991b
|
@ -90,6 +90,24 @@ export default Controller.extend({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setGroupOrUser(name);
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
return this.assign();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
@action
|
||||||
|
assignUsername(selected) {
|
||||||
|
if (this.isBulkAction) {
|
||||||
|
this.bulkAction(selected.firstObject);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setGroupOrUser(selected.firstObject);
|
||||||
|
},
|
||||||
|
|
||||||
|
setGroupOrUser(name) {
|
||||||
if (this.allowedGroupsForAssignment.includes(name)) {
|
if (this.allowedGroupsForAssignment.includes(name)) {
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
"model.username": null,
|
"model.username": null,
|
||||||
|
@ -103,14 +121,5 @@ export default Controller.extend({
|
||||||
"model.allowedGroups": this.taskActions.allowedGroups,
|
"model.allowedGroups": this.taskActions.allowedGroups,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name) {
|
|
||||||
return this.assign();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
@action
|
|
||||||
assignUsername(selected) {
|
|
||||||
this.assignUser(selected.firstObject);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,37 +2,9 @@ import EmberObject from "@ember/object";
|
||||||
import pretender from "discourse/tests/helpers/create-pretender";
|
import pretender from "discourse/tests/helpers/create-pretender";
|
||||||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { Promise } from "rsvp";
|
|
||||||
|
|
||||||
discourseModule("Unit | Controller | assign-user", function () {
|
discourseModule("Unit | Controller | assign-user", function () {
|
||||||
test("doesn't set suggestions and fails gracefully if controller is destroyed", function (assert) {
|
test("assigning a user via suggestions makes API call and closes the modal", function (assert) {
|
||||||
let resolveSuggestions;
|
|
||||||
pretender.get("/assign/suggestions", () => {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
resolveSuggestions = resolve;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
const controller = this.getController("assign-user", {
|
|
||||||
model: {
|
|
||||||
target: EmberObject.create({}),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
controller.destroy();
|
|
||||||
resolveSuggestions([
|
|
||||||
200,
|
|
||||||
{ "Content-Type": "application/json" },
|
|
||||||
{
|
|
||||||
suggestions: [],
|
|
||||||
assign_allowed_on_groups: ["nat"],
|
|
||||||
assign_allowed_for_groups: [],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
assert.strictEqual(controller.get("assign_allowed_on_groups"), undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("assigning a user closes the modal", function (assert) {
|
|
||||||
pretender.get("/assign/suggestions", () => {
|
pretender.get("/assign/suggestions", () => {
|
||||||
return [
|
return [
|
||||||
200,
|
200,
|
||||||
|
@ -64,4 +36,34 @@ discourseModule("Unit | Controller | assign-user", function () {
|
||||||
|
|
||||||
assert.strictEqual(modalClosed, true);
|
assert.strictEqual(modalClosed, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("assigning a user by selector does not close the modal", function (assert) {
|
||||||
|
pretender.get("/assign/suggestions", () => {
|
||||||
|
return [
|
||||||
|
200,
|
||||||
|
{ "Content-Type": "application/json" },
|
||||||
|
{
|
||||||
|
suggestions: [],
|
||||||
|
assign_allowed_on_groups: ["nat"],
|
||||||
|
assign_allowed_for_groups: [],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
let modalClosed = false;
|
||||||
|
const controller = this.getController("assign-user", {
|
||||||
|
model: {
|
||||||
|
target: EmberObject.create({}),
|
||||||
|
},
|
||||||
|
allowedGroupsForAssignment: ["nat"],
|
||||||
|
taskActions: { allowedGroups: [] },
|
||||||
|
});
|
||||||
|
controller.set("actions.closeModal", () => {
|
||||||
|
modalClosed = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.send("assignUsername", "nat");
|
||||||
|
|
||||||
|
assert.strictEqual(modalClosed, false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue