mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 22:25:48 +08:00
FIX: Don't show like error on topic creation (#24084)
This commit is contained in:
parent
5c38e55dc9
commit
115a05f37a
@ -1,6 +1,6 @@
|
|||||||
import { getOwner } from "@ember/application";
|
import { getOwner } from "@ember/application";
|
||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
import EmberObject from "@ember/object";
|
import EmberObject, { computed } from "@ember/object";
|
||||||
import { alias } from "@ember/object/computed";
|
import { alias } from "@ember/object/computed";
|
||||||
import { next, schedule, throttle } from "@ember/runloop";
|
import { next, schedule, throttle } from "@ember/runloop";
|
||||||
import { BasePlugin } from "@uppy/core";
|
import { BasePlugin } from "@uppy/core";
|
||||||
@ -285,7 +285,7 @@ export default Component.extend(ComposerUploadUppy, {
|
|||||||
count: minimumPostLength,
|
count: minimumPostLength,
|
||||||
});
|
});
|
||||||
const tl = this.get("currentUser.trust_level");
|
const tl = this.get("currentUser.trust_level");
|
||||||
if (tl === 0 || tl === 1) {
|
if ((tl === 0 || tl === 1) && !this._isNewTopic) {
|
||||||
reason +=
|
reason +=
|
||||||
"<br/>" +
|
"<br/>" +
|
||||||
I18n.t("composer.error.try_like", {
|
I18n.t("composer.error.try_like", {
|
||||||
@ -305,6 +305,15 @@ export default Component.extend(ComposerUploadUppy, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed("composer.{creatingTopic,editingFirstPost,creatingSharedDraft}")
|
||||||
|
get _isNewTopic() {
|
||||||
|
return (
|
||||||
|
this.composer.creatingTopic ||
|
||||||
|
this.composer.editingFirstPost ||
|
||||||
|
this.composer.creatingSharedDraft
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
_resetShouldBuildScrollMap() {
|
_resetShouldBuildScrollMap() {
|
||||||
this.set("shouldBuildScrollMap", true);
|
this.set("shouldBuildScrollMap", true);
|
||||||
},
|
},
|
||||||
|
71
spec/system/composer/post_validation_spec.rb
Normal file
71
spec/system/composer/post_validation_spec.rb
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe "Composer Post Validations", type: :system, js: true do
|
||||||
|
fab!(:tl0_user) { Fabricate(:user, trust_level: 0) }
|
||||||
|
fab!(:tl1_user) { Fabricate(:user, trust_level: 1) }
|
||||||
|
fab!(:tl2_user) { Fabricate(:user, trust_level: 2) }
|
||||||
|
fab!(:topic) { Fabricate(:topic) }
|
||||||
|
fab!(:post) { Fabricate(:post, topic: topic) }
|
||||||
|
|
||||||
|
let(:composer) { PageObjects::Components::Composer.new }
|
||||||
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||||
|
|
||||||
|
shared_examples "post length validation" do
|
||||||
|
context "when creating a topic" do
|
||||||
|
it "shows an error when post length is insufficient" do
|
||||||
|
visit("/latest")
|
||||||
|
page.find("#create-topic").click
|
||||||
|
composer.fill_content("abc")
|
||||||
|
composer.create
|
||||||
|
composer.have_post_error(I18n.t("js.composer.error.post_length"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when replying to a topic" do
|
||||||
|
it "shows an error to like instead when post length is insufficient" do
|
||||||
|
topic_page.visit_topic_and_open_composer(topic)
|
||||||
|
composer.fill_content("abc")
|
||||||
|
composer.create
|
||||||
|
composer.have_post_error(
|
||||||
|
"#{I18n.t("js.composer.error.post_length")} #{I18n.t("js.composer.error.try_like")}",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "trust level 0 user" do
|
||||||
|
before { sign_in(tl0_user) }
|
||||||
|
include_examples "post length validation"
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "trust level 1 user" do
|
||||||
|
before { sign_in(tl1_user) }
|
||||||
|
include_examples "post length validation"
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "trust level 2 user" do
|
||||||
|
before { sign_in(tl2_user) }
|
||||||
|
|
||||||
|
context "when creating a topic" do
|
||||||
|
it "shows an error when post length is insufficient" do
|
||||||
|
visit("/latest")
|
||||||
|
page.find("#create-topic").click
|
||||||
|
composer.fill_content("abc")
|
||||||
|
composer.create
|
||||||
|
composer.have_post_error(I18n.t("js.composer.error.post_length"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when replying to a topic" do
|
||||||
|
it "does not show an error to like when post length is insufficient" do
|
||||||
|
topic_page.visit_topic_and_open_composer(topic)
|
||||||
|
composer.fill_content("abc")
|
||||||
|
composer.create
|
||||||
|
composer.have_post_error("#{I18n.t("js.composer.error.post_length")}")
|
||||||
|
composer.have_no_post_error(
|
||||||
|
"#{I18n.t("js.composer.error.post_length")} #{I18n.t("js.composer.error.try_like")}",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -192,6 +192,14 @@ module PageObjects
|
|||||||
page.has_css?(".form-template-field__description", text: description)
|
page.has_css?(".form-template-field__description", text: description)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_post_error?(error)
|
||||||
|
page.has_css?(".popup-tip", text: error, visible: all)
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_no_post_error?(error)
|
||||||
|
page.has_no_css?(".popup-tip", text: error, visible: all)
|
||||||
|
end
|
||||||
|
|
||||||
def composer_input
|
def composer_input
|
||||||
find("#{COMPOSER_ID} .d-editor .d-editor-input")
|
find("#{COMPOSER_ID} .d-editor .d-editor-input")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user