@@ -4,11 +4,11 @@ import MarkdownIt from 'markdown-it';
4
4
import video from '../src/transform/plugins/video/index' ;
5
5
6
6
const generate = require ( 'markdown-it-testgen' ) ;
7
- const assert = require ( 'assert' ) ;
8
7
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 ( / < d i v i d = " \d + .\d + " / , '<div id="1.2"' )
11
+ . replace ( / n e w m f r \. R e n d e r \( " \d + .\d + " / , 'new mfr.Render("1.2"' ) ;
12
12
}
13
13
14
14
describe ( 'md-video' , function ( ) {
@@ -22,149 +22,82 @@ describe('md-video-mfr', function () {
22
22
const md = new MarkdownIt ( { } ) . use ( video ) ;
23
23
24
24
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 ( ) ;
27
27
} ) ;
28
28
29
29
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 ( ) ;
40
32
} ) ;
41
33
42
34
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 ( ) ;
53
37
} ) ;
54
38
55
39
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 ( ) ;
66
42
} ) ;
67
43
68
44
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 ( ) ;
79
47
} ) ;
80
48
81
49
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
+ ) ,
93
54
) ;
55
+ expect ( renderedHtml ) . toMatchSnapshot ( ) ;
94
56
} ) ;
95
57
96
58
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
+ ) ,
108
63
) ;
64
+ expect ( renderedHtml ) . toMatchSnapshot ( ) ;
109
65
} ) ;
110
66
111
67
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
+ ) ,
123
72
) ;
73
+ expect ( renderedHtml ) . toMatchSnapshot ( ) ;
124
74
} ) ;
125
75
126
76
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
+ ) ,
138
81
) ;
82
+ expect ( renderedHtml ) . toMatchSnapshot ( ) ;
139
83
} ) ;
140
84
141
85
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
+ ) ,
153
90
) ;
91
+ expect ( renderedHtml ) . toMatchSnapshot ( ) ;
154
92
} ) ;
155
93
156
94
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&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
+ ) ,
168
99
) ;
100
+
101
+ expect ( renderedHtml ) . toMatchSnapshot ( ) ;
169
102
} ) ;
170
103
} ) ;
0 commit comments