mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add note.test.ts
This commit is contained in:
parent
942260aa54
commit
c8f9483795
2 changed files with 29 additions and 1 deletions
28
src/utils/note.test.ts
Normal file
28
src/utils/note.test.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { assertEquals } from '@std/assert';
|
||||||
|
|
||||||
|
import { getMediaLinks, parseNoteContent } from '@/utils/note.ts';
|
||||||
|
|
||||||
|
Deno.test('parseNoteContent', () => {
|
||||||
|
const { html, links, firstUrl } = parseNoteContent('Hello, world!');
|
||||||
|
assertEquals(html, 'Hello, world!');
|
||||||
|
assertEquals(links, []);
|
||||||
|
assertEquals(firstUrl, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test('getMediaLinks', () => {
|
||||||
|
const links = [
|
||||||
|
{ href: 'https://example.com/image.png' },
|
||||||
|
{ href: 'https://example.com/index.html' },
|
||||||
|
{ href: 'https://example.com/yolo' },
|
||||||
|
{ href: 'https://example.com/' },
|
||||||
|
];
|
||||||
|
const mediaLinks = getMediaLinks(links);
|
||||||
|
assertEquals(mediaLinks, [
|
||||||
|
{
|
||||||
|
url: 'https://example.com/image.png',
|
||||||
|
data: {
|
||||||
|
mime: 'image/png',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
@ -58,7 +58,7 @@ function parseNoteContent(content: string): ParsedNoteContent {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMediaLinks(links: Link[]): DittoAttachment[] {
|
function getMediaLinks(links: Pick<Link, 'href'>[]): DittoAttachment[] {
|
||||||
return links.reduce<DittoAttachment[]>((acc, link) => {
|
return links.reduce<DittoAttachment[]>((acc, link) => {
|
||||||
const mediaType = getUrlMediaType(link.href);
|
const mediaType = getUrlMediaType(link.href);
|
||||||
if (!mediaType) return acc;
|
if (!mediaType) return acc;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue