Skip to content

Commit f8fdc60

Browse files
committed
chore: Fix video tests
1 parent b48d452 commit f8fdc60

File tree

3 files changed

+172
-113
lines changed

3 files changed

+172
-113
lines changed

src/transform/plugins/video/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function tokenizeVideo(md: MarkdownIt, options: VideoFullOptions): Renderer.Rend
7575
` class="embed-responsive-item ${service}-player"` +
7676
` type="text/html" width="${width}" height="${height}"` +
7777
` src="${options.url(service, videoID, options)}"` +
78-
`frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>`;
78+
` frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>`;
7979
};
8080
}
8181

test/__snapshots__/video.test.ts.snap

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`md-video-mfr make sure normal iframe generates properly when empty 1`] = `
4+
<p>
5+
</p>
6+
`;
7+
8+
exports[`md-video-mfr make sure normal iframe generates properly with guid 1`] = `
9+
<p>
10+
<div id="1.2"
11+
class="mfr mfr-file"
12+
>
13+
</div>
14+
<script>
15+
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
16+
</script>
17+
</p>
18+
`;
19+
20+
exports[`md-video-mfr make sure normal iframe generates properly with guid and extra space 1`] = `
21+
<p>
22+
<div id="1.2"
23+
class="mfr mfr-file"
24+
>
25+
</div>
26+
<script>
27+
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
28+
</script>
29+
</p>
30+
`;
31+
32+
exports[`md-video-mfr make sure normal iframe generates properly with guid and line break 1`] = `
33+
<p>
34+
<div id="1.2"
35+
class="mfr mfr-file"
36+
>
37+
</div>
38+
<script>
39+
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
40+
</script>
41+
</p>
42+
`;
43+
44+
exports[`md-video-mfr make sure normal iframe generates properly with guid and two extra spaces 1`] = `
45+
<p>
46+
<div id="1.2"
47+
class="mfr mfr-file"
48+
>
49+
</div>
50+
<script>
51+
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
52+
</script>
53+
</p>
54+
`;
55+
56+
exports[`md-video-mfr make sure normal iframe generates properly with link 1`] = `
57+
<p>
58+
<div id="1.2"
59+
class="mfr mfr-file"
60+
>
61+
</div>
62+
<script>
63+
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
64+
</script>
65+
</p>
66+
`;
67+
68+
exports[`md-video-mfr make sure normal iframe generates properly with link and extra space 1`] = `
69+
<p>
70+
<div id="1.2"
71+
class="mfr mfr-file"
72+
>
73+
</div>
74+
<script>
75+
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
76+
</script>
77+
</p>
78+
`;
79+
80+
exports[`md-video-mfr make sure normal iframe generates properly with link and two extra spaces 1`] = `
81+
<p>
82+
<div id="1.2"
83+
class="mfr mfr-file"
84+
>
85+
</div>
86+
<script>
87+
$(document).ready(function () {new mfr.Render("1.2", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); });
88+
</script>
89+
</p>
90+
`;
91+
92+
exports[`md-video-mfr make sure normal iframe generates properly with link to local 1`] = `
93+
<p>
94+
<div id="1.2"
95+
class="mfr mfr-file"
96+
>
97+
</div>
98+
<script>
99+
$(document).ready(function () {new mfr.Render("1.2", "https://localhost:7778/render?url=https://localhost:5000/xxxxx/?action=download%26mode=render"); });
100+
</script>
101+
</p>
102+
`;
103+
104+
exports[`md-video-mfr make sure normal iframe generates properly with link to local ip 1`] = `
105+
<p>
106+
<div id="1.2"
107+
class="mfr mfr-file"
108+
>
109+
</div>
110+
<script>
111+
$(document).ready(function () {new mfr.Render("1.2", "http://localhost:7778/render?mode=render&amp;url=http://192.168.168.167:5000/y98tn/?action=download%26mode=render%26direct"); });
112+
</script>
113+
</p>
114+
`;
115+
116+
exports[`md-video-mfr make sure normal iframe generates properly with link to staging 1`] = `
117+
<p>
118+
<div id="1.2"
119+
class="mfr mfr-file"
120+
>
121+
</div>
122+
<script>
123+
$(document).ready(function () {new mfr.Render("1.2", "https://mfr-staging3.osf.io/render?url=https://staging3.osf.io/xxxxx/?action=download%26mode=render"); });
124+
</script>
125+
</p>
126+
`;

