Skip to content

Commit

Permalink
Merge branch 'main' of github.com:paviliondev/discourse-mentionables …
Browse files Browse the repository at this point in the history
…into main
  • Loading branch information
merefield committed Jun 26, 2024
2 parents 54f94b8 + dcbb7f9 commit e24ddd8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default {
key: SEPARATOR,
afterComplete: (value) => {
this.set("value", value);
return this._focusTextArea();
return this.focusTextArea();
},
transformComplete: (item) => item.model.slug,
dataSource: (term) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ function replaceSpan($elem, item_data) {
}

export function linkSeenMentionableItems(elem, siteSettings) {
const mentionableItems = elem.querySelector("span.mentionable-item");
const mentionableItems = elem.querySelectorAll("span.mentionable-item");

if (!mentionableItems || !mentionableItems.length === 0) {
return [];
}

const items = [
...mentionableItems.map((_, mentionableitem) =>
mentionableitem.innerText.substr(1)
),
];
const items = [...mentionableItems].map((mentionableitem) => {
return mentionableitem.innerText.substr(1);
});

mentionableItems.each((index, mentionableitem) => {
mentionableItems.forEach((mentionableitem, index) => {
let item = items[index];
let item_data = searchMentionableItem(item, siteSettings)[0];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { click, fillIn, visit } from "@ember/test-helpers";
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
import { cloneJSON } from "discourse-common/lib/object";
import {
acceptance,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import mentionableFixtures from "../fixtures/mentionable-fixtures";

acceptance("Composer", function (needs) {
needs.user({
id: 5,
username: "kris",
whisperer: true,
});
needs.settings({
general_category_id: 1,
default_composer_category: 1,
});
needs.site({
categories: [
{
id: 1,
name: "General",
slug: "general",
permission: 1,
topic_template: null,
},
],
});
needs.site(cloneJSON(mentionableFixtures["mentionable_items.json"]));
needs.hooks.afterEach(() => toggleCheckDraftPopup(false));

test("composer controls", async function (assert) {
await visit("/");
assert.ok(exists("#create-topic"), "the create button is visible");
await click("#create-topic");
assert.ok(exists(".d-editor-input"), "the composer input is visible");
assert.ok(exists(".d-editor-preview:visible"), "shows the preview");
await fillIn("#reply-title", "this is my new topic title");
assert.ok(
exists(".title-input .popup-tip.good.hide"),
"the title is now good"
);
await fillIn(
".d-editor-input",
"this is the *content* of a post with a mentionable item +the-stuff-of-dreams"
);
assert.strictEqual(
query(".d-editor-preview").innerHTML.trim(),
'<p>this is the <em>content</em> of a post with a mentionable item <a href="https://amazing.com/stuff-of-dreams-book" class="mentionable-item" target="_blank" tabindex="-1"><span>The Stuff of Dreams</span></a></p>',
"it previews content"
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
"mentionable_items.json": {
mentionable_items: [
{
affiliate_snippet_1: "",
affiliate_snippet_2: "",
affiliate_snippet_3: "",
created_at: "2021-11-03T17:35:14.474Z",
description: "The Stuff of Dreams book",
id: 1,
image_url: null,
name: "The Stuff of Dreams",
slug: "the-stuff-of-dreams",
updated_at: "2021-11-03T17:35:14.474Z",
url: "https://amazing.com/stuff-of-dreams-book",
},
],
},
};

0 comments on commit e24ddd8

Please sign in to comment.