A platform for community discussion. Free, open, simple.
DEV: Add `create-topic-button-click` behavior transformer (#43142)
Gabriel Grubba8e250d40b05c
diff --git a/frontend/discourse/app/components/d-navigation.gjs b/frontend/discourse/app/components/d-navigation.gjsindex b2ec93cfbf9..52ad2499f09 100644--- a/frontend/discourse/app/components/d-navigation.gjs+++ b/frontend/discourse/app/components/d-navigation.gjs@@ -17,7 +17,10 @@ import TopicDismissButtons from "discourse/components/topic-dismiss-buttons";import lazyHash from "discourse/helpers/lazy-hash";import { filterTypeForMode } from "discourse/lib/filter-mode";import { NotificationLevels } from "discourse/lib/notification-levels";-import { applyValueTransformer } from "discourse/lib/transformer";+import {+ applyBehaviorTransformer,+ applyValueTransformer,+} from "discourse/lib/transformer";import NavItem from "discourse/models/nav-item";import CategoriesAdminDropdown from "discourse/select-kit/components/categories-admin-dropdown";import TagCategoryAdminDropdown from "discourse/select-kit/components/tag-category-admin-dropdown";@@ -272,7 +275,11 @@ export default class DNavigation extends Component {@actionclickCreateTopicButton() {- this.createTopic();+ applyBehaviorTransformer(+ "create-topic-button-click",+ () => this.createTopic(),+ { category: this.category, tag: this.tag }+ );}@actiondiff --git a/frontend/discourse/app/lib/registry/transformers.js b/frontend/discourse/app/lib/registry/transformers.jsindex 71cb5fd873b..a065fcb42c1 100644--- a/frontend/discourse/app/lib/registry/transformers.js+++ b/frontend/discourse/app/lib/registry/transformers.js@@ -19,6 +19,7 @@ export const BEHAVIOR_TRANSFORMERS = Object.freeze(["composer-position:correct-scroll-position","composer-position:editor-touch-move","create-account",+ "create-topic-button-click","custom-homepage-model","discovery-topic-list-load-more","full-page-search-load-more",diff --git a/frontend/discourse/tests/acceptance/create-topic-button-click-test.js b/frontend/discourse/tests/acceptance/create-topic-button-click-test.jsnew file mode 100644index 00000000000..a559a0f26ce--- /dev/null+++ b/frontend/discourse/tests/acceptance/create-topic-button-click-test.js@@ -0,0 +1,43 @@+import { click, visit } from "@ember/test-helpers";+import { test } from "qunit";+import { withPluginApi } from "discourse/lib/plugin-api";+import { acceptance } from "discourse/tests/helpers/qunit-helpers";++acceptance("Create topic button click transformer", function (needs) {+ needs.user();++ test("a behavior transformer can take over the click", async function (assert) {+ withPluginApi((api) => {+ api.registerBehaviorTransformer(+ "create-topic-button-click",+ ({ context }) => {+ assert.step(`intercepted:${context.category?.slug}`);+ }+ );+ });++ await visit("/c/bug/1");+ await click("#create-topic");++ assert.verifySteps(["intercepted:bug"]);+ assert.dom("#reply-control.open").doesNotExist("the composer stays closed");+ });++ test("calling next keeps the default composer behaviour", async function (assert) {+ withPluginApi((api) => {+ api.registerBehaviorTransformer(+ "create-topic-button-click",+ ({ next }) => {+ assert.step("passed through");+ next();+ }+ );+ });++ await visit("/c/bug/1");+ await click("#create-topic");++ assert.verifySteps(["passed through"]);+ assert.dom("#reply-control.open").exists("the composer opens");+ });+});