test/video.test.ts

+45-112
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import MarkdownIt from 'markdown-it';
44
import video from '../src/transform/plugins/video/index';
55

66
const generate = require('markdown-it-testgen');
7-
const assert = require('assert');
87

9-
// eslint-disable-next-line no-implicit-globals
10-
function getMfrId(html: string) {
11-
return html.split('"')[1];
8+
function preserveId(html: string) {
9+
return html
10+
.replace(/<div id="\d+.\d+"/, '<div id="1.2"')
11+
.replace(/new mfr\.Render\("\d+.\d+"/, 'new mfr.Render("1.2"');
1212
}
1313

1414
describe('md-video', function () {
@@ -22,149 +22,82 @@ describe('md-video-mfr', function () {
2222
const md = new MarkdownIt({}).use(video);
2323

2424
it('make sure normal iframe generates properly when empty', function () {
25-
const renderedHtml = md.render('@[osf]()');
26-
assert.equal(renderedHtml, '<p></p>\n');
25+
const renderedHtml = preserveId(md.render('@[osf]()'));
26+
expect(renderedHtml).toMatchSnapshot();
2727
});
2828

2929
it('make sure normal iframe generates properly with guid', function () {
30-
const renderedHtml = md.render('@[osf](xxxxx)');
31-
const id = getMfrId(renderedHtml);
32-
assert.equal(
33-
renderedHtml,
34-
'<p><div id="' +
35-
id +
36-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
37-
id +
38-
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
39-
);
30+
const renderedHtml = preserveId(md.render('@[osf](xxxxx)'));
31+
expect(renderedHtml).toMatchSnapshot();
4032
});
4133

4234
it('make sure normal iframe generates properly with guid and line break', function () {
43-
const renderedHtml = md.render('@[osf](xxxxx\n)');
44-
const id = getMfrId(renderedHtml);
45-
assert.equal(
46-
renderedHtml,
47-
'<p><div id="' +
48-
id +
49-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
50-
id +
51-
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
52-
);
35+
const renderedHtml = preserveId(md.render('@[osf](xxxxx\n)'));
36+
expect(renderedHtml).toMatchSnapshot();
5337
});
5438

5539
it('make sure normal iframe generates properly with guid and extra space', function () {
56-
const renderedHtml = md.render('@[osf](xxxxx )');
57-
const id = getMfrId(renderedHtml);
58-
assert.equal(
59-
renderedHtml,
60-
'<p><div id="' +
61-
id +
62-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
63-
id +
64-
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
65-
);
40+
const renderedHtml = preserveId(md.render('@[osf](xxxxx )'));
41+
expect(renderedHtml).toMatchSnapshot();
6642
});
6743

6844
it('make sure normal iframe generates properly with guid and two extra spaces', function () {
69-
const renderedHtml = md.render('@[osf]( xxxxx )');
70-
const id = getMfrId(renderedHtml);
71-
assert.equal(
72-
renderedHtml,
73-
'<p><div id="' +
74-
id +
75-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
76-
id +
77-
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
78-
);
45+
const renderedHtml = preserveId(md.render('@[osf]( xxxxx )'));
46+
expect(renderedHtml).toMatchSnapshot();
7947
});
8048

8149
it('make sure normal iframe generates properly with link', function () {
82-
const renderedHtml = md.render(
83-
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render)',
84-
);
85-
const id = getMfrId(renderedHtml);
86-
assert.equal(
87-
renderedHtml,
88-
'<p><div id="' +
89-
id +
90-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
91-
id +
92-
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
50+
const renderedHtml = preserveId(
51+
md.render(
52+
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render)',
53+
),
9354
);
55+
expect(renderedHtml).toMatchSnapshot();
9456
});
9557

9658
it('make sure normal iframe generates properly with link and extra space', function () {
97-
const renderedHtml = md.render(
98-
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render )',
99-
);
100-
const id = getMfrId(renderedHtml);
101-
assert.equal(
102-
renderedHtml,
103-
'<p><div id="' +
104-
id +
105-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
106-
id +
107-
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
59+
const renderedHtml = preserveId(
60+
md.render(
61+
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render )',
62+
),
10863
);
64+
expect(renderedHtml).toMatchSnapshot();
10965
});
11066

11167
it('make sure normal iframe generates properly with link and two extra spaces', function () {
112-
const renderedHtml = md.render(
113-
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render )',
114-
);
115-
const id = getMfrId(renderedHtml);
116-
assert.equal(
117-
renderedHtml,
118-
'<p><div id="' +
119-
id +
120-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
121-
id +
122-
'", "https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
68+
const renderedHtml = preserveId(
69+
md.render(
70+
'@[osf](https://mfr.osf.io/render?url=https://osf.io/xxxxx/?action=download%26mode=render )',
71+
),
12372
);
73+
expect(renderedHtml).toMatchSnapshot();
12474
});
12575

12676
it('make sure normal iframe generates properly with link to staging', function () {
127-
const renderedHtml = md.render(
128-
'@[osf](https://mfr-staging3.osf.io/render?url=https://staging3.osf.io/xxxxx/?action=download%26mode=render)',
129-
);
130-
const id = getMfrId(renderedHtml);
131-
assert.equal(
132-
renderedHtml,
133-
'<p><div id="' +
134-
id +
135-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
136-
id +
137-
'", "https://mfr-staging3.osf.io/render?url=https://staging3.osf.io/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
77+
const renderedHtml = preserveId(
78+
md.render(
79+
'@[osf](https://mfr-staging3.osf.io/render?url=https://staging3.osf.io/xxxxx/?action=download%26mode=render)',
80+
),
13881
);
82+
expect(renderedHtml).toMatchSnapshot();
13983
});
14084

14185
it('make sure normal iframe generates properly with link to local', function () {
142-
const renderedHtml = md.render(
143-
'@[osf](https://localhost:7778/render?url=https://localhost:5000/xxxxx/?action=download%26mode=render)',
144-
);
145-
const id = getMfrId(renderedHtml);
146-
assert.equal(
147-
renderedHtml,
148-
'<p><div id="' +
149-
id +
150-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
151-
id +
152-
'", "https://localhost:7778/render?url=https://localhost:5000/xxxxx/?action=download%26mode=render"); }); </script></p>\n',
86+
const renderedHtml = preserveId(
87+
md.render(
88+
'@[osf](https://localhost:7778/render?url=https://localhost:5000/xxxxx/?action=download%26mode=render)',
89+
),
15390
);
91+
expect(renderedHtml).toMatchSnapshot();
15492
});
15593

15694
it('make sure normal iframe generates properly with link to local ip', function () {
157-
const renderedHtml = md.render(
158-
'@[osf](http://localhost:7778/render?mode=render&url=http://192.168.168.167:5000/y98tn/?action=download%26mode=render%26direct)',
159-
);
160-
const id = getMfrId(renderedHtml);
161-
assert.equal(
162-
renderedHtml,
163-
'<p><div id="' +
164-
id +
165-
'" class="mfr mfr-file"></div><script>$(document).ready(function () {new mfr.Render("' +
166-
id +
167-
'", "http://localhost:7778/render?mode=render&amp;url=http://192.168.168.167:5000/y98tn/?action=download%26mode=render%26direct"); }); </script></p>\n',
95+
const renderedHtml = preserveId(
96+
md.render(
97+
'@[osf](http://localhost:7778/render?mode=render&url=http://192.168.168.167:5000/y98tn/?action=download%26mode=render%26direct)',
98+
),
16899
);
100+
101+
expect(renderedHtml).toMatchSnapshot();
169102
});
170103
});

0 commit comments

Comments
 (0)