@@ -11,10 +11,6 @@ describe('instantiation', function() {
1111} ) ;
1212
1313describe ( 'properties' , function ( ) {
14- after ( function ( done ) {
15- exec ( 'rm ' + __dirname + '/.xinitrc' , done ) ;
16- } ) ;
17-
1814 it ( 'should include all required format properties' , function ( ) {
1915 var format = WebsiteExtension . props . format ;
2016
@@ -37,29 +33,81 @@ describe('properties', function() {
3733 assert ( format . end_command ) ;
3834 assert ( typeof format . end_command === 'string' ) ;
3935 } ) ;
36+ } ) ;
4037
41- it ( 'start_command should update .xinitrc file with supplied token' , function ( done ) {
42- var format = WebsiteExtension . props . format ,
43- command ,
44- expected = 'exec /usr/bin/chromium --noerrdialogs --kiosk --incognito http://test.com' ;
38+ describe ( 'start_command' , function ( ) {
39+ var expectedDefault = 'exec /usr/bin/chromium --noerrdialogs --kiosk --incognito "http://test.com"' ;
4540
46- // use test .xinitrc
47- format . xinitrcTplPath = __dirname + '/.xinitrc.tpl' ;
48- format . xinitrcFinalPath = format . xinitrcTplPath . replace ( '.tpl' , '' ) ;
41+ after ( function ( done ) {
42+ exec ( 'rm ' + __dirname + '/.xinitrc' , done ) ;
43+ } ) ;
44+
45+ it ( 'should update .xinitrc file with supplied token' , function ( done ) {
46+ var format = getTestFormat ( ) ,
47+ command ;
4948
5049 // replace $url token with url string
5150 command = format . start_command ( { } , {
5251 $url : 'http://test.com'
5352 } ) ;
5453
5554 assert ( typeof command === 'string' ) ;
55+ checkXinitrc ( format . xinitrcFinalPath , expectedDefault , done ) ;
56+ } ) ;
57+ it ( 'should not accept undefined args parameter' , function ( done ) {
58+ var format = getTestFormat ( ) ,
59+ command ;
60+
61+ // replace $url token with url string
62+ command = format . start_command ( undefined , {
63+ $url : 'http://test.com'
64+ } ) ;
65+
66+ assert ( typeof command === 'string' ) ;
67+ checkXinitrc ( format . xinitrcFinalPath , expectedDefault , done ) ;
68+ } ) ;
69+ it ( 'should update .xinitrc with optional args' , function ( done ) {
70+ var format = getTestFormat ( ) ,
71+ command ,
72+ expected = 'exec /usr/bin/chromium --noerrdialogs --kiosk --incognito --allow-insecure-localhost "http://test.com"' ;
5673
57- fs . readFile ( format . xinitrcFinalPath , 'utf8' , function ( err , data ) {
74+ // replace $url token with url string
75+ command = format . start_command ( { flags :'--allow-insecure-localhost' } , {
76+ $url : 'http://test.com'
77+ } ) ;
78+
79+ assert ( typeof command === 'string' ) ;
80+ checkXinitrc ( format . xinitrcFinalPath , expected , done ) ;
81+ } ) ;
82+ it ( 'should ignore unsupported args' , function ( done ) {
83+ var format = getTestFormat ( ) ,
84+ command ;
85+
86+ // replace $url token with url string
87+ command = format . start_command ( { random :'args' } , {
88+ $url : 'http://test.com'
89+ } ) ;
90+
91+ assert ( typeof command === 'string' ) ;
92+ checkXinitrc ( format . xinitrcFinalPath , expectedDefault , done ) ;
93+ } ) ;
94+
95+ function checkXinitrc ( path , expected , done ) {
96+ fs . readFile ( path , 'utf8' , function ( err , data ) {
5897 if ( err ) {
5998 throw err ;
6099 }
61100 assert . equal ( data , expected ) ;
62101 done ( ) ;
63102 } ) ;
64- } ) ;
103+ }
104+ function getTestFormat ( ) {
105+ var format = WebsiteExtension . props . format ;
106+
107+ // set test .xinitrc.tpl
108+ format . xinitrcTplPath = __dirname + '/.xinitrc.tpl' ;
109+ format . xinitrcFinalPath = format . xinitrcTplPath . replace ( '.tpl' , '' ) ;
110+
111+ return format ;
112+ }
65113} ) ;
0 commit comments