File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -138,13 +138,24 @@ cases(
138138) ;
139139
140140test ( 'Gets the correct YouTube iframe' , async ( ) => {
141- const html = await getHTML ( 'https://youtu.be/dQw4w9WgXcQ' ) ;
141+ const html = await getHTML ( 'https://youtu.be/dQw4w9WgXcQ' , { } ) ;
142142
143143 expect ( html ) . toMatchInlineSnapshot (
144144 `<iframe width="100%" height="315" src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?rel=0" frameBorder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>`
145145 ) ;
146146} ) ;
147147
148+ test ( 'Gets the correct YouTube iframe with custom dimensions' , async ( ) => {
149+ const html = await getHTML ( 'https://youtu.be/dQw4w9WgXcQ' , {
150+ width : '50%' ,
151+ height : '50%' ,
152+ } ) ;
153+
154+ expect ( html ) . toMatchInlineSnapshot (
155+ `"<iframe width=\\"50%\\" height=\\"50%\\" src=\\"https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?rel=0\\" frameBorder=\\"0\\" allow=\\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\\" allowFullScreen></iframe>"`
156+ ) ;
157+ } ) ;
158+
148159test ( 'Plugin can transform YouTube links' , async ( ) => {
149160 const markdownAST = getMarkdownASTForFile ( 'YouTube' ) ;
150161
Original file line number Diff line number Diff line change @@ -45,8 +45,8 @@ export const getYouTubeIFrameSrc = (urlString) => {
4545
4646 return embedUrl . toString ( ) ;
4747} ;
48- export const getHTML = ( url ) => {
48+ export const getHTML = ( url , { width = '100%' , height = '315' } ) => {
4949 const iframeSrc = getYouTubeIFrameSrc ( url ) ;
5050
51- return `<iframe width="100% " height="315 " src="${ iframeSrc } " frameBorder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>` ;
51+ return `<iframe width="${ width } " height="${ height } " src="${ iframeSrc } " frameBorder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>` ;
5252} ;
You can’t perform that action at this time.
0 commit comments