diff --git a/app/assets/javascripts/discourse/app/components/composer-title.js b/app/assets/javascripts/discourse/app/components/composer-title.js index da1a6cd90d5..04979bfda26 100644 --- a/app/assets/javascripts/discourse/app/components/composer-title.js +++ b/app/assets/javascripts/discourse/app/components/composer-title.js @@ -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 && diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-topic-links-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-topic-links-test.js index d633ae5c108..02307c26985 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/composer-topic-links-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/composer-topic-links-test.js @@ -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)", + "title is from the oneboxed article" + ); + }); + test("no onebox result", async function (assert) { await visit("/"); await click("#create-topic"); diff --git a/app/assets/javascripts/discourse/tests/helpers/create-pretender.js b/app/assets/javascripts/discourse/tests/helpers/create-pretender.js index aa627d6eed2..a59a911ec80 100644 --- a/app/assets/javascripts/discourse/tests/helpers/create-pretender.js +++ b/app/assets/javascripts/discourse/tests/helpers/create-pretender.js @@ -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" }, + '', + ]; + } + if (request.queryParams.url.indexOf("/internal-page.html") > -1) { return [ 200,