A platform for community discussion. Free, open, simple.
FIX: Keep the pin topic form while typing a custom time (#45007)
Régis Hanol1df4383de135
diff --git a/frontend/discourse/app/components/modal/feature-topic/pin-option-section.gjs b/frontend/discourse/app/components/modal/feature-topic/pin-option-section.gjsindex 95ee36c2f20..dfa35043da8 100644--- a/frontend/discourse/app/components/modal/feature-topic/pin-option-section.gjs+++ b/frontend/discourse/app/components/modal/feature-topic/pin-option-section.gjs@@ -1,5 +1,4 @@import Component from "@glimmer/component";-import { cached } from "@glimmer/tracking";import { action } from "@ember/object";import { service } from "@ember/service";import { trustHTML } from "@ember/template";@@ -15,10 +14,7 @@ export const MAX_GLOBALLY_PINNED_TOPICS = 4;export default class PinOptionSection extends Component {@service dialog;- @cached- get formData() {- return { pinUntil: this.args.dateValue };- }+ formData = { pinUntil: this.args.dateValue };@actionvalidatePinUntil(name, value, { addError }) {@@ -32,8 +28,7 @@ export default class PinOptionSection extends Component {}@action- handleDateSet(value, { set }) {- set("pinUntil", value);+ handleDateSet(name, value) {this.args.onDateChange?.(value);}@@ -53,6 +48,7 @@ export default class PinOptionSection extends Component {<Formclass="feature-section"@data={{this.formData}}+ @onSet={{this.handleDateSet}}@onSubmit={{this.handleSubmit}}as |form|>@@ -71,7 +67,6 @@ export default class PinOptionSection extends Component {<form.Field@name="pinUntil"- @onSet={{this.handleDateSet}}@showTitle={{false}}@title={{i18n "topic.feature_topic.pin_until"}}@type="custom"diff --git a/frontend/discourse/tests/acceptance/topic-test.js b/frontend/discourse/tests/acceptance/topic-test.jsindex dd426b0d0da..329d7f2201d 100644--- a/frontend/discourse/tests/acceptance/topic-test.js+++ b/frontend/discourse/tests/acceptance/topic-test.js@@ -2,6 +2,7 @@ import {click,currentURL,fillIn,+ find,triggerKeyEvent,visit,} from "@ember/test-helpers";@@ -9,6 +10,10 @@ import { test } from "qunit";import { cloneJSON } from "discourse/lib/object";import CategoryFixtures from "discourse/tests/fixtures/category-fixtures";import topicFixtures from "discourse/tests/fixtures/topic";+import pretender, {+ parsePostData,+ response,+} from "discourse/tests/helpers/create-pretender";import {acceptance,chromeTest,@@ -485,6 +490,47 @@ acceptance(`Topic pinning/unpinning as an admin`, function (needs) {.exists("should show the 'Pin Topic' button");assert.dom(".make-banner").exists("should show the 'Banner Topic' button");++ const futureDateInput = selectKit(".pin-until .future-date-input-selector");+ await futureDateInput.expand();+ await futureDateInput.selectRowByValue("tomorrow");+ await visit("/");++ assert.strictEqual(currentURL(), "/", "navigates without confirmation");+ });++ test("Pinning a topic until a custom date and time", async function (assert) {+ let pinnedUntil;+ pretender.put(+ "/t/a-topic-with-group-category-moderators/2480/status",+ (request) => {+ pinnedUntil = parsePostData(request.requestBody).until;+ return response({ success: "OK" });+ }+ );++ await visit("/t/topic-for-group-moderators/2480");++ await click(".toggle-admin-menu");+ await click(".topic-admin-pin .btn");++ const futureDateInput = selectKit(".pin-until .future-date-input-selector");+ await futureDateInput.expand();+ await futureDateInput.selectRowByValue("custom");++ await fillIn(".pin-until .date-picker", "2100-11-24");++ const timeInput = find(".pin-until .time-input");+ await fillIn(timeInput, "01:00");+ await fillIn(timeInput, "13:45");++ await click(".feature-topic .btn-primary");++ assert.strictEqual(+ pinnedUntil.slice(0, 16),+ "2100-11-24 13:45",+ "pins until the typed date and time"+ );});test("Pinning a topic should consider user's timezone when selecting the later today date shortcut", async function (assert) {