A platform for community discussion. Free, open, simple.
DEV: Convert 10 components to glimmer (#44592)
Jarek Radosz4c210a955ed7
diff --git a/frontend/discourse/app/components/composer-action-title.gjs b/frontend/discourse/app/components/composer-action-title.gjsindex aa529850120..c50864e1b3a 100644--- a/frontend/discourse/app/components/composer-action-title.gjs+++ b/frontend/discourse/app/components/composer-action-title.gjs@@ -1,34 +1,31 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";-import { action, computed } from "@ember/object";+import Component from "@glimmer/component";+import { action, get } from "@ember/object";import { service } from "@ember/service";import { trustHTML } from "@ember/template";-import { tagName } from "@ember-decorators/component";import ComposerActions from "discourse/components/composer-actions";import escape from "discourse/lib/escape";import { iconHTML } from "discourse/lib/icon-library";import { EDIT } from "discourse/models/composer";import DButton from "discourse/ui-kit/d-button";-@tagName("")export default class ComposerActionTitle extends Component {@service composer;- @computed("model.replyOptions")get options() {- return this.model?.replyOptions;+ return this.args.model?.replyOptions;}- @computed("model.action", "model.post.can_edit", "model.topic")get canEditReplyTo() {+ const model = this.args.model;+ if (!model) {+ return false;+ }+return (- this.model?.action === EDIT &&- !!this.model?.post?.can_edit &&- !!this.model?.topic+ get(model, "action") === EDIT && !!model.post?.can_edit && !!model.topic);}- @computed("options.originalUser")get replyTargetSegment() {const originalUser = this.options?.originalUser;if (!originalUser) {@@ -50,11 +47,11 @@ export default class ComposerActionTitle extends Component {<div class="composer-action-title" ...attributes><span aria-level="1" class="action-title" role="heading"><ComposerActions- @action={{this.model.action}}- @composerModel={{this.model}}- @post={{this.model.post}}- @replyOptions={{this.model.replyOptions}}- @topic={{this.model.topic}}+ @action={{@model.action}}+ @composerModel={{@model}}+ @post={{@model.post}}+ @replyOptions={{@model.replyOptions}}+ @topic={{@model.topic}}/>{{#if this.replyTargetSegment}}diff --git a/frontend/discourse/app/components/login-buttons.gjs b/frontend/discourse/app/components/login-buttons.gjsindex 8826ff0ae3d..df7f6f77f4a 100644--- a/frontend/discourse/app/components/login-buttons.gjs+++ b/frontend/discourse/app/components/login-buttons.gjs@@ -1,9 +1,8 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";+import Component from "@glimmer/component";+import { cached } from "@glimmer/tracking";import { fn } from "@ember/helper";import { on } from "@ember/modifier";-import { computed } from "@ember/object";-import { tagName } from "@ember-decorators/component";+import { service } from "@ember/service";import GoogleIcon from "discourse/components/google-icon";import PasskeyLoginButton from "discourse/components/passkey-login-button";import PluginOutlet from "discourse/components/plugin-outlet";@@ -13,33 +12,31 @@ import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";import dIcon from "discourse/ui-kit/helpers/d-icon";import { i18n } from "discourse-i18n";-@tagName("")export default class LoginButtons extends Component {- @computed("buttons.length", "showLoginWithEmailLink", "showPasskeysButton")+ @service siteSettings;+get hidden() {return (this.buttons?.length === 0 &&- !this.showLoginWithEmailLink &&+ !this.args.showLoginWithEmailLink &&!this.showPasskeysButton);}- @computed("buttons.length")get multiple() {return this.buttons?.length > 1;}- @computed+ @cachedget buttons() {return findAll();}- @computedget showPasskeysButton() {return (this.siteSettings.enable_local_logins &&this.siteSettings.enable_passkeys &&- this.context === "login" &&+ this.args.context === "login" &&isWebauthnSupported());}@@ -60,7 +57,7 @@ export default class LoginButtons extends Component {aria-label={{b.screenReaderTitle}}class="btn btn-social {{b.name}}"type="button"- {{on "click" (fn this.externalLogin b)}}+ {{on "click" (fn @externalLogin b)}}>{{dIcon b.icon}}<span class="btn-social-title">{{b.title}}</span>@@ -79,7 +76,7 @@ export default class LoginButtons extends Component {aria-label={{b.screenReaderTitle}}class="btn btn-social {{b.name}}"type="button"- {{on "click" (fn this.externalLogin b)}}+ {{on "click" (fn @externalLogin b)}}>{{#if b.isGoogle}}<GoogleIcon />@@ -94,7 +91,7 @@ export default class LoginButtons extends Component {{{/each}}{{#if this.showPasskeysButton}}- <PasskeyLoginButton @passkeyLogin={{this.passkeyLogin}} />+ <PasskeyLoginButton @passkeyLogin={{@passkeyLogin}} />{{/if}}<PluginOutlet @name="after-login-buttons" />diff --git a/frontend/discourse/app/components/reviewable-field-editor.gjs b/frontend/discourse/app/components/reviewable-field-editor.gjsindex 66a10edab89..fbf6b8210dd 100644--- a/frontend/discourse/app/components/reviewable-field-editor.gjs+++ b/frontend/discourse/app/components/reviewable-field-editor.gjs@@ -1,11 +1,7 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";-import { tagName } from "@ember-decorators/component";import DEditor from "discourse/ui-kit/d-editor";-@tagName("")-export default class ReviewableFieldEditor extends Component {- <template>- <DEditor @change={{this.valueChanged}} @value={{this.value}} />- </template>-}+const ReviewableFieldEditor = <template>+ <DEditor @change={{@valueChanged}} @value={{@value}} />+</template>;++export default ReviewableFieldEditor;diff --git a/frontend/discourse/app/components/reviewable-field-text.gjs b/frontend/discourse/app/components/reviewable-field-text.gjsindex 37d2bd297e7..87ac53133a8 100644--- a/frontend/discourse/app/components/reviewable-field-text.gjs+++ b/frontend/discourse/app/components/reviewable-field-text.gjs@@ -1,15 +1,12 @@-/* eslint-disable ember/no-classic-components */-import Component, { Input } from "@ember/component";+import { Input } from "@ember/component";import { on } from "@ember/modifier";-import { tagName } from "@ember-decorators/component";-@tagName("")-export default class ReviewableFieldText extends Component {- <template>- <Input- class="reviewable-input-text"- @value={{this.value}}- {{on "change" this.valueChanged}}- />- </template>-}+const ReviewableFieldText = <template>+ <Input+ class="reviewable-input-text"+ @value={{@value}}+ {{on "change" @valueChanged}}+ />+</template>;++export default ReviewableFieldText;diff --git a/frontend/discourse/app/components/reviewable-field-textarea.gjs b/frontend/discourse/app/components/reviewable-field-textarea.gjsindex d335c2831d5..e0fd9ee65c0 100644--- a/frontend/discourse/app/components/reviewable-field-textarea.gjs+++ b/frontend/discourse/app/components/reviewable-field-textarea.gjs@@ -1,15 +1,12 @@-/* eslint-disable ember/no-classic-components */-import Component, { Textarea } from "@ember/component";+import { Textarea } from "@ember/component";import { on } from "@ember/modifier";-import { tagName } from "@ember-decorators/component";-@tagName("")-export default class ReviewableFieldTextarea extends Component {- <template>- <Textarea- class="reviewable-input-textarea"- @value={{this.value}}- {{on "change" this.valueChanged}}- />- </template>-}+const ReviewableFieldTextarea = <template>+ <Textarea+ class="reviewable-input-textarea"+ @value={{@value}}+ {{on "change" @valueChanged}}+ />+</template>;++export default ReviewableFieldTextarea;diff --git a/frontend/discourse/app/components/reviewable-post-edits.gjs b/frontend/discourse/app/components/reviewable-post-edits.gjsindex 84c50a54ce1..9ecaf34b840 100644--- a/frontend/discourse/app/components/reviewable-post-edits.gjs+++ b/frontend/discourse/app/components/reviewable-post-edits.gjs@@ -1,52 +1,46 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";-import { action, computed } from "@ember/object";+import Component from "@glimmer/component";+import { action } from "@ember/object";import { service } from "@ember/service";-import { tagName } from "@ember-decorators/component";import HistoryModal from "discourse/components/modal/history";import { historyHeat } from "discourse/components/post/meta-data/edits-indicator";import { longDate } from "discourse/lib/formatter";import DButton from "discourse/ui-kit/d-button";import { i18n } from "discourse-i18n";-@tagName("")export default class ReviewablePostEdits extends Component {@service modal;+ @service siteSettings;+ @service store;- @computed("reviewable.post_version")get hasEdits() {- return this.reviewable?.post_version > 1;+ return this.args.reviewable?.post_version > 1;}- @computed("reviewable.post_version")get editCount() {- return this.reviewable?.post_version - 1;+ return this.args.reviewable?.post_version - 1;}- @computed("reviewable.post_updated_at")get historyClass() {return historyHeat(this.siteSettings,- new Date(this.reviewable?.post_updated_at)+ new Date(this.args.reviewable?.post_updated_at));}- @computed("reviewable.post_updated_at")get editedDate() {- return longDate(this.reviewable?.post_updated_at);+ return longDate(this.args.reviewable?.post_updated_at);}- @computed("reviewable.post_updated_at")get editedTitle() {return i18n("post.last_edited_on", {- dateTime: longDate(this.reviewable?.post_updated_at),+ dateTime: longDate(this.args.reviewable?.post_updated_at),});}@actionshowEditHistory(event) {event?.preventDefault();- let postId = this.get("reviewable.post_id");+ let postId = this.args.reviewable?.post_id;this.store.find("post", postId).then((post) => {this.modal.show(HistoryModal, {model: {diff --git a/frontend/discourse/app/components/reviewable-topic-link.gjs b/frontend/discourse/app/components/reviewable-topic-link.gjsindex c2544ba9240..fbb7b6f0213 100644--- a/frontend/discourse/app/components/reviewable-topic-link.gjs+++ b/frontend/discourse/app/components/reviewable-topic-link.gjs@@ -1,44 +1,37 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";import { array } from "@ember/helper";import { LinkTo } from "@ember/routing";-import { tagName } from "@ember-decorators/component";import ReviewableTags from "discourse/components/reviewable-tags";import TopicStatus from "discourse/components/topic-status";import highlightWatchedWords from "discourse/lib/highlight-watched-words";import dCategoryBadge from "discourse/ui-kit/helpers/d-category-badge";import { i18n } from "discourse-i18n";-@tagName("")-export default class ReviewableTopicLink extends Component {- <template>- {{#if this.reviewable.topic}}- <TopicStatus- @showPrivateMessageIcon={{true}}- @topic={{this.reviewable.topic}}- />- <a- class="title-text"- href={{this.reviewable.target_url}}- >{{highlightWatchedWords- this.reviewable.topic.fancyTitle- this.reviewable- }}</a>- {{dCategoryBadge this.reviewable.category}}- <ReviewableTags- @tags={{this.reviewable.topic_tags}}- @topic={{this.reviewable.topic}}- />- {{else if (has-block)}}- {{yield}}- {{else}}- <span class="title-text">- {{i18n "review.topics.deleted"}}- <LinkTo- @models={{array "-" this.reviewable.removed_topic_id}}- @route="topic"- >{{i18n "review.topics.original"}}</LinkTo>- </span>- {{/if}}- </template>-}+const ReviewableTopicLink = <template>+ {{#if @reviewable.topic}}+ <TopicStatus+ @showPrivateMessageIcon={{true}}+ @topic={{@reviewable.topic}}+ />+ <a+ class="title-text"+ href={{@reviewable.target_url}}+ >{{highlightWatchedWords @reviewable.topic.fancyTitle @reviewable}}</a>+ {{dCategoryBadge @reviewable.category}}+ <ReviewableTags+ @tags={{@reviewable.topic_tags}}+ @topic={{@reviewable.topic}}+ />+ {{else if (has-block)}}+ {{yield}}+ {{else}}+ <span class="title-text">+ {{i18n "review.topics.deleted"}}+ <LinkTo+ @models={{array "-" @reviewable.removed_topic_id}}+ @route="topic"+ >{{i18n "review.topics.original"}}</LinkTo>+ </span>+ {{/if}}+</template>;++export default ReviewableTopicLink;diff --git a/frontend/discourse/app/components/signup-cta.gjs b/frontend/discourse/app/components/signup-cta.gjsindex 70676601400..3d3811dcf41 100644--- a/frontend/discourse/app/components/signup-cta.gjs+++ b/frontend/discourse/app/components/signup-cta.gjs@@ -1,17 +1,25 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";+import Component from "@glimmer/component";import { action } from "@ember/object";+import { service } from "@ember/service";import { trustHTML } from "@ember/template";-import { tagName } from "@ember-decorators/component";-import { on } from "@ember-decorators/object";import routeAction from "discourse/helpers/route-action";import discourseLater from "discourse/lib/later";import DButton from "discourse/ui-kit/d-button";import dReplaceEmoji from "discourse/ui-kit/helpers/d-replace-emoji";import { i18n } from "discourse-i18n";-@tagName("")export default class SignupCta extends Component {+ @service keyValueStore;+ @service session;++ willDestroy() {+ super.willDestroy(...arguments);++ if (this.session.get("hideSignupCta")) {+ this.session.set("showSignupCta", false);+ }+ }+@actionhideForSession() {this.session.set("hideSignupCta", true);@@ -25,13 +33,6 @@ export default class SignupCta extends Component {this.keyValueStore.setItem("anon-cta-never", "t");}- @on("willDestroyElement")- _turnOffIfHidden() {- if (this.session.get("hideSignupCta")) {- this.session.set("showSignupCta", false);- }- }-<template><div class="signup-cta alert alert-info" ...attributes>{{#if this.session.hideSignupCta}}diff --git a/frontend/discourse/tests/integration/components/composer-action-title-test.gjs b/frontend/discourse/tests/integration/components/composer-action-title-test.gjsnew file mode 100644index 00000000000..5bba26cbf67--- /dev/null+++ b/frontend/discourse/tests/integration/components/composer-action-title-test.gjs@@ -0,0 +1,44 @@+import { render, settled } from "@ember/test-helpers";+import { module, test } from "qunit";+import ComposerActionTitle from "discourse/components/composer-action-title";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";++module("Integration | Component | ComposerActionTitle", function (hooks) {+ setupRenderingTest(hooks);++ test("offers to change the reply target only for a post edit", async function (assert) {+ const store = this.owner.lookup("service:store");+ const topic = store.createRecord("topic", { id: 1, title: "A topic" });+ const post = store.createRecord("post", {+ id: 2,+ post_number: 2,+ can_edit: true,+ topic,+ });+ const model = store.createRecord("composer", {+ action: "edit",+ topic,+ post,+ reply_to_user: {+ username: "eviltrout",+ avatar_template: "/images/avatar.png",+ },+ });++ await render(<template><ComposerActionTitle @model={{model}} /></template>);++ assert+ .dom(".composer-edit-reply-to")+ .exists("offers the change while editing a post");++ model.set("action", "editSharedDraft");+ await settled();++ assert+ .dom(".original-username")+ .hasText("eviltrout", "still shows the reply target");+ assert+ .dom(".composer-edit-reply-to")+ .doesNotExist("does not offer the change for a shared draft edit");+ });+});diff --git a/frontend/discourse/tests/integration/components/reviewable-field-editor-test.gjs b/frontend/discourse/tests/integration/components/reviewable-field-editor-test.gjsnew file mode 100644index 00000000000..6e4fb514942--- /dev/null+++ b/frontend/discourse/tests/integration/components/reviewable-field-editor-test.gjs@@ -0,0 +1,25 @@+import { fillIn, render } from "@ember/test-helpers";+import { module, test } from "qunit";+import ReviewableFieldEditor from "discourse/components/reviewable-field-editor";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";++module("Integration | Component | ReviewableFieldEditor", function (hooks) {+ setupRenderingTest(hooks);++ test("reports an edit", async function (assert) {+ const changes = [];+ const valueChanged = (event) => changes.push(event.target.value);++ await render(+ <template>+ <ReviewableFieldEditor @value="first" @valueChanged={{valueChanged}} />+ </template>+ );++ assert.dom(".d-editor-input").hasValue("first");++ await fillIn(".d-editor-input", "second");++ assert.strictEqual(changes.at(-1), "second", "passes the edited value up");+ });+});diff --git a/frontend/discourse/tests/integration/components/reviewable-field-text-test.gjs b/frontend/discourse/tests/integration/components/reviewable-field-text-test.gjsnew file mode 100644index 00000000000..80c547783ba--- /dev/null+++ b/frontend/discourse/tests/integration/components/reviewable-field-text-test.gjs@@ -0,0 +1,26 @@+import { fillIn, render } from "@ember/test-helpers";+import { module, test } from "qunit";+import ReviewableFieldText from "discourse/components/reviewable-field-text";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";++module("Integration | Component | ReviewableFieldText", function (hooks) {+ setupRenderingTest(hooks);++ test("reports an edit", async function (assert) {+ const changes = [];+ const valueChanged = (event) => changes.push(event.target.value);++ await render(+ <template>+ <ReviewableFieldText @value="first" @valueChanged={{valueChanged}} />+ </template>+ );++ assert.dom(".reviewable-input-text").hasValue("first");++ await fillIn(".reviewable-input-text", "second");++ assert.deepEqual(changes, ["second"], "passes the edited value up");+ assert.dom(".reviewable-input-text").hasValue("second");+ });+});diff --git a/frontend/discourse/tests/integration/components/reviewable-field-textarea-test.gjs b/frontend/discourse/tests/integration/components/reviewable-field-textarea-test.gjsnew file mode 100644index 00000000000..ad86b0ad7ab--- /dev/null+++ b/frontend/discourse/tests/integration/components/reviewable-field-textarea-test.gjs@@ -0,0 +1,29 @@+import { fillIn, render } from "@ember/test-helpers";+import { module, test } from "qunit";+import ReviewableFieldTextarea from "discourse/components/reviewable-field-textarea";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";++module("Integration | Component | ReviewableFieldTextarea", function (hooks) {+ setupRenderingTest(hooks);++ test("reports an edit", async function (assert) {+ const changes = [];+ const valueChanged = (event) => changes.push(event.target.value);++ await render(+ <template>+ <ReviewableFieldTextarea+ @value="first"+ @valueChanged={{valueChanged}}+ />+ </template>+ );++ assert.dom(".reviewable-input-textarea").hasValue("first");++ await fillIn(".reviewable-input-textarea", "second");++ assert.deepEqual(changes, ["second"], "passes the edited value up");+ assert.dom(".reviewable-input-textarea").hasValue("second");+ });+});diff --git a/frontend/discourse/tests/integration/components/reviewable-post-edits-test.gjs b/frontend/discourse/tests/integration/components/reviewable-post-edits-test.gjsnew file mode 100644index 00000000000..e4872e8e5ad--- /dev/null+++ b/frontend/discourse/tests/integration/components/reviewable-post-edits-test.gjs@@ -0,0 +1,32 @@+import { render } from "@ember/test-helpers";+import { module, test } from "qunit";+import ReviewablePostEdits from "discourse/components/reviewable-post-edits";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";++module("Integration | Component | ReviewablePostEdits", function (hooks) {+ setupRenderingTest(hooks);++ test("shows the number of edits", async function (assert) {+ const reviewable = {+ post_id: 1,+ post_version: 3,+ post_updated_at: "2026-01-01T12:00:00Z",+ };++ await render(+ <template><ReviewablePostEdits @reviewable={{reviewable}} /></template>+ );++ assert.dom(".post-info.edits .btn").hasText("2", "counts the edits");+ });++ test("renders nothing for an unedited post", async function (assert) {+ const reviewable = { post_id: 1, post_version: 1 };++ await render(+ <template><ReviewablePostEdits @reviewable={{reviewable}} /></template>+ );++ assert.dom(".post-info.edits").doesNotExist();+ });+});diff --git a/frontend/discourse/tests/integration/components/signup-cta-test.gjs b/frontend/discourse/tests/integration/components/signup-cta-test.gjsnew file mode 100644index 00000000000..61b9f60d1f3--- /dev/null+++ b/frontend/discourse/tests/integration/components/signup-cta-test.gjs@@ -0,0 +1,44 @@+import { click, render, settled } from "@ember/test-helpers";+import { module, test } from "qunit";+import SignupCta from "discourse/components/signup-cta";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import { i18n } from "discourse-i18n";++module("Integration | Component | SignupCta", function (hooks) {+ setupRenderingTest(hooks);++ test("hides the prompt for the session", async function (assert) {+ const session = this.owner.lookup("service:session");+ session.setProperties({ hideSignupCta: false, showSignupCta: true });++ await render(<template><SignupCta /></template>);+ await click(".signup-cta .btn-default");++ assert+ .dom(".signup-cta h3")+ .hasText(+ i18n("signup_cta.hidden_for_session"),+ "confirms it is hidden for the session"+ );+ assert.true(session.get("hideSignupCta"), "records the choice");+ });++ test("turns a hidden prompt off when it goes away", async function (assert) {+ const session = this.owner.lookup("service:session");+ session.setProperties({ hideSignupCta: true, showSignupCta: true });+ this.set("shown", true);++ await render(+ <template>+ {{#if this.shown}}+ <SignupCta />+ {{/if}}+ </template>+ );++ this.set("shown", false);+ await settled();++ assert.false(session.get("showSignupCta"), "stops showing the prompt");+ });+});diff --git a/plugins/discourse-subscriptions/assets/javascripts/discourse/components/create-coupon-form.gjs b/plugins/discourse-subscriptions/assets/javascripts/discourse/components/create-coupon-form.gjsindex 0fbe552e9f0..1feeacd637c 100644--- a/plugins/discourse-subscriptions/assets/javascripts/discourse/components/create-coupon-form.gjs+++ b/plugins/discourse-subscriptions/assets/javascripts/discourse/components/create-coupon-form.gjs@@ -1,28 +1,24 @@-/* eslint-disable ember/no-classic-components */-import Component, { Input } from "@ember/component";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { Input } from "@ember/component";import { fn } from "@ember/helper";import { on } from "@ember/modifier";-import { action, computed } from "@ember/object";-import { tagName } from "@ember-decorators/component";+import { action } from "@ember/object";import withEventValue from "discourse/helpers/with-event-value";import ComboBox from "discourse/select-kit/components/combo-box";import DButton from "discourse/ui-kit/d-button";import { i18n } from "discourse-i18n";-@tagName("")export default class CreateCouponForm extends Component {- discountType = "amount";- discount = null;- promoCode = null;- active = false;+ @tracked discountType = "amount";+ @tracked discount = null;+ @tracked promoCode = null;+ @tracked active = false;- @computed- get discountTypes() {- return [- { id: "amount", name: "Amount" },- { id: "percent", name: "Percent" },- ];- }+ discountTypes = [+ { id: "amount", name: "Amount" },+ { id: "percent", name: "Percent" },+ ];@actioncreateNewCoupon() {@@ -33,12 +29,12 @@ export default class CreateCouponForm extends Component {active: this.active,};- this.create(createParams);+ this.args.create(createParams);}@actioncancelCreate() {- this.cancel();+ this.args.cancel();}<template>diff --git a/plugins/discourse-subscriptions/test/javascripts/integration/components/create-coupon-form-test.gjs b/plugins/discourse-subscriptions/test/javascripts/integration/components/create-coupon-form-test.gjsnew file mode 100644index 00000000000..ba68600fa8a--- /dev/null+++ b/plugins/discourse-subscriptions/test/javascripts/integration/components/create-coupon-form-test.gjs@@ -0,0 +1,39 @@+import { click, fillIn, render } from "@ember/test-helpers";+import { module, test } from "qunit";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import selectKit from "discourse/tests/helpers/select-kit-helper";+import CreateCouponForm from "discourse/plugins/discourse-subscriptions/discourse/components/create-coupon-form";++module("Integration | Component | CreateCouponForm", function (hooks) {+ setupRenderingTest(hooks);++ test("creates a coupon from the entered values", async function (assert) {+ let created;+ const create = (params) => (created = params);+ const cancel = () => {};++ await render(+ <template>+ <CreateCouponForm @cancel={{cancel}} @create={{create}} />+ </template>+ );++ await fillIn("input[name='promo_code']", "SAVE10");+ await selectKit().expand();+ await selectKit().selectRowByValue("percent");+ await fillIn(".discount-amount", "10");+ await click("input[name='active']");+ await click(".btn-primary");++ assert.deepEqual(+ created,+ {+ promo: "SAVE10",+ discount_type: "percent",+ discount: "10",+ active: true,+ },+ "passes the form values to create"+ );+ });+});diff --git a/plugins/styleguide/assets/javascripts/discourse/components/styleguide-section.gjs b/plugins/styleguide/assets/javascripts/discourse/components/styleguide-section.gjsindex e0b96af441c..938b9f7b66a 100644--- a/plugins/styleguide/assets/javascripts/discourse/components/styleguide-section.gjs+++ b/plugins/styleguide/assets/javascripts/discourse/components/styleguide-section.gjs@@ -1,7 +1,5 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";-import { computed } from "@ember/object";-import { tagName } from "@ember-decorators/component";+import Component from "@glimmer/component";+import { modifier } from "ember-modifier";import DBreadcrumbsItem from "discourse/ui-kit/d-breadcrumbs-item";import DPageHeader from "discourse/ui-kit/d-page-header";import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";@@ -9,33 +7,32 @@ import { i18n } from "discourse-i18n";import ToggleColorMode from "discourse/plugins/styleguide/discourse/components/toggle-color-mode";import sectionTitle from "discourse/plugins/styleguide/discourse/helpers/section-title";-@tagName("")export default class StyleguideSection extends Component {- @computed("section")+ scrollToTop = modifier((element, [section, title]) => {+ if (section || title) {+ window.scrollTo(0, 0);+ }+ });+get sectionClass() {- if (this.section) {- return `${this.section.id}-examples`;+ if (this.args.section) {+ return `${this.args.section.id}-examples`;}}// Built by hand rather than with a route, because a breadcrumb item can only link to a route// without dynamic segments and this one needs the category and section.- @computed("section")get sectionPath() {- if (this.section) {- return `/styleguide/${this.section.category}/${this.section.id}`;+ if (this.args.section) {+ return `/styleguide/${this.args.section.category}/${this.args.section.id}`;}}- didReceiveAttrs() {- super.didReceiveAttrs(...arguments);- window.scrollTo(0, 0);- }-<template><sectionclass={{dConcatClass "styleguide-section" this.sectionClass}}...attributes+ {{this.scrollToTop @section @title}}><DPageHeader @hideTabs={{true}}><:breadcrumbs>@@ -44,9 +41,9 @@ export default class StyleguideSection extends Component {@path="/styleguide"/>- {{#if this.section}}+ {{#if @section}}<DBreadcrumbsItem- @label={{sectionTitle this.section.id}}+ @label={{sectionTitle @section.id}}@path={{this.sectionPath}}/>{{/if}}@@ -57,10 +54,10 @@ export default class StyleguideSection extends Component {</:breadcrumbs><:title>- {{#if this.section}}- {{sectionTitle this.section.id}}- {{else if this.title}}- {{i18n this.title}}+ {{#if @section}}+ {{sectionTitle @section.id}}+ {{else if @title}}+ {{i18n @title}}{{/if}}</:title></DPageHeader>diff --git a/plugins/styleguide/test/javascripts/integration/components/styleguide-section-test.gjs b/plugins/styleguide/test/javascripts/integration/components/styleguide-section-test.gjsnew file mode 100644index 00000000000..00bfccdcfe9--- /dev/null+++ b/plugins/styleguide/test/javascripts/integration/components/styleguide-section-test.gjs@@ -0,0 +1,31 @@+import { tracked } from "@glimmer/tracking";+import { render, settled } from "@ember/test-helpers";+import { module, test } from "qunit";+import sinon from "sinon";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import StyleguideSection from "discourse/plugins/styleguide/discourse/components/styleguide-section";++class State {+ @tracked section = { id: "colors", category: "atoms" };+}++module("Integration | Component | StyleguideSection", function (hooks) {+ setupRenderingTest(hooks);++ test("scrolls to the top whenever another section is shown", async function (assert) {+ const scrollTo = sinon.stub(window, "scrollTo");+ const state = new State();++ await render(+ <template><StyleguideSection @section={{state.section}} /></template>+ );++ assert.strictEqual(scrollTo.callCount, 1, "scrolls when first shown");++ state.section = { id: "icons", category: "atoms" };+ await settled();++ assert.strictEqual(scrollTo.callCount, 2, "scrolls on a section change");+ assert.dom(".styleguide-section").hasClass("icons-examples");+ });+});