Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix failing share topic tests (#16309)

Martin Brennan045be237a057
diff --git a/app/assets/javascripts/discourse/app/controllers/share-topic.js b/app/assets/javascripts/discourse/app/controllers/share-topic.js
index def7fe308a8..46a09006ea9 100644
--- a/app/assets/javascripts/discourse/app/controllers/share-topic.js
+++ b/app/assets/javascripts/discourse/app/controllers/share-topic.js
@@ -1,7 +1,9 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { getAbsoluteURL } from "discourse-common/lib/get-url";
-import discourseComputed from "discourse-common/utils/decorators";
+import discourseComputed, {
+ afterRender,
+} from "discourse-common/utils/decorators";
import { longDateNoYear } from "discourse/lib/formatter";
import Sharing from "discourse/lib/sharing";
import showModal from "discourse/lib/show-modal";
@@ -9,7 +11,6 @@ import { bufferedProperty } from "discourse/mixins/buffered-content";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import I18n from "I18n";
import Category from "discourse/models/category";
-import { scheduleOnce } from "@ember/runloop";
import { getOwner } from "discourse-common/lib/get-owner";
export default Controller.extend(
@@ -19,7 +20,6 @@ export default Controller.extend(
topic: null,
post: null,
allowInvites: false,
- restrictedGroups: null,
onShow() {
this.setProperties({
@@ -28,35 +28,23 @@ export default Controller.extend(
allowInvites: false,
});
- this.appEvents.on(
- "modal:body-shown",
- this,
- this.showRestrictedGroupWarning
- );
-
- scheduleOnce("afterRender", this, this.selectUrl);
- },
-
- onClose() {
- this.appEvents.off(
- "modal:body-shown",
- this,
- this.showRestrictedGroupWarning
- );
+ this._showRestrictedGroupWarning();
+ this._selectUrl();
},
- showRestrictedGroupWarning() {
+ @afterRender
+ _showRestrictedGroupWarning() {
if (!this.model) {
return;
}
Category.reloadBySlugPath(this.model.slug).then((result) => {
const groups = result.category.group_permissions.mapBy("group_name");
- if (groups && !groups.any((x) => x === "everyone")) {
+ if (groups && !groups.any((group) => group === "everyone")) {
this.flash(
I18n.t("topic.share.restricted_groups", {
count: groups.length,
- groups: groups.join(", "),
+ groupNames: groups.join(", "),
}),
"warning"
);
@@ -64,7 +52,8 @@ export default Controller.extend(
});
},
- selectUrl() {
+ @afterRender
+ _selectUrl() {
const input = document.querySelector("input.invite-link");
if (input && !this.site.mobileView) {
// if the input is auto-focused on mobile, iOS requires two taps of the copy button
diff --git a/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js b/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js
index c1cb5afc9ee..e028b05ab12 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/share-topic-test.js
@@ -1,8 +1,10 @@
import CategoryFixtures from "discourse/tests/fixtures/category-fixtures";
+import I18n from "I18n";
import { click, visit } from "@ember/test-helpers";
import {
acceptance,
exists,
+ query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
@@ -28,6 +30,10 @@ acceptance("Share and Invite modal", function (needs) {
await click("#topic-footer-button-share-and-invite");
assert.ok(exists(".share-topic-modal"), "it shows the modal");
+ assert.notOk(
+ exists("#modal-alert.alert-warning"),
+ "it does not show the alert with restricted groups"
+ );
assert.ok(
queryAll("input.invite-link")
@@ -64,6 +70,14 @@ acceptance("Share and Invite modal", function (needs) {
exists("#modal-alert.alert-warning"),
"it shows restricted warning"
);
+ assert.strictEqual(
+ query("#modal-alert.alert-warning").innerText,
+ I18n.t("topic.share.restricted_groups", {
+ count: 1,
+ groupNames: "moderators",
+ }),
+ "it shows correct restricted group name"
+ );
});
});
@@ -71,6 +85,12 @@ acceptance("Share and Invite modal - mobile", function (needs) {
needs.user();
needs.mobileView();
+ needs.pretender((server, helper) => {
+ server.get("/c/feature/find_by_slug.json", () =>
+ helper.response(200, CategoryFixtures["/c/1/show.json"])
+ );
+ });
+
test("Topic footer mobile button", async function (assert) {
await visit("/t/internationalization-localization/280");
@@ -90,6 +110,13 @@ acceptance("Share and Invite modal - mobile", function (needs) {
acceptance("Share url with badges disabled - desktop", function (needs) {
needs.user();
needs.settings({ enable_badges: false });
+
+ needs.pretender((server, helper) => {
+ server.get("/c/feature/find_by_slug.json", () =>
+ helper.response(200, CategoryFixtures["/c/1/show.json"])
+ );
+ });
+
test("topic footer button - badges disabled - desktop", async function (assert) {
await visit("/t/internationalization-localization/280");
await click("#topic-footer-button-share-and-invite");