mirror of
https://github.com/discourse/discourse.git
synced 2025-04-26 20:44:28 +08:00
DEV: Fix failing share topic tests (#16309)
Since 3fd7b31a2aa79dabcc34625c10877fcf737d5855 some tests were failing with this error: > Error: Unhandled request in test environment: /c/feature/find_by_slug.json > (GET) at http://localhost:7357/assets/test-helpers.js This commit fixes the issue by adding the missing pretender. Also noticed while fixing this that the parameter for the translation was incorrect -- it was `group` instead of `groupNames`, so that is fixed here too, along with moving the onShow functions into @afterRender decorated private functions. There is no need for the appevent listeners.
This commit is contained in:
parent
1516dd75f5
commit
f0574564c4
@ -1,7 +1,9 @@
|
|||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { getAbsoluteURL } from "discourse-common/lib/get-url";
|
import { getAbsoluteURL } from "discourse-common/lib/get-url";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed, {
|
||||||
|
afterRender,
|
||||||
|
} from "discourse-common/utils/decorators";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { extractError } from "discourse/lib/ajax-error";
|
import { extractError } from "discourse/lib/ajax-error";
|
||||||
import Sharing from "discourse/lib/sharing";
|
import Sharing from "discourse/lib/sharing";
|
||||||
@ -16,38 +18,26 @@ export default Controller.extend(
|
|||||||
bufferedProperty("invite"),
|
bufferedProperty("invite"),
|
||||||
{
|
{
|
||||||
topic: null,
|
topic: null,
|
||||||
restrictedGroups: null,
|
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
this.set("showNotifyUsers", false);
|
this.set("showNotifyUsers", false);
|
||||||
|
|
||||||
this.appEvents.on(
|
this._showRestrictedGroupWarning();
|
||||||
"modal:body-shown",
|
|
||||||
this,
|
|
||||||
this.showRestrictedGroupWarning
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onClose() {
|
@afterRender
|
||||||
this.appEvents.off(
|
_showRestrictedGroupWarning() {
|
||||||
"modal:body-shown",
|
|
||||||
this,
|
|
||||||
this.showRestrictedGroupWarning
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
showRestrictedGroupWarning() {
|
|
||||||
if (!this.model) {
|
if (!this.model) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Category.reloadBySlugPath(this.model.slug).then((result) => {
|
Category.reloadBySlugPath(this.model.slug).then((result) => {
|
||||||
const groups = result.category.group_permissions.mapBy("group_name");
|
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(
|
this.flash(
|
||||||
I18n.t("topic.share.restricted_groups", {
|
I18n.t("topic.share.restricted_groups", {
|
||||||
count: groups.length,
|
count: groups.length,
|
||||||
groups: groups.join(", "),
|
groupNames: groups.join(", "),
|
||||||
}),
|
}),
|
||||||
"warning"
|
"warning"
|
||||||
);
|
);
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import CategoryFixtures from "discourse/tests/fixtures/category-fixtures";
|
import CategoryFixtures from "discourse/tests/fixtures/category-fixtures";
|
||||||
|
import I18n from "I18n";
|
||||||
import { click, visit } from "@ember/test-helpers";
|
import { click, visit } from "@ember/test-helpers";
|
||||||
import {
|
import {
|
||||||
acceptance,
|
acceptance,
|
||||||
count,
|
count,
|
||||||
exists,
|
exists,
|
||||||
|
query,
|
||||||
queryAll,
|
queryAll,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||||
@ -29,6 +31,10 @@ acceptance("Share and Invite modal", function (needs) {
|
|||||||
await click("#topic-footer-button-share-and-invite");
|
await click("#topic-footer-button-share-and-invite");
|
||||||
|
|
||||||
assert.ok(exists(".share-topic-modal"), "it shows the modal");
|
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(
|
assert.ok(
|
||||||
queryAll("input.invite-link")
|
queryAll("input.invite-link")
|
||||||
@ -71,6 +77,14 @@ acceptance("Share and Invite modal", function (needs) {
|
|||||||
exists("#modal-alert.alert-warning"),
|
exists("#modal-alert.alert-warning"),
|
||||||
"it shows restricted 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"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -78,6 +92,12 @@ acceptance("Share and Invite modal - mobile", function (needs) {
|
|||||||
needs.user();
|
needs.user();
|
||||||
needs.mobileView();
|
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) {
|
test("Topic footer mobile button", async function (assert) {
|
||||||
await visit("/t/internationalization-localization/280");
|
await visit("/t/internationalization-localization/280");
|
||||||
|
|
||||||
@ -97,6 +117,13 @@ acceptance("Share and Invite modal - mobile", function (needs) {
|
|||||||
acceptance("Share url with badges disabled - desktop", function (needs) {
|
acceptance("Share url with badges disabled - desktop", function (needs) {
|
||||||
needs.user();
|
needs.user();
|
||||||
needs.settings({ enable_badges: false });
|
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) {
|
test("topic footer button - badges disabled - desktop", async function (assert) {
|
||||||
await visit("/t/internationalization-localization/280");
|
await visit("/t/internationalization-localization/280");
|
||||||
await click("#topic-footer-button-share-and-invite");
|
await click("#topic-footer-button-share-and-invite");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user