FIX: Selecting categories for new admin webhooks (#26746)

This commit is contained in:
Daniel Waterworth 2024-04-25 09:43:16 -05:00 committed by GitHub
parent 0f2067b363
commit c77d109362
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View File

@ -11,11 +11,15 @@ class WebHookExtras {
@tracked categories; @tracked categories;
constructor(args) { constructor(args) {
this.categories = args.categories; this.categories = args.categories || [];
this.content_types = args.content_types; this.content_types = args.content_types || [];
this.default_event_types = args.default_event_types; this.default_event_types = args.default_event_types || [];
this.delivery_statuses = args.delivery_statuses; this.delivery_statuses = args.delivery_statuses || [];
this.grouped_event_types = args.grouped_event_types; this.grouped_event_types = args.grouped_event_types || [];
}
addCategories(categories) {
this.categories = this.categories.concat(categories).uniqBy((c) => c.id);
} }
get categoriesById() { get categoriesById() {
@ -56,6 +60,9 @@ export default class WebHook extends RestModel {
} }
set categories(value) { set categories(value) {
this.extras ||= new WebHookExtras({});
this.extras.addCategories(value);
this.set( this.set(
"category_ids", "category_ids",
value.map((c) => c.id) value.map((c) => c.id)

View File

@ -5,6 +5,7 @@ import pretender, {
response, response,
} from "discourse/tests/helpers/create-pretender"; } from "discourse/tests/helpers/create-pretender";
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("Admin - Webhooks", function (needs) { acceptance("Admin - Webhooks", function (needs) {
needs.user(); needs.user();
@ -66,8 +67,12 @@ acceptance("Admin - Webhooks", function (needs) {
await click(".admin-webhooks__new-button"); await click(".admin-webhooks__new-button");
await fillIn(`[name="payload-url"`, "https://example.com/webhook"); await fillIn(`[name="payload-url"`, "https://example.com/webhook");
await click(".admin-webhooks__save-button");
const categorySelector = selectKit(".category-selector");
await categorySelector.expand();
categorySelector.selectRowByName("support");
await click(".admin-webhooks__save-button");
assert.strictEqual(currentURL(), "/admin/api/web_hooks/1"); assert.strictEqual(currentURL(), "/admin/api/web_hooks/1");
}); });
}); });