|
| 1 | +import { setLogLevel } from "../log"; |
| 2 | +import { NotionBlock } from "../types"; |
| 3 | +import { standardVideoTransformer } from "./VideoTransformer"; |
| 4 | +import { blocksToMarkdown } from "./pluginTestRun"; |
| 5 | + |
| 6 | +test("youtube embedded", async () => { |
| 7 | + const config = { plugins: [standardVideoTransformer] }; |
| 8 | + const result = await blocksToMarkdown(config, [ |
| 9 | + { |
| 10 | + object: "block", |
| 11 | + type: "video", |
| 12 | + video: { |
| 13 | + caption: [ |
| 14 | + { |
| 15 | + type: "text", |
| 16 | + text: { |
| 17 | + content: "A video about editing in Notion", |
| 18 | + link: null, |
| 19 | + }, |
| 20 | + plain_text: "A video about editing in Notion", |
| 21 | + href: null, |
| 22 | + }, |
| 23 | + ], |
| 24 | + type: "external", |
| 25 | + external: { url: "https://www.youtube.com/watch?v=FXIrojSK3Jo" }, |
| 26 | + }, |
| 27 | + } as unknown as NotionBlock, |
| 28 | + ]); |
| 29 | + expect(result).toContain(`import ReactPlayer from "react-player";`); |
| 30 | + expect(result).toContain( |
| 31 | + `<ReactPlayer controls url="https://www.youtube.com/watch?v=FXIrojSK3Jo" />` |
| 32 | + ); |
| 33 | +}); |
| 34 | + |
| 35 | +test("vimeo embedded", async () => { |
| 36 | + setLogLevel("verbose"); |
| 37 | + const config = { plugins: [standardVideoTransformer] }; |
| 38 | + const result = await blocksToMarkdown(config, [ |
| 39 | + { |
| 40 | + object: "block", |
| 41 | + type: "video", |
| 42 | + video: { |
| 43 | + caption: [], |
| 44 | + type: "external", |
| 45 | + external: { url: "https://vimeo.com/4613611xx" }, |
| 46 | + }, |
| 47 | + } as unknown as NotionBlock, |
| 48 | + ]); |
| 49 | + expect(result).toContain(`import ReactPlayer from "react-player";`); |
| 50 | + expect(result).toContain( |
| 51 | + `<ReactPlayer controls url="https://vimeo.com/4613611xx" />` |
| 52 | + ); |
| 53 | +}); |
| 54 | + |
| 55 | +test("video link, not embedded", async () => { |
| 56 | + setLogLevel("verbose"); |
| 57 | + const config = { plugins: [standardVideoTransformer] }; |
| 58 | + const result = await blocksToMarkdown(config, [ |
| 59 | + { |
| 60 | + object: "block", |
| 61 | + type: "paragraph", |
| 62 | + paragraph: { |
| 63 | + rich_text: [ |
| 64 | + { |
| 65 | + type: "text", |
| 66 | + text: { |
| 67 | + content: "https://vimeo.com/4613611xx", |
| 68 | + link: { |
| 69 | + url: "https://vimeo.com/4613611xx", |
| 70 | + }, |
| 71 | + }, |
| 72 | + annotations: { |
| 73 | + code: false, |
| 74 | + }, |
| 75 | + plain_text: "https://vimeo.com/4613611xx", |
| 76 | + href: "https://vimeo.com/4613611xx", |
| 77 | + }, |
| 78 | + ], |
| 79 | + color: "default", |
| 80 | + }, |
| 81 | + } as unknown as NotionBlock, |
| 82 | + ]); |
| 83 | + expect(result).toContain( |
| 84 | + "[https://vimeo.com/4613611xx](https://vimeo.com/4613611xx)" |
| 85 | + ); |
| 86 | + expect(result).not.toContain(`import`); |
| 87 | +}); |
0 commit comments