1
0
Fork 0

modify tests to support current behaviour regarding plaintext description

This commit is contained in:
Rigel Kent 2021-04-12 11:43:29 +02:00 committed by Chocobozzz
parent 84bced652c
commit a073c91270
3 changed files with 28 additions and 18 deletions

View File

@ -19,8 +19,21 @@ const toSafeHtml = text => {
return sanitizeHtml(html, SANITIZE_OPTIONS)
}
const mdToPlainText = text => {
// Convert possible markdown (emojis, emphasis and lists) to html
const html = markdownIt.render(text)
// Convert to safe Html
const safeHtml = sanitizeHtml(html, SANITIZE_OPTIONS)
return safeHtml.replace(/<[^>]+>/g, '')
.replace(/\n$/, '')
.replace('\n', ', ')
}
// ---------------------------------------------------------------------------
export {
toSafeHtml
toSafeHtml,
mdToPlainText
}

View File

@ -24,7 +24,7 @@ import { VideoChannelModel } from '../models/video/video-channel'
import { getActivityStreamDuration } from '../models/video/video-format-utils'
import { VideoPlaylistModel } from '../models/video/video-playlist'
import { MAccountActor, MChannelActor } from '../types/models'
import { toSafeHtml } from '../helpers/markdown'
import { mdToPlainText } from '../helpers/markdown'
type Tags = {
ogType: string
@ -55,10 +55,6 @@ type Tags = {
}
}
const toPlainText = (content: string) => {
return toSafeHtml(content).replace(/<[^>]+>/g, '')
}
class ClientHtml {
private static htmlCache: { [path: string]: string } = {}
@ -99,13 +95,13 @@ class ClientHtml {
}
let customHtml = ClientHtml.addTitleTag(html, escapeHTML(video.name))
customHtml = ClientHtml.addDescriptionTag(customHtml, toPlainText(video.description))
customHtml = ClientHtml.addDescriptionTag(customHtml, mdToPlainText(video.description))
const url = WEBSERVER.URL + video.getWatchStaticPath()
const originUrl = video.url
const title = escapeHTML(video.name)
const siteName = escapeHTML(CONFIG.INSTANCE.NAME)
const description = toPlainText(video.description)
const description = mdToPlainText(video.description)
const image = {
url: WEBSERVER.URL + video.getPreviewStaticPath()
@ -157,13 +153,13 @@ class ClientHtml {
}
let customHtml = ClientHtml.addTitleTag(html, escapeHTML(videoPlaylist.name))
customHtml = ClientHtml.addDescriptionTag(customHtml, toPlainText(videoPlaylist.description))
customHtml = ClientHtml.addDescriptionTag(customHtml, mdToPlainText(videoPlaylist.description))
const url = videoPlaylist.getWatchUrl()
const originUrl = videoPlaylist.url
const title = escapeHTML(videoPlaylist.name)
const siteName = escapeHTML(CONFIG.INSTANCE.NAME)
const description = toPlainText(videoPlaylist.description)
const description = mdToPlainText(videoPlaylist.description)
const image = {
url: videoPlaylist.getThumbnailUrl()
@ -241,13 +237,13 @@ class ClientHtml {
}
let customHtml = ClientHtml.addTitleTag(html, escapeHTML(entity.getDisplayName()))
customHtml = ClientHtml.addDescriptionTag(customHtml, toPlainText(entity.description))
customHtml = ClientHtml.addDescriptionTag(customHtml, mdToPlainText(entity.description))
const url = entity.getLocalUrl()
const originUrl = entity.Actor.url
const siteName = escapeHTML(CONFIG.INSTANCE.NAME)
const title = escapeHTML(entity.getDisplayName())
const description = toPlainText(entity.description)
const description = mdToPlainText(entity.description)
const image = {
url: entity.Actor.getAvatarUrl(),
@ -383,7 +379,7 @@ class ClientHtml {
}
metaTags['og:url'] = tags.url
metaTags['og:description'] = tags.description
metaTags['og:description'] = mdToPlainText(tags.description)
if (tags.embed) {
metaTags['og:video:url'] = tags.embed.url
@ -399,7 +395,7 @@ class ClientHtml {
private static generateStandardMetaTags (tags: Tags) {
return {
name: tags.title,
description: tags.description,
description: mdToPlainText(tags.description),
image: tags.image.url
}
}

View File

@ -39,7 +39,8 @@ describe('Test a client controllers', function () {
let account: Account
const videoName = 'my super name for server 1'
const videoDescription = 'my super description for server 1'
const videoDescription = 'my<br> super __description__ for *server* 1<p></p>'
const videoDescriptionPlainText = 'my super description for server 1'
const playlistName = 'super playlist name'
const playlistDescription = 'super playlist description'
@ -169,7 +170,7 @@ describe('Test a client controllers', function () {
.expect(HttpStatusCode.OK_200)
expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
expect(res.text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`)
expect(res.text).to.contain('<meta property="og:type" content="video" />')
expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
})
@ -181,7 +182,7 @@ describe('Test a client controllers', function () {
.expect(HttpStatusCode.OK_200)
expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
expect(res.text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`)
expect(res.text).to.contain('<meta property="og:type" content="video" />')
expect(res.text).to.contain(`<meta property="og:url" content="${servers[0].url}/videos/watch/${servers[0].video.uuid}" />`)
})
@ -210,7 +211,7 @@ describe('Test a client controllers', function () {
expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
expect(res.text).to.contain(`<meta property="twitter:title" content="${videoName}" />`)
expect(res.text).to.contain(`<meta property="twitter:description" content="${videoDescription}" />`)
expect(res.text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`)
})
it('Should have valid twitter card on the watch playlist page', async function () {