mirror of
https://github.com/discourse/discourse.git
synced 2025-02-17 08:45:05 +00:00
DEV: Add a test for the "duplicate link" message (#21139)
A followup to cb1e95cd3d16c1550596cee33ef361402d1bec0b --- `warning_message = nil` in the rb file was an unused variable
This commit is contained in:
parent
0650504bf5
commit
0cd8659b06
@ -649,27 +649,30 @@ export default class ComposerController extends Controller {
|
|||||||
|
|
||||||
const [linkWarn, linkInfo] = linkLookup.check(post, href);
|
const [linkWarn, linkInfo] = linkLookup.check(post, href);
|
||||||
|
|
||||||
if (linkWarn && !this.get("isWhispering")) {
|
if (linkWarn && !this.isWhispering) {
|
||||||
let body;
|
|
||||||
if (linkInfo.username === this.currentUser.username) {
|
if (linkInfo.username === this.currentUser.username) {
|
||||||
body = I18n.t("composer.duplicate_link_same_user", {
|
this.appEvents.trigger("composer-messages:create", {
|
||||||
domain: linkInfo.domain,
|
extraClass: "custom-body",
|
||||||
post_url: topic.urlForPostNumber(linkInfo.post_number),
|
templateName: "education",
|
||||||
ago: shortDate(linkInfo.posted_at),
|
body: I18n.t("composer.duplicate_link_same_user", {
|
||||||
|
domain: linkInfo.domain,
|
||||||
|
post_url: topic.urlForPostNumber(linkInfo.post_number),
|
||||||
|
ago: shortDate(linkInfo.posted_at),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
body = I18n.t("composer.duplicate_link", {
|
this.appEvents.trigger("composer-messages:create", {
|
||||||
domain: linkInfo.domain,
|
extraClass: "custom-body duplicate-link-message",
|
||||||
username: linkInfo.username,
|
templateName: "education",
|
||||||
post_url: topic.urlForPostNumber(linkInfo.post_number),
|
body: I18n.t("composer.duplicate_link", {
|
||||||
ago: shortDate(linkInfo.posted_at),
|
domain: linkInfo.domain,
|
||||||
|
username: linkInfo.username,
|
||||||
|
post_url: topic.urlForPostNumber(linkInfo.post_number),
|
||||||
|
ago: shortDate(linkInfo.posted_at),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.appEvents.trigger("composer-messages:create", {
|
|
||||||
extraClass: "custom-body",
|
|
||||||
templateName: "education",
|
|
||||||
body,
|
|
||||||
});
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,16 @@ import {
|
|||||||
exists,
|
exists,
|
||||||
query,
|
query,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
|
import {
|
||||||
|
click,
|
||||||
|
fillIn,
|
||||||
|
triggerKeyEvent,
|
||||||
|
visit,
|
||||||
|
waitUntil,
|
||||||
|
} from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
import pretender, { response } from "../helpers/create-pretender";
|
||||||
|
|
||||||
acceptance("Composer - Messages", function (needs) {
|
acceptance("Composer - Messages", function (needs) {
|
||||||
needs.user();
|
needs.user();
|
||||||
@ -22,13 +29,14 @@ acceptance("Composer - Messages", function (needs) {
|
|||||||
test("Shows warning in composer if user hasn't been seen in a long time.", async function (assert) {
|
test("Shows warning in composer if user hasn't been seen in a long time.", async function (assert) {
|
||||||
await visit("/u/charlie");
|
await visit("/u/charlie");
|
||||||
await click("button.compose-pm");
|
await click("button.compose-pm");
|
||||||
assert.ok(
|
assert.false(
|
||||||
!exists(".composer-popup"),
|
exists(".composer-popup"),
|
||||||
"composer warning is not shown by default"
|
"composer warning is not shown by default"
|
||||||
);
|
);
|
||||||
|
|
||||||
await triggerKeyEvent(".d-editor-input", "keyup", "Space");
|
await triggerKeyEvent(".d-editor-input", "keyup", "Space");
|
||||||
assert.ok(exists(".composer-popup"), "shows composer warning message");
|
assert.true(exists(".composer-popup"), "shows composer warning message");
|
||||||
assert.ok(
|
assert.true(
|
||||||
query(".composer-popup").innerHTML.includes(
|
query(".composer-popup").innerHTML.includes(
|
||||||
I18n.t("composer.user_not_seen_in_a_while.single", {
|
I18n.t("composer.user_not_seen_in_a_while.single", {
|
||||||
usernames: ['<a class="mention" href="/u/charlie">@charlie</a>'],
|
usernames: ['<a class="mention" href="/u/charlie">@charlie</a>'],
|
||||||
@ -60,13 +68,14 @@ acceptance("Composer - Messages - Cannot see group", function (needs) {
|
|||||||
test("Shows warning in composer if group hasn't been invited", async function (assert) {
|
test("Shows warning in composer if group hasn't been invited", async function (assert) {
|
||||||
await visit("/t/130");
|
await visit("/t/130");
|
||||||
await click("button.create");
|
await click("button.create");
|
||||||
assert.ok(
|
assert.false(
|
||||||
!exists(".composer-popup"),
|
exists(".composer-popup"),
|
||||||
"composer warning is not shown by default"
|
"composer warning is not shown by default"
|
||||||
);
|
);
|
||||||
|
|
||||||
await fillIn(".d-editor-input", "Mention @staff");
|
await fillIn(".d-editor-input", "Mention @staff");
|
||||||
assert.ok(exists(".composer-popup"), "shows composer warning message");
|
assert.true(exists(".composer-popup"), "shows composer warning message");
|
||||||
assert.ok(
|
assert.true(
|
||||||
query(".composer-popup").innerHTML.includes(
|
query(".composer-popup").innerHTML.includes(
|
||||||
I18n.t("composer.cannot_see_group_mention.not_allowed", {
|
I18n.t("composer.cannot_see_group_mention.not_allowed", {
|
||||||
group: "staff",
|
group: "staff",
|
||||||
@ -79,13 +88,14 @@ acceptance("Composer - Messages - Cannot see group", function (needs) {
|
|||||||
test("Shows warning in composer if group hasn't been invited, but some members have access already", async function (assert) {
|
test("Shows warning in composer if group hasn't been invited, but some members have access already", async function (assert) {
|
||||||
await visit("/t/130");
|
await visit("/t/130");
|
||||||
await click("button.create");
|
await click("button.create");
|
||||||
assert.ok(
|
assert.false(
|
||||||
!exists(".composer-popup"),
|
exists(".composer-popup"),
|
||||||
"composer warning is not shown by default"
|
"composer warning is not shown by default"
|
||||||
);
|
);
|
||||||
|
|
||||||
await fillIn(".d-editor-input", "Mention @staff2");
|
await fillIn(".d-editor-input", "Mention @staff2");
|
||||||
assert.ok(exists(".composer-popup"), "shows composer warning message");
|
assert.true(exists(".composer-popup"), "shows composer warning message");
|
||||||
assert.ok(
|
assert.true(
|
||||||
query(".composer-popup").innerHTML.includes(
|
query(".composer-popup").innerHTML.includes(
|
||||||
I18n.t("composer.cannot_see_group_mention.some_not_allowed", {
|
I18n.t("composer.cannot_see_group_mention.some_not_allowed", {
|
||||||
group: "staff2",
|
group: "staff2",
|
||||||
@ -96,3 +106,54 @@ acceptance("Composer - Messages - Cannot see group", function (needs) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
acceptance("Composer - Messages - Duplicate links", function (needs) {
|
||||||
|
needs.user();
|
||||||
|
|
||||||
|
test("Shows the warning", async function (assert) {
|
||||||
|
pretender.get("/inline-onebox", () =>
|
||||||
|
response({
|
||||||
|
"inline-oneboxes": [],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
let receivedMessages = false;
|
||||||
|
pretender.get("/composer_messages", () => {
|
||||||
|
receivedMessages = true;
|
||||||
|
return response({
|
||||||
|
composer_messages: [],
|
||||||
|
extras: {
|
||||||
|
duplicate_lookup: {
|
||||||
|
"test.localhost/t/testing-topic/123/4567": {
|
||||||
|
domain: "test.localhost",
|
||||||
|
username: "uwe_keim",
|
||||||
|
posted_at: "2021-01-01T12:00:00.000Z",
|
||||||
|
post_number: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await visit("/t/internationalization-localization/280");
|
||||||
|
await click("button.create");
|
||||||
|
|
||||||
|
// Work around the lack of CSS transitions in the test env
|
||||||
|
query("#reply-control").dispatchEvent(new Event("transitionend"));
|
||||||
|
|
||||||
|
assert
|
||||||
|
.dom(".composer-popup")
|
||||||
|
.doesNotExist("composer warning is not shown by default");
|
||||||
|
|
||||||
|
await waitUntil(() => receivedMessages);
|
||||||
|
|
||||||
|
await fillIn(
|
||||||
|
".d-editor-input",
|
||||||
|
"Here's a link: https://test.localhost/t/testing-topic/123/4567"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert
|
||||||
|
.dom(".composer-popup.duplicate-link-message")
|
||||||
|
.exists("shows composer warning message");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -22,7 +22,6 @@ class ComposerMessagesController < ApplicationController
|
|||||||
usernames = params.require(:usernames)
|
usernames = params.require(:usernames)
|
||||||
users = ComposerMessagesFinder.user_not_seen_in_a_while(usernames)
|
users = ComposerMessagesFinder.user_not_seen_in_a_while(usernames)
|
||||||
user_count = users.count
|
user_count = users.count
|
||||||
warning_message = nil
|
|
||||||
|
|
||||||
if user_count > 0
|
if user_count > 0
|
||||||
message_locale =
|
message_locale =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user