|
| 1 | +import { NotionBlock } from "../config/configuration"; |
| 2 | +import { setLogLevel } from "../log"; |
| 3 | +import { blocksToMarkdown } from "../TestRun"; |
| 4 | +import { |
| 5 | + gifEmbed, |
| 6 | + imgurGifEmbed, |
| 7 | + vimeoEmbed, |
| 8 | + youtubeEmbed, |
| 9 | +} from "./StandardEmbeddings"; |
| 10 | + |
| 11 | +test("youtube", async () => { |
| 12 | + const config = { plugins: [youtubeEmbed] }; |
| 13 | + const result = await blocksToMarkdown(config, [ |
| 14 | + { |
| 15 | + object: "block", |
| 16 | + id: "e6ddd1d4-36d4-4925-94c1-5dff4662c1f3", |
| 17 | + has_children: false, |
| 18 | + archived: false, |
| 19 | + type: "video", |
| 20 | + video: { |
| 21 | + caption: [ |
| 22 | + { |
| 23 | + type: "text", |
| 24 | + text: { |
| 25 | + content: "A video about editing in Notion", |
| 26 | + link: null, |
| 27 | + }, |
| 28 | + plain_text: "A video about editing in Notion", |
| 29 | + href: null, |
| 30 | + }, |
| 31 | + ], |
| 32 | + type: "external", |
| 33 | + external: { url: "https://www.youtube.com/watch?v=FXIrojSK3Jo" }, |
| 34 | + }, |
| 35 | + } as unknown as NotionBlock, |
| 36 | + ]); |
| 37 | + expect(result).toContain(`import ReactPlayer from "react-player";`); |
| 38 | + expect(result).toContain( |
| 39 | + `<ReactPlayer controls url="https://www.youtube.com/watch?v=FXIrojSK3Jo" />` |
| 40 | + ); |
| 41 | +}); |
| 42 | + |
| 43 | +test("vimeo", async () => { |
| 44 | + setLogLevel("verbose"); |
| 45 | + const config = { plugins: [vimeoEmbed] }; |
| 46 | + const result = await blocksToMarkdown(config, [ |
| 47 | + { |
| 48 | + object: "block", |
| 49 | + id: "39ff83a3-2fb5-4411-a715-960656a177ff", |
| 50 | + type: "video", |
| 51 | + video: { |
| 52 | + caption: [], |
| 53 | + type: "external", |
| 54 | + external: { url: "https://vimeo.com/4613611xx" }, |
| 55 | + }, |
| 56 | + } as unknown as NotionBlock, |
| 57 | + ]); |
| 58 | + expect(result).toContain(`import ReactPlayer from "react-player";`); |
| 59 | + expect(result).toContain( |
| 60 | + `<ReactPlayer controls url="https://vimeo.com/4613611xx" />` |
| 61 | + ); |
| 62 | +}); |
| 63 | + |
| 64 | +test("imgur", async () => { |
| 65 | + setLogLevel("verbose"); |
| 66 | + const config = { plugins: [imgurGifEmbed] }; |
| 67 | + const result = await blocksToMarkdown(config, [ |
| 68 | + { |
| 69 | + object: "block", |
| 70 | + id: "e36710d8-98ad-40dc-b41b-b376ebdd6894", |
| 71 | + type: "bookmark", |
| 72 | + bookmark: { caption: [], url: "https://imgur.com/gallery/U8TTNuI" }, |
| 73 | + } as unknown as NotionBlock, |
| 74 | + ]); |
| 75 | + expect(result.trim()).toBe(``); |
| 76 | +}); |
| 77 | + |
| 78 | +test("gif", async () => { |
| 79 | + setLogLevel("verbose"); |
| 80 | + const config = { plugins: [gifEmbed] }; |
| 81 | + const result = await blocksToMarkdown(config, [ |
| 82 | + { |
| 83 | + object: "block", |
| 84 | + id: "e36710d8-98ad-40dc-b41b-b376ebdd6894", |
| 85 | + type: "bookmark", |
| 86 | + bookmark: { |
| 87 | + caption: [], |
| 88 | + url: "https://en.wikipedia.org/wiki/GIF#/media/File:Rotating_earth_(large).gif", |
| 89 | + }, |
| 90 | + } as unknown as NotionBlock, |
| 91 | + ]); |
| 92 | + expect(result.trim()).toBe( |
| 93 | + `.gif)` |
| 94 | + ); |
| 95 | +}); |
0 commit comments