A platform for community discussion. Free, open, simple.
DEV: Convert 10 components to glimmer (#44687)
Jarek Radosz4bae0436fe7a
diff --git a/frontend/discourse/admin/components/admin-penalty-post-action.gjs b/frontend/discourse/admin/components/admin-penalty-post-action.gjsindex 10f5548eee7..7a84589844c 100644--- a/frontend/discourse/admin/components/admin-penalty-post-action.gjs+++ b/frontend/discourse/admin/components/admin-penalty-post-action.gjs@@ -1,11 +1,12 @@-/* eslint-disable ember/no-classic-components, ember/require-tagless-components */+import Component from "@glimmer/component";import { tracked } from "@glimmer/tracking";-import Component, { Input, Textarea } from "@ember/component";+import { Input } from "@ember/component";import { on } from "@ember/modifier";-import { action, computed } from "@ember/object";+import { action } from "@ember/object";import { trustHTML } from "@ember/template";-import { afterRender } from "discourse/lib/decorators";+import withEventValue from "discourse/helpers/with-event-value";import ComboBox from "discourse/select-kit/components/combo-box";+import dAutoFocus from "discourse/ui-kit/modifiers/d-auto-focus";import I18n, { i18n } from "discourse-i18n";const ACTIONS = ["delete", "delete_all", "delete_replies", "edit", "none"];@@ -13,26 +14,14 @@ const ACTIONS = ["delete", "delete_all", "delete_replies", "edit", "none"];export default class AdminPenaltyPostAction extends Component {@tracked confirmDeleteAll = false;- /** @type {number | null | undefined} */- postId = null;-- /** @type {string | null} */- postAction = null;-- /** @type {string | null | undefined} */- postEdit = null;-- @computed("postAction")get editing() {- return this.postAction === "edit";+ return this.args.postAction === "edit";}- @computed("postAction")get deletingAll() {- return this.postAction === "delete_all";+ return this.args.postAction === "delete_all";}- @computedget penaltyActions() {const allActions = ACTIONS.map((id) => ({id,@@ -41,7 +30,7 @@ export default class AdminPenaltyPostAction extends Component {// Remove "delete all" option for users at or above the configured trust level// For now the trust level is static, add a site setting later if we want users to be able to modify this- if (this.user.trust_level >= 2) {+ if (this.args.user.trust_level >= 2) {return allActions.filter((act) => act.id !== "delete_all");}@@ -49,15 +38,15 @@ export default class AdminPenaltyPostAction extends Component {}get topicsCount() {- return this.user.topic_count;+ return this.args.user.topic_count;}get repliesCount() {- return this.user.post_count - this.user.topic_count;+ return this.args.user.post_count - this.args.user.topic_count;}get readyToDeleteAll() {- return this.canSubmitDeleteAll();+ return this.deletingAll && this.confirmDeleteAll;}get deleteAllMessage() {@@ -70,64 +59,49 @@ export default class AdminPenaltyPostAction extends Component {);}- canSubmitDeleteAll() {- return this.postAction === "delete_all" && this.confirmDeleteAll;- }-- @action- penaltyChanged(postAction) {- this.set("postAction", postAction);-- // If we switch to edit mode, jump to the edit textarea- if (postAction === "edit") {- this._focusEditTextarea();- }- }-@actiontoggleConfirmDeleteAll(event) {- this.set("confirmDeleteAll", event.target.checked);-- this.onDeleteAllPostsReady?.(this.readyToDeleteAll);- }+ this.confirmDeleteAll = event.target.checked;- @afterRender- _focusEditTextarea() {- const elem = this.element;- const body = elem.closest(".d-modal__body");- body.scrollTo(0, body.clientHeight);- elem.querySelector(".post-editor").focus();+ this.args.onDeleteAllPostsReady?.(this.readyToDeleteAll);}<template>- <div class="penalty-post-controls">- <label>- <div class="penalty-post-label">- {{trustHTML (i18n "admin.user.penalty_post_actions")}}+ <div ...attributes>+ <div class="penalty-post-controls">+ <label>+ <div class="penalty-post-label">+ {{trustHTML (i18n "admin.user.penalty_post_actions")}}+ </div>+ </label>+ <ComboBox+ @content={{this.penaltyActions}}+ @onChange={{@onChangePostAction}}+ @value={{@postAction}}+ />+ </div>++ {{#if this.editing}}+ <div class="penalty-post-edit">+ <textarea+ class="post-editor"+ value={{@postEdit}}+ {{dAutoFocus preventScroll=false}}+ {{on "input" (withEventValue @onChangePostEdit)}}+ /></div>- </label>- <ComboBox- @content={{this.penaltyActions}}- @onChange={{this.penaltyChanged}}- @value={{this.postAction}}- />+ {{/if}}++ {{#if this.deletingAll}}+ <label>+ <Input+ @checked={{this.confirmDeleteAll}}+ @type="checkbox"+ {{on "click" this.toggleConfirmDeleteAll}}+ />+ {{trustHTML this.deleteAllMessage}}+ </label>+ {{/if}}</div>-- {{#if this.editing}}- <div class="penalty-post-edit">- <Textarea class="post-editor" @value={{this.postEdit}} />- </div>- {{/if}}-- {{#if this.deletingAll}}- <label>- <Input- @checked={{this.confirmDeleteAll}}- @type="checkbox"- {{on "click" this.toggleConfirmDeleteAll}}- />- {{trustHTML this.deleteAllMessage}}- </label>- {{/if}}</template>}diff --git a/frontend/discourse/admin/components/admin-penalty-reason.gjs b/frontend/discourse/admin/components/admin-penalty-reason.gjsindex cbba62fefee..c10dd2b7168 100644--- a/frontend/discourse/admin/components/admin-penalty-reason.gjs+++ b/frontend/discourse/admin/components/admin-penalty-reason.gjs@@ -1,8 +1,9 @@-/* eslint-disable ember/no-classic-components */-import Component, { Textarea } from "@ember/component";-import { action, computed } from "@ember/object";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { on } from "@ember/modifier";+import { action } from "@ember/object";import { trustHTML } from "@ember/template";-import { tagName } from "@ember-decorators/component";+import withEventValue from "discourse/helpers/with-event-value";import ComboBox from "discourse/select-kit/components/combo-box";import { eq } from "discourse/truth-helpers";import DTextField from "discourse/ui-kit/d-text-field";@@ -10,53 +11,46 @@ import { i18n } from "discourse-i18n";const CUSTOM_REASON_KEY = "custom";-@tagName("")+const REASON_KEYS = [+ "not_listening_to_staff",+ "consuming_staff_time",+ "combative",+ "in_wrong_place",+ "no_constructive_purpose",+ CUSTOM_REASON_KEY,+];+export default class AdminPenaltyReason extends Component {- selectedReason = CUSTOM_REASON_KEY;- customReason = "";+ @tracked selectedReason = CUSTOM_REASON_KEY;+ @tracked customReason = "";- reasonKeys = [- "not_listening_to_staff",- "consuming_staff_time",- "combative",- "in_wrong_place",- "no_constructive_purpose",- CUSTOM_REASON_KEY,- ];+ reasons = REASON_KEYS.map((key) => ({+ id: key,+ name: i18n(`admin.user.suspend_reasons.${key}`),+ }));- @computed("selectedReason")get isCustomReason() {return this.selectedReason === CUSTOM_REASON_KEY;}- @computed("reasonKeys")- get reasons() {- return this.reasonKeys.map((key) => {- return { id: key, name: i18n(`admin.user.suspend_reasons.${key}`) };- });- }-@actionsetSelectedReason(value) {- this.set("selectedReason", value);- this.setReason();+ this.selectedReason = value;+ this.#updateReason();}@actionsetCustomReason(value) {- this.set("customReason", value);- this.setReason();+ this.customReason = value;+ this.#updateReason();}- setReason() {- if (this.isCustomReason) {- this.set("reason", this.customReason);- } else {- this.set(- "reason",- i18n(`admin.user.suspend_reasons.${this.selectedReason}`)- );- }+ #updateReason() {+ this.args.onChangeReason(+ this.isCustomReason+ ? this.customReason+ : i18n(`admin.user.suspend_reasons.${this.selectedReason}`)+ );}<template>@@ -103,10 +97,11 @@ export default class AdminPenaltyReason extends Component {<div class="penalty-message-controls"><label>{{i18n "admin.user.suspend_message"}}</label>- <Textarea+ <textareaclass="suspend-message"placeholder={{i18n "admin.user.suspend_message_placeholder"}}- @value={{this.message}}+ value={{@message}}+ {{on "input" (withEventValue @onChangeMessage)}}/></div></template>diff --git a/frontend/discourse/admin/components/bulk-user-suspend-confirmation.gjs b/frontend/discourse/admin/components/bulk-user-suspend-confirmation.gjsindex e0ba3360c1d..9a5b461c054 100644--- a/frontend/discourse/admin/components/bulk-user-suspend-confirmation.gjs+++ b/frontend/discourse/admin/components/bulk-user-suspend-confirmation.gjs@@ -178,8 +178,9 @@ export default class BulkUserSuspendConfirmation extends Component {/><AdminPenaltyReason@message={{this.message}}+ @onChangeMessage={{fn (mut this.message)}}+ @onChangeReason={{fn (mut this.reason)}}@penaltyType="suspend"- @reason={{this.reason}}/>{{/if}}</:body>diff --git a/frontend/discourse/admin/components/modal/penalize-user.gjs b/frontend/discourse/admin/components/modal/penalize-user.gjsindex 3c40ad306dc..639a4aa48f2 100644--- a/frontend/discourse/admin/components/modal/penalize-user.gjs+++ b/frontend/discourse/admin/components/modal/penalize-user.gjs@@ -26,7 +26,7 @@ export default class PenalizeUser extends Component {@tracked otherUserIds = [];@tracked postAction = "delete";- @tracked postEdit = this.args.model.postEdit; // eslint-disable-line discourse/no-unnecessary-tracked+ @tracked postEdit = this.args.model.postEdit;@tracked flash;@tracked reason;@tracked message;@@ -198,15 +198,17 @@ export default class PenalizeUser extends Component {{{/if}}<AdminPenaltyReason@message={{this.message}}+ @onChangeMessage={{fn (mut this.message)}}+ @onChangeReason={{fn (mut this.reason)}}@penaltyType={{@model.penaltyType}}- @reason={{this.reason}}/>{{#if @model.postId}}<AdminPenaltyPostAction+ @onChangePostAction={{fn (mut this.postAction)}}+ @onChangePostEdit={{fn (mut this.postEdit)}}@onDeleteAllPostsReady={{this.updateReadyToDeleteAll}}@postAction={{this.postAction}}@postEdit={{this.postEdit}}- @postId={{@model.postId}}@user={{@model.user}}/>{{/if}}diff --git a/frontend/discourse/admin/components/screened-ip-address-form.gjs b/frontend/discourse/admin/components/screened-ip-address-form.gjsindex 53de7cd8262..a5dbef10f2f 100644--- a/frontend/discourse/admin/components/screened-ip-address-form.gjs+++ b/frontend/discourse/admin/components/screened-ip-address-form.gjs@@ -1,10 +1,10 @@-/* eslint-disable ember/no-classic-components, ember/require-tagless-components */-import Component from "@ember/component";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";import { fn } from "@ember/helper";-import { action, computed } from "@ember/object";+import { action } from "@ember/object";import { schedule } from "@ember/runloop";import { service } from "@ember/service";-import { classNames, tagName } from "@ember-decorators/component";+import { modifier as modifierFn } from "ember-modifier";import ScreenedIpAddress from "discourse/admin/models/screened-ip-address";import ComboBox from "discourse/select-kit/components/combo-box";import DButton from "discourse/ui-kit/d-button";@@ -15,24 +15,29 @@ import { i18n } from "discourse-i18n";A form to create an IP address that will be blocked or allowed.Example usage:- {{screened-ip-address-form action=(action "recordAdded")}}+ <ScreenedIpAddressForm @action={{this.recordAdded}} />where action is a callback on the controller or route that will get called afterthe new record is successfully saved. It is called with the new ScreenedIpAddress recordas an argument.**/-@tagName("form")-@classNames("screened-ip-address-form", "inline-form")export default class ScreenedIpAddressForm extends Component {@service dialog;+ @service siteSettings;- formSubmitted = false;- actionName = "block";+ @tracked actionName = "block";+ @tracked formSubmitted = false;+ @tracked ipAddress;++ registerInput = modifierFn((element) => {+ this.#input = element;+ });++ #input;- @computed("siteSettings.use_admin_ip_allowlist")get actionNames() {- if (this.siteSettings?.use_admin_ip_allowlist) {+ if (this.siteSettings.use_admin_ip_allowlist) {return [{ id: "block", name: i18n("admin.logs.screened_ips.actions.block") },{@@ -57,27 +62,30 @@ export default class ScreenedIpAddressForm extends Component {focusInput() {schedule("afterRender", () => {- this.element.querySelector("input").focus();+ this.#input.focus();});}@actionsubmitForm() {if (!this.formSubmitted) {- this.set("formSubmitted", true);+ this.formSubmitted = true;const screenedIpAddress = ScreenedIpAddress.create({- ip_address: this.ip_address,+ ip_address: this.ipAddress,action_name: this.actionName,});screenedIpAddress.save().then((result) => {- this.setProperties({ ip_address: "", formSubmitted: false });- this.action(ScreenedIpAddress.create(result.screened_ip_address));+ this.ipAddress = "";+ this.formSubmitted = false;+ this.args.action(+ ScreenedIpAddress.create(result.screened_ip_address)+ );this.focusInput();}).catch((e) => {- this.set("formSubmitted", false);+ this.formSubmitted = false;const message = e.jqXHR.responseJSON?.errors? i18n("generic_error_with_reason", {error: e.jqXHR.responseJSON.errors.join(". "),@@ -93,28 +101,31 @@ export default class ScreenedIpAddressForm extends Component {}<template>- <label>{{i18n "admin.logs.screened_ips.form.label"}}</label>- <DTextField- class="ip-address-input"- @autocapitalize="off"- @autocorrect="off"- @disabled={{this.formSubmitted}}- @placeholderKey="admin.logs.screened_ips.form.ip_address"- @value={{this.ip_address}}- />+ <form class="screened-ip-address-form inline-form" ...attributes>+ <label>{{i18n "admin.logs.screened_ips.form.label"}}</label>+ <DTextField+ class="ip-address-input"+ @autocapitalize="off"+ @autocorrect="off"+ @disabled={{this.formSubmitted}}+ @placeholderKey="admin.logs.screened_ips.form.ip_address"+ @value={{this.ipAddress}}+ {{this.registerInput}}+ />- <ComboBox- @content={{this.actionNames}}- @onChange={{fn (mut this.actionName)}}- @value={{this.actionName}}- />+ <ComboBox+ @content={{this.actionNames}}+ @onChange={{fn (mut this.actionName)}}+ @value={{this.actionName}}+ />- <DButton- class="btn-default"- type="submit"- @action={{this.submitForm}}- @disabled={{this.formSubmitted}}- @label="admin.logs.screened_ips.form.add"- />+ <DButton+ class="btn-default"+ type="submit"+ @action={{this.submitForm}}+ @disabled={{this.formSubmitted}}+ @label="admin.logs.screened_ips.form.add"+ />+ </form></template>}diff --git a/frontend/discourse/app/components/d-document.js b/frontend/discourse/app/components/d-document.jsindex d5d3b6338f6..ac78f456002 100644--- a/frontend/discourse/app/components/d-document.js+++ b/frontend/discourse/app/components/d-document.js@@ -1,7 +1,5 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";+import Component from "@glimmer/component";import { service } from "@ember/service";-import { tagName } from "@ember-decorators/component";import { setLogoffCallback } from "discourse/lib/ajax";import { clearBodyLocks } from "discourse/lib/body-scroll-lock";import { bind } from "discourse/lib/decorators";@@ -17,15 +15,18 @@ export function clearPluginDocumentTitleCounters() {pluginCounterFunctions.length = 0;}-@tagName("")export default class DDocument extends Component {- @service documentTitle;+ @service appEvents;+ @service currentUser;@service dialog;+ @service documentTitle;+ @service messageBus;+ @service session;- _showingLogout = false;+ #showingLogout = false;- didInsertElement() {- super.didInsertElement(...arguments);+ constructor() {+ super(...arguments);this.documentTitle.setTitle(document.title);document.addEventListener("visibilitychange", this._focusChanged);@@ -37,8 +38,8 @@ export default class DDocument extends Component {setLogoffCallback(() => this.displayLogoff());}- willDestroyElement() {- super.willDestroyElement(...arguments);+ willDestroy() {+ super.willDestroy(...arguments);setLogoffCallback(null);document.removeEventListener("visibilitychange", this._focusChanged);@@ -53,11 +54,11 @@ export default class DDocument extends Component {}displayLogoff() {- if (this._showingLogout) {+ if (this.#showingLogout) {return;}- this._showingLogout = true;+ this.#showingLogout = true;this.messageBus.stop();this.dialog.alert({@@ -91,7 +92,7 @@ export default class DDocument extends Component {if (this.session.hasFocus) {this.documentTitle.setFocus(false);}- } else if (!this.hasFocus) {+ } else if (!this.session.hasFocus) {this.documentTitle.setFocus(true);}}diff --git a/frontend/discourse/app/components/group-membership-button.gjs b/frontend/discourse/app/components/group-membership-button.gjsindex 26dea3e10c3..994ea930515 100644--- a/frontend/discourse/app/components/group-membership-button.gjs+++ b/frontend/discourse/app/components/group-membership-button.gjs@@ -1,42 +1,40 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";-import { action, computed } from "@ember/object";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { action, get } from "@ember/object";import { service } from "@ember/service";-import { tagName } from "@ember-decorators/component";import { popupAjaxError } from "discourse/lib/ajax-error";import DButton from "discourse/ui-kit/d-button";import { i18n } from "discourse-i18n";import RequestGroupMembershipForm from "./modal/request-group-membership-form.gjs";-@tagName("")export default class GroupMembershipButton extends Component {@service appEvents;@service currentUser;@service dialog;@service modal;- @computed("model.public_admission", "userIsGroupUser")+ @tracked updatingMembership = false;+get canJoinGroup() {- return this.model?.public_admission && !this.userIsGroupUser;+ return get(this.args.model, "public_admission") && !this.userIsGroupUser;}- @computed("model.public_exit", "userIsGroupUser")get canLeaveGroup() {- return this.model?.public_exit && this.userIsGroupUser;+ return get(this.args.model, "public_exit") && this.userIsGroupUser;}- @computed("model.allow_membership_requests", "userIsGroupUser")get canRequestMembership() {- return this.model?.allow_membership_requests && !this.userIsGroupUser;+ return (+ get(this.args.model, "allow_membership_requests") && !this.userIsGroupUser+ );}- @computed("model.is_group_user")get userIsGroupUser() {- return !!this.model?.is_group_user;+ return !!get(this.args.model, "is_group_user");}removeFromGroup() {- const model = this.model;+ const model = this.args.model;model.leave().then(() => {@@ -44,17 +42,17 @@ export default class GroupMembershipButton extends Component {this.appEvents.trigger("group:leave", model);}).catch(popupAjaxError)- .finally(() => this.set("updatingMembership", false));+ .finally(() => (this.updatingMembership = false));}@actionjoinGroup() {if (!this.currentUser) {- return this.showLogin();+ return this.args.showLogin();}- this.set("updatingMembership", true);- const group = this.model;+ this.updatingMembership = true;+ const group = this.args.model;group.join()@@ -64,21 +62,23 @@ export default class GroupMembershipButton extends Component {}).catch(popupAjaxError).finally(() => {- this.set("updatingMembership", false);+ this.updatingMembership = false;});}@actionleaveGroup() {- this.set("updatingMembership", true);+ this.updatingMembership = true;- if (this.model.public_admission) {+ if (this.args.model.public_admission) {this.removeFromGroup();} else {return this.dialog.yesNoConfirm({message: i18n("groups.confirm_leave"),didConfirm: () => this.removeFromGroup(),- didCancel: () => this.set("updatingMembership", false),+ didCancel: () => {+ this.updatingMembership = false;+ },});}}@@ -86,12 +86,12 @@ export default class GroupMembershipButton extends Component {@actionshowRequestMembershipForm() {if (!this.currentUser) {- return this.showLogin();+ return this.args.showLogin();}this.modal.show(RequestGroupMembershipForm, {model: {- group: this.model,+ group: this.args.model,},});}@@ -118,7 +118,6 @@ export default class GroupMembershipButton extends Component {<DButtonclass="btn-default group-index-request"@action={{this.showRequestMembershipForm}}- @disabled={{this.loading}}@icon="user-plus"@label="groups.request"/>diff --git a/frontend/discourse/app/components/groups-form-interaction-fields.gjs b/frontend/discourse/app/components/groups-form-interaction-fields.gjsindex 9198be09f21..d2cf11b0731 100644--- a/frontend/discourse/app/components/groups-form-interaction-fields.gjs+++ b/frontend/discourse/app/components/groups-form-interaction-fields.gjs@@ -1,8 +1,8 @@-/* eslint-disable ember/no-classic-components */-import Component, { Input } from "@ember/component";+import Component from "@glimmer/component";+import { Input } from "@ember/component";import { fn, hash } from "@ember/helper";-import { computed } from "@ember/object";-import { tagName } from "@ember-decorators/component";+import { get } from "@ember/object";+import { service } from "@ember/service";import PluginOutlet from "discourse/components/plugin-outlet";import DTooltip from "discourse/float-kit/components/d-tooltip";import lazyHash from "discourse/helpers/lazy-hash";@@ -12,8 +12,10 @@ import NotificationsButton from "discourse/select-kit/components/notifications-bimport DTextField from "discourse/ui-kit/d-text-field";import { i18n } from "discourse-i18n";-@tagName("")export default class GroupsFormInteractionFields extends Component {+ @service currentUser;+ @service siteSettings;+aliasLevelOptions = [{ name: i18n("groups.alias_levels.nobody"), value: 0 },{ name: i18n("groups.alias_levels.only_admins"), value: 1 },@@ -23,54 +25,39 @@ export default class GroupsFormInteractionFields extends Component {{ name: i18n("groups.alias_levels.everyone"), value: 99 },];- watchingNotificationLevel = NotificationLevels.WATCHING;-- @computed("model.messageable_level", "aliasLevelOptions.firstObject.value")get messageableLevel() {return (- this.model?.messageable_level ||- this.aliasLevelOptions?.firstObject?.value+ get(this.args.model, "messageable_level") ||+ this.aliasLevelOptions[0].value);}- @computed("model.mentionable_level", "aliasLevelOptions.firstObject.value")get mentionableLevel() {return (- this.model?.mentionable_level ||- this.aliasLevelOptions?.firstObject?.value+ get(this.args.model, "mentionable_level") ||+ this.aliasLevelOptions[0].value);}- @computed("model.default_notification_level", "watchingNotificationLevel")get defaultNotificationLevel() {- if (- Object.values(NotificationLevels).includes(- this.model?.default_notification_level- )- ) {- return this.model?.default_notification_level;- }- return this.watchingNotificationLevel;+ const level = get(this.args.model, "default_notification_level");+ return Object.values(NotificationLevels).includes(level)+ ? level+ : NotificationLevels.WATCHING;}- @computed("siteSettings.email_in", "model.automatic", "currentUser.admin")get showEmailSettings() {return (- this.siteSettings?.email_in &&+ this.siteSettings.email_in &&this.currentUser?.admin &&- !this.model?.automatic+ !this.args.model?.automatic);}- @computed(- "model.isCreated",- "model.can_admin_group",- "currentUser.can_create_group"- )get canAdminGroup() {return (- (!this.model?.isCreated && this.currentUser?.can_create_group) ||- (this.model?.isCreated && this.model?.can_admin_group)+ (!this.args.model?.isCreated && this.currentUser?.can_create_group) ||+ (this.args.model?.isCreated && this.args.model?.can_admin_group));}@@ -86,7 +73,7 @@ export default class GroupsFormInteractionFields extends Component {class="groups-form-mentionable-level"@content={{this.aliasLevelOptions}}@name="alias"- @onChange={{fn (mut this.model.mentionable_level)}}+ @onChange={{fn (mut @model.mentionable_level)}}@value={{this.mentionableLevel}}@valueProperty="value"/>@@ -99,7 +86,7 @@ export default class GroupsFormInteractionFields extends Component {class="groups-form-messageable-level"@content={{this.aliasLevelOptions}}@name="alias"- @onChange={{fn (mut this.model.messageable_level)}}+ @onChange={{fn (mut @model.messageable_level)}}@value={{this.messageableLevel}}@valueProperty="value"/>@@ -110,7 +97,7 @@ export default class GroupsFormInteractionFields extends Component {<label><Inputclass="groups-form-publish-read-state"- @checked={{this.model.publish_read_state}}+ @checked={{@model.publish_read_state}}@type="checkbox"/>@@ -132,7 +119,7 @@ export default class GroupsFormInteractionFields extends Component {class="input-xxlarge groups-form-incoming-email"@name="incoming_email"@placeholderKey="admin.groups.manage.interaction.incoming_email_placeholder"- @value={{this.model.incoming_email}}+ @value={{@model.incoming_email}}/><DTooltip@@ -146,7 +133,7 @@ export default class GroupsFormInteractionFields extends Component {<PluginOutlet@connectorTagName="div"@name="group-email-in"- @outletArgs={{lazyHash model=this.model}}+ @outletArgs={{lazyHash model=@model}}/></span></div>@@ -161,7 +148,7 @@ export default class GroupsFormInteractionFields extends Component {<NotificationsButtonclass="groups-form-default-notification-level"- @onChange={{fn (mut this.model.default_notification_level)}}+ @onChange={{fn (mut @model.default_notification_level)}}@options={{hash i18nPrefix="groups.notifications"}}@value={{this.defaultNotificationLevel}}/>@@ -171,7 +158,7 @@ export default class GroupsFormInteractionFields extends Component {<PluginOutlet@connectorTagName="div"@name="groups-interaction-custom-options"- @outletArgs={{lazyHash model=this.model}}+ @outletArgs={{lazyHash model=@model}}/></span></div>diff --git a/frontend/discourse/app/components/user-notification-schedule-day.gjs b/frontend/discourse/app/components/user-notification-schedule-day.gjsindex 37765cdc898..7c44f17c4a9 100644--- a/frontend/discourse/app/components/user-notification-schedule-day.gjs+++ b/frontend/discourse/app/components/user-notification-schedule-day.gjs@@ -1,39 +1,32 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";-import { computed } from "@ember/object";-import { tagName } from "@ember-decorators/component";+import { concat } from "@ember/helper";import ComboBox from "discourse/select-kit/components/combo-box";import { i18n } from "discourse-i18n";-@tagName("")-export default class UserNotificationScheduleDay extends Component {- <template>- <tr class="day {{this.dayLabel}}">- <td class="day-label">{{this.dayLabel}}</td>+const UserNotificationScheduleDay = <template>+ {{#let (i18n (concat "user.notification_schedule." @day)) as |dayLabel|}}+ <tr class="day {{dayLabel}}">+ <td class="day-label">{{dayLabel}}</td><td class="starts-at"><ComboBox- @content={{this.startTimeOptions}}- @onChange={{this.onChangeStartTime}}- @value={{this.startTimeValue}}+ @content={{@startTimeOptions}}+ @onChange={{@onChangeStartTime}}+ @value={{@startTimeValue}}@valueProperty="value"/></td>- {{#if this.endTimeOptions}}+ {{#if @endTimeOptions}}<td class="to">{{i18n "user.notification_schedule.to"}}</td><td class="ends-at"><ComboBox- @content={{this.endTimeOptions}}- @onChange={{this.onChangeEndTime}}- @value={{this.endTimeValue}}+ @content={{@endTimeOptions}}+ @onChange={{@onChangeEndTime}}+ @value={{@endTimeValue}}@valueProperty="value"/></td>{{/if}}</tr>- </template>+ {{/let}}+</template>;- @computed("day")- get dayLabel() {- return i18n(`user.notification_schedule.${this.day}`);- }-}+export default UserNotificationScheduleDay;diff --git a/frontend/discourse/app/components/user-notification-schedule.gjs b/frontend/discourse/app/components/user-notification-schedule.gjsindex 4d2d8cee560..92585dd1f8f 100644--- a/frontend/discourse/app/components/user-notification-schedule.gjs+++ b/frontend/discourse/app/components/user-notification-schedule.gjs@@ -1,7 +1,6 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";+import Component from "@glimmer/component";+import { cached } from "@glimmer/tracking";import EmberObject, { action, computed } from "@ember/object";-import { tagName } from "@ember-decorators/component";import PreferenceCheckbox from "discourse/components/preference-checkbox";import UserNotificationScheduleDay from "discourse/components/user-notification-schedule-day";import { i18n } from "discourse-i18n";@@ -72,73 +71,66 @@ class Day extends EmberObject {if (startTime === -1) {return null;}- return this.buildTimeOptions(startTime + 30, {+ return buildTimeOptions(startTime + 30, {includeNone: false,showMidnight: true,});}}-@tagName("")-export default class UserNotificationSchedule extends Component {- /** @type {Day[] | null} */- days = null;-- didInsertElement() {- super.didInsertElement(...arguments);- this.set(- "startTimeOptions",- this.buildTimeOptions(0, {- includeNone: true,- showMidnight: false,- })- );+function buildTimeOptions(+ startAt,+ opts = { includeNone: false, showMidnight: true }+) {+ let timeOptions = [];- const days = DAYS.map((day, index) =>- Day.create({- id: index,- day,- model: this.model,- buildTimeOptions: this.buildTimeOptions,- startTimeOptions: this.startTimeOptions,- })- );-- this.set("days", days);+ if (opts.includeNone) {+ timeOptions.push({+ name: i18n("user.notification_schedule.none"),+ value: -1,+ });}- buildTimeOptions(startAt, opts = { includeNone: false, showMidnight: true }) {- let timeOptions = [];+ for (let timeInMin = startAt; timeInMin <= 1440; timeInMin += 30) {+ let hours = Math.floor(timeInMin / 60);+ let minutes = timeInMin % 60;- if (opts.includeNone) {- timeOptions.push({- name: i18n("user.notification_schedule.none"),- value: -1,- });+ if (minutes === 0) {+ minutes = "00";}-- for (let timeInMin = startAt; timeInMin <= 1440; timeInMin += 30) {- let hours = Math.floor(timeInMin / 60);- let minutes = timeInMin % 60;-- if (minutes === 0) {- minutes = "00";- }- if (hours === 24) {- if (opts.showMidnight) {- timeOptions.push({- name: i18n("user.notification_schedule.midnight"),- value: 1440,- });- }- break;+ if (hours === 24) {+ if (opts.showMidnight) {+ timeOptions.push({+ name: i18n("user.notification_schedule.midnight"),+ value: 1440,+ });}- timeOptions.push({- name: moment().set("hour", hours).set("minute", minutes).format("LT"),- value: timeInMin,- });+ break;}- return timeOptions;+ timeOptions.push({+ name: moment().set("hour", hours).set("minute", minutes).format("LT"),+ value: timeInMin,+ });+ }+ return timeOptions;+}++export default class UserNotificationSchedule extends Component {+ @cached+ get days() {+ const startTimeOptions = buildTimeOptions(0, {+ includeNone: true,+ showMidnight: false,+ });++ return DAYS.map((day, index) =>+ Day.create({+ id: index,+ day,+ model: this.args.model,+ startTimeOptions,+ })+ );}<template>@@ -151,11 +143,11 @@ export default class UserNotificationSchedule extends Component {"user.notification_schedule.title"}}</label><PreferenceCheckbox- @checked={{this.model.user_notification_schedule.enabled}}+ @checked={{@model.user_notification_schedule.enabled}}@labelKey="user.notification_schedule.label"/>- {{#if this.model.user_notification_schedule.enabled}}+ {{#if @model.user_notification_schedule.enabled}}<div class="instruction">{{i18n "user.notification_schedule.tip"}}</div><table class="notification-schedule-table">diff --git a/frontend/discourse/tests/integration/components/admin-penalty-post-action-test.gjs b/frontend/discourse/tests/integration/components/admin-penalty-post-action-test.gjsnew file mode 100644index 00000000000..0219a6dfb8d--- /dev/null+++ b/frontend/discourse/tests/integration/components/admin-penalty-post-action-test.gjs@@ -0,0 +1,60 @@+import { tracked } from "@glimmer/tracking";+import { click, fillIn, render } from "@ember/test-helpers";+import { module, test } from "qunit";+import AdminPenaltyPostAction from "discourse/admin/components/admin-penalty-post-action";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import selectKit from "discourse/tests/helpers/select-kit-helper";++module("Integration | Component | AdminPenaltyPostAction", function (hooks) {+ setupRenderingTest(hooks);++ test("reports the action and the edited post", async function (assert) {+ const postAction = tracked("delete");+ const edits = [];+ const readiness = [];+ const changePostAction = (value) => (postAction.value = value);+ const changePostEdit = (value) => edits.push(value);+ const deleteAllPostsReady = (ready) => readiness.push(ready);+ const user = { trust_level: 1, topic_count: 2, post_count: 5 };++ await render(+ <template>+ <div class="d-modal__body">+ <AdminPenaltyPostAction+ @onChangePostAction={{changePostAction}}+ @onChangePostEdit={{changePostEdit}}+ @onDeleteAllPostsReady={{deleteAllPostsReady}}+ @postAction={{postAction.value}}+ @postEdit="original post"+ @user={{user}}+ />+ </div>+ </template>+ );++ assert.dom(".post-editor").doesNotExist();++ await selectKit(".penalty-post-controls .combo-box").expand();+ await selectKit(".penalty-post-controls .combo-box").selectRowByValue(+ "edit"+ );++ assert.strictEqual(postAction.value, "edit", "reports the picked action");+ assert.dom(".post-editor").hasValue("original post");++ await fillIn(".post-editor", "edited post");+ assert.deepEqual(edits, ["edited post"], "reports the edited post");++ await selectKit(".penalty-post-controls .combo-box").expand();+ await selectKit(".penalty-post-controls .combo-box").selectRowByValue(+ "delete_all"+ );+ assert+ .dom(".penalty-post-controls .select-kit-header")+ .isFocused("returns focus to the dropdown for other actions");++ await click(".penalty-post-controls ~ label input[type='checkbox']");++ assert.deepEqual(readiness, [true], "reports the confirmed delete");+ });+});diff --git a/frontend/discourse/tests/integration/components/admin-penalty-reason-test.gjs b/frontend/discourse/tests/integration/components/admin-penalty-reason-test.gjsnew file mode 100644index 00000000000..77a2e4b055c--- /dev/null+++ b/frontend/discourse/tests/integration/components/admin-penalty-reason-test.gjs@@ -0,0 +1,42 @@+import { fillIn, render } from "@ember/test-helpers";+import { module, test } from "qunit";+import AdminPenaltyReason from "discourse/admin/components/admin-penalty-reason";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import selectKit from "discourse/tests/helpers/select-kit-helper";+import { i18n } from "discourse-i18n";++module("Integration | Component | AdminPenaltyReason", function (hooks) {+ setupRenderingTest(hooks);++ test("reports the reason and the message", async function (assert) {+ const reasons = [];+ const messages = [];+ const changeReason = (value) => reasons.push(value);+ const changeMessage = (value) => messages.push(value);++ await render(+ <template>+ <AdminPenaltyReason+ @message="initial message"+ @onChangeMessage={{changeMessage}}+ @onChangeReason={{changeReason}}+ @penaltyType="suspend"+ />+ </template>+ );++ assert.dom(".suspend-message").hasValue("initial message");++ await fillIn("input.suspend-reason", "custom reason");+ await selectKit(".suspend-reason").expand();+ await selectKit(".suspend-reason").selectRowByValue("combative");+ await fillIn(".suspend-message", "a message");++ assert.deepEqual(+ reasons,+ ["custom reason", i18n("admin.user.suspend_reasons.combative")],+ "reports the typed and the picked reason"+ );+ assert.deepEqual(messages, ["a message"], "reports the message");+ });+});diff --git a/frontend/discourse/tests/integration/components/groups-form-interaction-fields-test.gjs b/frontend/discourse/tests/integration/components/groups-form-interaction-fields-test.gjsnew file mode 100644index 00000000000..a18f89c802d--- /dev/null+++ b/frontend/discourse/tests/integration/components/groups-form-interaction-fields-test.gjs@@ -0,0 +1,43 @@+import { render } from "@ember/test-helpers";+import { module, test } from "qunit";+import GroupsFormInteractionFields from "discourse/components/groups-form-interaction-fields";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import selectKit from "discourse/tests/helpers/select-kit-helper";+import { i18n } from "discourse-i18n";++module(+ "Integration | Component | GroupsFormInteractionFields",+ function (hooks) {+ setupRenderingTest(hooks);++ test("shows and updates the alias levels", async function (assert) {+ const model = { mentionable_level: 0, messageable_level: 99 };++ await render(+ <template><GroupsFormInteractionFields @model={{model}} /></template>+ );++ const mentionable = selectKit(".groups-form-mentionable-level");+ assert.strictEqual(mentionable.header().value(), "0");+ assert.strictEqual(+ mentionable.header().label(),+ i18n("groups.alias_levels.nobody"),+ "shows the lowest level"+ );++ await mentionable.expand();+ await mentionable.selectRowByValue(3);++ assert.strictEqual(model.mentionable_level, 3, "writes the picked level");+ assert.strictEqual(+ mentionable.header().value(),+ "3",+ "shows the picked level"+ );+ assert.strictEqual(+ selectKit(".groups-form-messageable-level").header().value(),+ "99"+ );+ });+ }+);diff --git a/frontend/discourse/tests/integration/components/screened-ip-address-form-test.gjs b/frontend/discourse/tests/integration/components/screened-ip-address-form-test.gjsnew file mode 100644index 00000000000..0cd9fca652e--- /dev/null+++ b/frontend/discourse/tests/integration/components/screened-ip-address-form-test.gjs@@ -0,0 +1,38 @@+import { click, fillIn, render } from "@ember/test-helpers";+import { module, test } from "qunit";+import ScreenedIpAddressForm from "discourse/admin/components/screened-ip-address-form";+import { setupRenderingTest } from "discourse/tests/helpers/component-test";+import pretender, { response } from "discourse/tests/helpers/create-pretender";++module("Integration | Component | ScreenedIpAddressForm", function (hooks) {+ setupRenderingTest(hooks);++ test("reports the added address and clears the input", async function (assert) {+ pretender.post("/admin/logs/screened_ip_addresses.json", (request) => {+ const params = new URLSearchParams(request.requestBody);+ return response({+ screened_ip_address: {+ id: 1,+ ip_address: params.get("ip_address"),+ action_name: params.get("action_name"),+ },+ });+ });+ const added = [];+ const recordAdded = (record) => added.push(record);++ await render(+ <template><ScreenedIpAddressForm @action={{recordAdded}} /></template>+ );+ await fillIn(".ip-address-input", "1.2.3.4");+ await click(".screened-ip-address-form .btn-default");++ assert.deepEqual(+ added.map((record) => [record.ip_address, record.action_name]),+ [["1.2.3.4", "block"]],+ "reports the saved address"+ );+ assert.dom(".ip-address-input").hasValue("", "clears the input");+ assert.dom(".ip-address-input").isFocused("focuses the input again");+ });+});diff --git a/plugins/discourse-cakeday/assets/javascripts/discourse/connectors/user-custom-preferences/user-date-of-birth-input.gjs b/plugins/discourse-cakeday/assets/javascripts/discourse/connectors/user-custom-preferences/user-date-of-birth-input.gjsindex c9d0d66f9f9..f571bf52cb5 100644--- a/plugins/discourse-cakeday/assets/javascripts/discourse/connectors/user-custom-preferences/user-date-of-birth-input.gjs+++ b/plugins/discourse-cakeday/assets/javascripts/discourse/connectors/user-custom-preferences/user-date-of-birth-input.gjs@@ -1,47 +1,50 @@-/* eslint-disable ember/no-classic-components, ember/no-observers */-import Component from "@ember/component";-import { fn, hash } from "@ember/helper";-import { tagName } from "@ember-decorators/component";+import Component from "@glimmer/component";+import { tracked } from "@glimmer/tracking";+import { hash } from "@ember/helper";+import { action } from "@ember/object";+import { service } from "@ember/service";import ComboBox from "discourse/select-kit/components/combo-box";import { i18n } from "discourse-i18n";-@tagName("")export default class UserDateOfBirthInput extends Component {- init() {- super.init(...arguments);- const { model } = this;- const { birthdate } = model;- const months = moment.months().map((month, index) => {- return {- name: month,- value: index + 1,- };- });- const days = [...Array(31).keys()].map((d) => (d + 1).toString());- const month = birthdate- ? moment(birthdate, "YYYY-MM-DD").month() + 1- : null;- const day = birthdate- ? moment(birthdate, "YYYY-MM-DD").date().toString()- : null;- this.setProperties({- months,- days,- month,- day,- });- const updateBirthdate = () => {- let date = "";- if (this.month && this.day) {- date = `1904-${this.month}-${this.day}`;- }+ @service siteSettings;- // The property that is being serialized when sending the update- // request to the server is called `date_of_birth`- model.set("date_of_birth", date);- };- this.addObserver("month", updateBirthdate);- this.addObserver("day", updateBirthdate);+ @tracked month = null;+ @tracked day = null;++ months = moment.months().map((name, index) => ({ name, value: index + 1 }));+ days = [...Array(31).keys()].map((d) => (d + 1).toString());++ constructor() {+ super(...arguments);++ const { birthdate } = this.args.model;+ if (birthdate) {+ const date = moment(birthdate, "YYYY-MM-DD");+ this.month = date.month() + 1;+ this.day = date.date().toString();+ }+ }++ @action+ changeMonth(month) {+ this.month = month;+ this.#updateBirthdate();+ }++ @action+ changeDay(day) {+ this.day = day;+ this.#updateBirthdate();+ }++ #updateBirthdate() {+ // The property that is being serialized when sending the update+ // request to the server is called `date_of_birth`+ this.args.model.set(+ "date_of_birth",+ this.month && this.day ? `1904-${this.month}-${this.day}` : ""+ );}<template>@@ -58,7 +61,7 @@ export default class UserDateOfBirthInput extends Component {<ComboBox@content={{this.months}}@none="cakeday.none"- @onChange={{fn (mut this.month)}}+ @onChange={{this.changeMonth}}@options={{hash clearable=true autoInsertNoneItem=false}}@value={{this.month}}@valueAttribute="value"@@ -69,7 +72,7 @@ export default class UserDateOfBirthInput extends Component {@content={{this.days}}@nameProperty={{null}}@none="cakeday.none"- @onChange={{fn (mut this.day)}}+ @onChange={{this.changeDay}}@options={{hash clearable=true autoInsertNoneItem=false}}@value={{this.day}}@valueProperty={{null}}diff --git a/plugins/discourse-cakeday/test/javascripts/integration/components/user-date-of-birth-input-test.gjs b/plugins/discourse-cakeday/test/javascripts/integration/components/user-date-of-birth-input-test.gjsnew file mode 100644index 00000000000..e44680c4d6e--- /dev/null+++ b/plugins/discourse-cakeday/test/javascripts/integration/components/user-date-of-birth-input-test.gjs@@ -0,0 +1,38 @@+import EmberObject from "@ember/object";+import { 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 UserDateOfBirthInput from "discourse/plugins/discourse-cakeday/discourse/connectors/user-custom-preferences/user-date-of-birth-input";++module("Integration | Component | UserDateOfBirthInput", function (hooks) {+ setupRenderingTest(hooks);++ test("shows the birthdate and records changes", async function (assert) {+ this.siteSettings.cakeday_birthday_enabled = true;+ const model = EmberObject.create({ birthdate: "1904-03-05" });++ await render(+ <template><UserDateOfBirthInput @model={{model}} /></template>+ );++ const month = selectKit(".controls .combo-box:first-child");+ const day = selectKit(".controls .combo-box:last-child");+ assert.strictEqual(month.header().value(), "3", "shows the month");+ assert.strictEqual(day.header().value(), "5", "shows the day");++ await day.expand();+ await day.selectRowByValue("17");++ assert.strictEqual(+ model.date_of_birth,+ "1904-3-17",+ "records the new birthdate"+ );++ await month.expand();+ await month.selectRowByValue(11);++ assert.strictEqual(model.date_of_birth, "1904-11-17");+ });+});diff --git a/plugins/discourse-subscriptions/assets/javascripts/discourse/components/payment-options.gjs b/plugins/discourse-subscriptions/assets/javascripts/discourse/components/payment-options.gjsindex bc3a1ed31fb..d4c3d130438 100644--- a/plugins/discourse-subscriptions/assets/javascripts/discourse/components/payment-options.gjs+++ b/plugins/discourse-subscriptions/assets/javascripts/discourse/components/payment-options.gjs@@ -1,31 +1,20 @@-/* eslint-disable ember/no-classic-components */-import Component from "@ember/component";-import { action, computed } from "@ember/object";-import { tagName } from "@ember-decorators/component";+import Component from "@glimmer/component";+import { action } from "@ember/object";import { i18n } from "discourse-i18n";import PaymentPlan from "./payment-plan.gjs";-@tagName("")export default class PaymentOptions extends Component {- @computed("plans")get orderedPlans() {- if (this.plans) {- return this.plans.sort((a, b) =>+ if (this.args.plans) {+ return this.args.plans.toSorted((a, b) =>a.unit_amount > b.unit_amount ? 1 : -1);}}- didInsertElement() {- super.didInsertElement(...arguments);- if (this.plans && this.plans.length === 1) {- this.set("selectedPlan", this.plans[0].id);- }- }-@actionclickPlan(plan) {- this.set("selectedPlan", plan.id);+ this.args.onSelectPlan(plan.id);}<template>@@ -39,7 +28,7 @@ export default class PaymentOptions extends Component {<PaymentPlan@clickPlan={{this.clickPlan}}@plan={{plan}}- @selectedPlan={{this.selectedPlan}}+ @selectedPlan={{@selectedPlan}}/>{{/each}}</div>diff --git a/plugins/discourse-subscriptions/assets/javascripts/discourse/components/payment-plan.gjs b/plugins/discourse-subscriptions/assets/javascripts/discourse/components/payment-plan.gjsindex 7f2d563150f..78ffca1e648 100644--- a/plugins/discourse-subscriptions/assets/javascripts/discourse/components/payment-plan.gjs+++ b/plugins/discourse-subscriptions/assets/javascripts/discourse/components/payment-plan.gjs@@ -29,7 +29,7 @@ export default class PaymentPlan extends Component {"btn-discourse-subscriptions-subscribe"this.selectedClass}}- @action={{@planClick}}+ @action={{this.planClick}}><span class="interval">{{#if this.recurringPlan}}diff --git a/plugins/discourse-subscriptions/assets/javascripts/discourse/routes/subscribe/show.js b/plugins/discourse-subscriptions/assets/javascripts/discourse/routes/subscribe/show.jsindex 1ec4f42c25f..03b02bf6b06 100644--- a/plugins/discourse-subscriptions/assets/javascripts/discourse/routes/subscribe/show.js+++ b/plugins/discourse-subscriptions/assets/javascripts/discourse/routes/subscribe/show.js@@ -16,4 +16,12 @@ export default class SubscribeShowRoute extends Route {return result;});}++ setupController(controller, model) {+ super.setupController(...arguments);+ controller.set(+ "selectedPlan",+ model.plans.length === 1 ? model.plans[0].id : null+ );+ }}diff --git a/plugins/discourse-subscriptions/assets/javascripts/discourse/templates/subscribe/show.gjs b/plugins/discourse-subscriptions/assets/javascripts/discourse/templates/subscribe/show.gjsindex 07ac7299ded..2c5fa5c4cc0 100644--- a/plugins/discourse-subscriptions/assets/javascripts/discourse/templates/subscribe/show.gjs+++ b/plugins/discourse-subscriptions/assets/javascripts/discourse/templates/subscribe/show.gjs@@ -1,4 +1,5 @@import { Input } from "@ember/component";+import { fn } from "@ember/helper";import { LinkTo } from "@ember/routing";import { trustHTML } from "@ember/template";import DButton from "discourse/ui-kit/d-button";@@ -34,6 +35,7 @@ export default <template><hr /><PaymentOptions+ @onSelectPlan={{fn (mut @controller.selectedPlan)}}@plans={{@controller.model.plans}}@selectedPlan={{@controller.selectedPlan}}/>diff --git a/plugins/discourse-subscriptions/test/javascripts/integration/components/payment-options-test.gjs b/plugins/discourse-subscriptions/test/javascripts/integration/components/payment-options-test.gjsindex 8b4540b0842..963cbd6148e 100644--- a/plugins/discourse-subscriptions/test/javascripts/integration/components/payment-options-test.gjs+++ b/plugins/discourse-subscriptions/test/javascripts/integration/components/payment-options-test.gjs@@ -1,5 +1,5 @@import { tracked } from "@glimmer/tracking";-import { render } from "@ember/test-helpers";+import { click, render } from "@ember/test-helpers";import { module, test } from "qunit";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import PaymentOptions from "discourse/plugins/discourse-subscriptions/discourse/components/payment-options";@@ -45,4 +45,34 @@ module("payment-options", function (hooks) {"No plans are selected by default");});+ test("selecting a plan reports it", async function (assert) {+ const plans = [+ { id: "plan_yearly", currency: "aud", unit_amount: 4499 },+ { id: "plan_monthly", currency: "aud", unit_amount: 999 },+ ];+ const selectedPlan = tracked(undefined);+ const selectPlan = (id) => (selectedPlan.value = id);++ await render(+ <template>+ <PaymentOptions+ @onSelectPlan={{selectPlan}}+ @plans={{plans}}+ @selectedPlan={{selectedPlan.value}}+ />+ </template>+ );++ await click(".btn-discourse-subscriptions-subscribe:last-child");++ assert.strictEqual(selectedPlan.value, "plan_yearly");+ assert+ .dom(".btn-discourse-subscriptions-subscribe:last-child")+ .hasClass("btn-primary", "highlights the selected plan");+ assert.deepEqual(+ plans.map((plan) => plan.id),+ ["plan_yearly", "plan_monthly"],+ "leaves the plans in their original order"+ );+ });});