FIX: Anons should see the Topic slow mode notice. (#12460)

This commit is contained in:
Roman Rizzi 2021-03-22 13:55:45 -03:00 committed by GitHub
parent ec7415ff49
commit e4ec0da714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 3 deletions

View File

@ -11,9 +11,9 @@ export default Component.extend({
return durationTextFromSeconds(seconds);
},
@discourseComputed("user", "topic.slow_mode_seconds", "topic.closed")
showSlowModeNotice(user, seconds, closed) {
return user && seconds > 0 && !closed;
@discourseComputed("topic.slow_mode_seconds", "topic.closed")
showSlowModeNotice(seconds, closed) {
return seconds > 0 && !closed;
},
@action

View File

@ -0,0 +1,80 @@
import componentTest, {
setupRenderingTest,
} from "discourse/tests/helpers/component-test";
import {
discourseModule,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
discourseModule("Integration | Component | slow-mode-info", function (hooks) {
setupRenderingTest(hooks);
componentTest("doesn't render if the topic is closed", {
template: "{{slow-mode-info topic=topic}}",
beforeEach() {
this.set("topic", { slow_mode_seconds: 3600, closed: true });
},
test(assert) {
assert.ok(!exists(".slow-mode-heading"), "it doesn't render the notice");
},
});
componentTest("doesn't render if the slow mode is disabled", {
template: "{{slow-mode-info topic=topic}}",
beforeEach() {
this.set("topic", { slow_mode_seconds: 0, closed: false });
},
test(assert) {
assert.ok(!exists(".slow-mode-heading"), "it doesn't render the notice");
},
});
componentTest("renders if slow mode is enabled", {
template: "{{slow-mode-info topic=topic}}",
beforeEach() {
this.set("topic", { slow_mode_seconds: 3600, closed: false });
},
test(assert) {
assert.ok(queryAll(".slow-mode-heading").length === 1);
},
});
componentTest("staff and TL4 users can disable slow mode", {
template: "{{slow-mode-info topic=topic user=user}}",
beforeEach() {
this.setProperties({
topic: { slow_mode_seconds: 3600, closed: false },
user: { canManageTopic: true },
});
},
test(assert) {
assert.ok(queryAll(".slow-mode-remove").length === 1);
},
});
componentTest("regular users can't disable slow mode", {
template: "{{slow-mode-info topic=topic user=user}}",
beforeEach() {
this.setProperties({
topic: { slow_mode_seconds: 3600, closed: false },
user: { canManageTopic: false },
});
},
test(assert) {
assert.ok(
!exists(".slow-mode-remove"),
"it doesn't let you disable slow mode"
);
},
});
});