Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: title when YouTube is pasted as the title to composer #12565

Merged
merged 1 commit into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -164,8 +164,12 @@ export default Component.extend({

const heading = frag.querySelector("h3, h4");

if (heading && heading.textContent) {
this.changeTitle(heading.textContent);
const title =
(heading && heading.textContent) ||
(frag.firstElementChild && frag.firstElementChild.title);

if (title) {
this.changeTitle(title);
} else {
const firstTitle =
(frag.firstChild &&
Expand Down
Expand Up @@ -52,6 +52,17 @@ acceptance("Composer topic featured links", function (needs) {
);
});

test("YouTube onebox with title", async function (assert) {
await visit("/");
await click("#create-topic");
await fillIn("#reply-title", "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
assert.equal(
queryAll(".title-input input").val(),
"Rick Astley - Never Gonna Give You Up (Video)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice choice.

"title is from the oneboxed article"
);
});

test("no onebox result", async function (assert) {
await visit("/");
await click("#create-topic");
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/discourse/tests/helpers/create-pretender.js
Expand Up @@ -850,6 +850,16 @@ export function applyDefaultHandlers(pretender) {
];
}

if (
request.queryParams.url === "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
) {
return [
200,
{ "Content-Type": "application/html" },
'<img src="https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg" width="480" height="360" title="Rick Astley - Never Gonna Give You Up (Video)">',
];
}

if (request.queryParams.url.indexOf("/internal-page.html") > -1) {
return [
200,
Expand Down