Skip to content

Commit 7d667e8

Browse files
committed
test: add tests for expandableImages
1 parent 399f54a commit 7d667e8

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/expandableImages.test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const test = require("tape")
2+
const { markdownToHtml } = require("./utils")
3+
const expandableImages = require("../src/expandableImages")
4+
5+
test("plain images are not converted to span with data attributes", (t) => {
6+
t.plan(1)
7+
const markdown = "![plain image](https://example.com/image.png)"
8+
const expected = '<p><img src="https://example.com/image.png" alt="plain image"></p>'
9+
10+
const rendered = markdownToHtml(markdown, expandableImages)
11+
t.equal(rendered, expected)
12+
})
13+
14+
test("expandable images are converted to span with data attributes", (t) => {
15+
t.plan(1)
16+
const markdown = "Check out this cool ![expandable](https://example.com/image.png) dog!"
17+
const expected =
18+
'<p>Check out this cool <span data-url="https://example.com/image.png" data-alt="" class="expandable-image"></span> dog!</p>'
19+
20+
const rendered = markdownToHtml(markdown, expandableImages)
21+
t.equal(rendered, expected)
22+
})
23+
24+
test("expandable image with alt text are converted to span with data attributes", (t) => {
25+
t.plan(1)
26+
const markdown =
27+
"Check out this cool ![image of a dog expandable](https://example.com/image.png) dog!"
28+
const expected =
29+
'<p>Check out this cool <span data-url="https://example.com/image.png" data-alt="image of a dog" class="expandable-image">image of a dog</span> dog!</p>'
30+
31+
const rendered = markdownToHtml(markdown, expandableImages)
32+
t.equal(rendered, expected)
33+
})
34+
35+
test("'expandable' anywhere but the end of the alt text does not make it expandable", (t) => {
36+
t.plan(1)
37+
const markdown = "![expandable image](https://example.com/image.png)"
38+
const expected =
39+
'<p><img src="https://example.com/image.png" alt="expandable image"></p>'
40+
41+
const rendered = markdownToHtml(markdown, expandableImages)
42+
t.equal(rendered, expected)
43+
})
44+
45+
test("'expandable' flag at the end of the alt text handles 'expandable' elsewhere in the alt text", (t) => {
46+
t.plan(1)
47+
const markdown =
48+
"Check out this cool ![expandable image of a dog expandable](https://example.com/image.png) dog!"
49+
const expected =
50+
'<p>Check out this cool <span data-url="https://example.com/image.png" data-alt="expandable image of a dog" class="expandable-image">expandable image of a dog</span> dog!</p>'
51+
52+
const rendered = markdownToHtml(markdown, expandableImages)
53+
t.equal(rendered, expected)
54+
})

0 commit comments

Comments
 (0)