at main 5.0 kB view raw
1import { expect, test } from "vitest"; 2import { parseBlocks } from "../lib/utils"; 3 4test("should correctly parse an h1 block to an h2 tag", () => { 5 const html = parseBlocks({ 6 block: { 7 $type: "pub.leaflet.pages.linearDocument#block", 8 block: { 9 $type: "pub.leaflet.blocks.header", 10 level: 1, 11 facets: [], 12 plaintext: "heading 1", 13 }, 14 }, 15 did: "did:plc:qttsv4e7pu2jl3ilanfgc3zn", 16 }); 17 18 expect(html).toMatchInlineSnapshot(`"<h2>heading 1</h2>"`); 19}); 20 21test("should correctly parse an h2 block to an h3 tag", () => { 22 const html = parseBlocks({ 23 block: { 24 $type: "pub.leaflet.pages.linearDocument#block", 25 block: { 26 $type: "pub.leaflet.blocks.header", 27 level: 2, 28 facets: [], 29 plaintext: "heading 2", 30 }, 31 }, 32 did: "did:plc:qttsv4e7pu2jl3ilanfgc3zn", 33 }); 34 35 expect(html).toMatchInlineSnapshot(`"<h3>heading 2</h3>"`); 36}); 37 38test("should correctly parse an h3 block to an h4 tag", () => { 39 const html = parseBlocks({ 40 block: { 41 $type: "pub.leaflet.pages.linearDocument#block", 42 block: { 43 $type: "pub.leaflet.blocks.header", 44 level: 3, 45 facets: [], 46 plaintext: "heading 3", 47 }, 48 }, 49 did: "did:plc:qttsv4e7pu2jl3ilanfgc3zn", 50 }); 51 52 expect(html).toMatchInlineSnapshot(`"<h4>heading 3</h4>"`); 53}); 54 55test("should correctly parse a block with no level to an h6 tag", () => { 56 const html = parseBlocks({ 57 block: { 58 $type: "pub.leaflet.pages.linearDocument#block", 59 block: { 60 $type: "pub.leaflet.blocks.header", 61 facets: [], 62 plaintext: "heading 6", 63 }, 64 }, 65 did: "did:plc:qttsv4e7pu2jl3ilanfgc3zn", 66 }); 67 68 expect(html).toMatchInlineSnapshot(`"<h6>heading 6</h6>"`); 69}); 70 71test("should correctly parse an unordered list block", () => { 72 const html = parseBlocks({ 73 block: { 74 $type: "pub.leaflet.pages.linearDocument#block", 75 block: { 76 $type: "pub.leaflet.blocks.unorderedList", 77 children: [ 78 { 79 $type: "pub.leaflet.blocks.unorderedList#listItem", 80 content: { 81 $type: "pub.leaflet.blocks.text", 82 facets: [ 83 { 84 index: { 85 byteEnd: 18, 86 byteStart: 0, 87 }, 88 features: [ 89 { 90 uri: "https://pdsls.dev/", 91 $type: "pub.leaflet.richtext.facet#link", 92 }, 93 ], 94 }, 95 { 96 index: { 97 byteEnd: 28, 98 byteStart: 22, 99 }, 100 features: [ 101 { 102 uri: "https://bsky.app/profile/juli.ee", 103 $type: "pub.leaflet.richtext.facet#link", 104 }, 105 ], 106 }, 107 ], 108 plaintext: "https://pdsls.dev/ by Juliet", 109 }, 110 children: [], 111 }, 112 { 113 $type: "pub.leaflet.blocks.unorderedList#listItem", 114 content: { 115 $type: "pub.leaflet.blocks.text", 116 facets: [ 117 { 118 index: { 119 byteEnd: 34, 120 byteStart: 0, 121 }, 122 features: [ 123 { 124 uri: "https://github.com/mary-ext/atcute", 125 $type: "pub.leaflet.richtext.facet#link", 126 }, 127 ], 128 }, 129 { 130 index: { 131 byteEnd: 42, 132 byteStart: 38, 133 }, 134 features: [ 135 { 136 uri: "https://bsky.app/profile/mary.my.id", 137 $type: "pub.leaflet.richtext.facet#link", 138 }, 139 ], 140 }, 141 ], 142 plaintext: "https://github.com/mary-ext/atcute by mary", 143 }, 144 children: [], 145 }, 146 { 147 $type: "pub.leaflet.blocks.unorderedList#listItem", 148 content: { 149 $type: "pub.leaflet.blocks.text", 150 facets: [ 151 { 152 index: { 153 byteEnd: 27, 154 byteStart: 0, 155 }, 156 features: [ 157 { 158 uri: "https://www.microcosm.blue/", 159 $type: "pub.leaflet.richtext.facet#link", 160 }, 161 ], 162 }, 163 { 164 index: { 165 byteEnd: 35, 166 byteStart: 31, 167 }, 168 features: [ 169 { 170 uri: "https://bsky.app/profile/bad-example.com", 171 $type: "pub.leaflet.richtext.facet#link", 172 }, 173 ], 174 }, 175 ], 176 plaintext: "https://www.microcosm.blue/ by phil", 177 }, 178 children: [], 179 }, 180 ], 181 }, 182 }, 183 did: "did:plc:qttsv4e7pu2jl3ilanfgc3zn", 184 }); 185 186 expect(html).toMatchInlineSnapshot( 187 `"<ul><li><p><a href="https://pdsls.dev/" target="_blank" rel="noopener noreferrer">https://pdsls.dev/</a> by <a href="https://bsky.app/profile/juli.ee" target="_blank" rel="noopener noreferrer">Juliet</a></p></li><li><p><a href="https://github.com/mary-ext/atcute" target="_blank" rel="noopener noreferrer">https://github.com/mary-ext/atcute</a> by <a href="https://bsky.app/profile/mary.my.id" target="_blank" rel="noopener noreferrer">mary</a></p></li><li><p><a href="https://www.microcosm.blue/" target="_blank" rel="noopener noreferrer">https://www.microcosm.blue/</a> by <a href="https://bsky.app/profile/bad-example.com" target="_blank" rel="noopener noreferrer">phil</a></p></li></ul>"`, 188 ); 189});