File size: 2,737 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import generateEmbedFrameMarkup from '../';

describe( '#generateEmbedFrameMarkup()', () => {
	test( 'should return an empty string if no arguments passed', () => {
		expect( generateEmbedFrameMarkup() ).toEqual( '' );
	} );

	test( 'should generate markup with the body contents', () => {
		expect( generateEmbedFrameMarkup( { body: 'Hello World' } ) ).toEqual(
			'<html><head><style>a { cursor: default; }</style></head><body style="margin:0"><div>Hello World</div><script src="https://s0.wp.com/wp-includes/js/jquery/jquery.js"></script><script>\n\t\t\t\t\t[ \'click\', \'dragstart\' ].forEach( function( type ) {\n\t\t\t\t\t\tdocument.addEventListener( type, function( event ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tevent.stopImmediatePropagation();\n\t\t\t\t\t\t}, true );\n\t\t\t\t\t} );\n\t\t\t\t</script></body></html>'
		);
	} );

	test( 'should generate markup with styles', () => {
		const styles = {
			'jetpack-carousel': {
				src: 'https://s1.wp.com/wp-content/mu-plugins/carousel/jetpack-carousel.css?m=1458924076h&ver=20120629',
				media: 'all',
			},
		};

		expect( generateEmbedFrameMarkup( { styles } ) ).toEqual(
			'<html><head><link rel="stylesheet" media="all" href="https://s1.wp.com/wp-content/mu-plugins/carousel/jetpack-carousel.css?m=1458924076h&amp;ver=20120629"/><style>a { cursor: default; }</style></head><body style="margin:0"><div></div><script src="https://s0.wp.com/wp-includes/js/jquery/jquery.js"></script><script>\n\t\t\t\t\t[ \'click\', \'dragstart\' ].forEach( function( type ) {\n\t\t\t\t\t\tdocument.addEventListener( type, function( event ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tevent.stopImmediatePropagation();\n\t\t\t\t\t\t}, true );\n\t\t\t\t\t} );\n\t\t\t\t</script></body></html>'
		);
	} );

	test( 'should generate markup with scripts', () => {
		const scripts = {
			'jetpack-facebook-embed': {
				src: 'https://s2.wp.com/wp-content/mu-plugins/shortcodes/js/facebook.js?ver',
				extra: 'var jpfbembed = {"appid":"249643311490"};',
			},
		};

		expect( generateEmbedFrameMarkup( { scripts } ) ).toEqual(
			'<html><head><style>a { cursor: default; }</style></head><body style="margin:0"><div></div><script src="https://s0.wp.com/wp-includes/js/jquery/jquery.js"></script><script>\n\t\t\t\t\t[ \'click\', \'dragstart\' ].forEach( function( type ) {\n\t\t\t\t\t\tdocument.addEventListener( type, function( event ) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tevent.stopImmediatePropagation();\n\t\t\t\t\t\t}, true );\n\t\t\t\t\t} );\n\t\t\t\t</script><script>var jpfbembed = {"appid":"249643311490"};</script><script src="https://s2.wp.com/wp-content/mu-plugins/shortcodes/js/facebook.js?ver"></script></body></html>'
		);
	} );
} );