44var fs = require ( 'fs' ) ,
55 should = require ( 'should' ) ,
66 jsdom = require ( 'jsdom' ) . jsdom ,
7- document = jsdom ( fs . readFileSync ( './test/index.html' ) . toString ( ) ) ,
7+ jsdomOptions = { features : { QuerySelector : true } } ,
8+ testFile = fs . readFileSync ( './test/index.html' ) . toString ( ) ,
9+ document = jsdom ( testFile , null , jsdomOptions ) ,
810 window = document . createWindow ( ) ;
911
1012eval ( fs . readFileSync ( 'src/paypal-button.js' ) . toString ( ) ) ;
1113
14+
1215// Test the object's integrity
1316describe ( 'PAYPAL.apps.ButtonFactory' , function ( ) {
14-
1517 'use strict' ;
1618
1719 it ( 'Should have a PAYPAL object' , function ( ) {
@@ -28,9 +30,9 @@ describe('PAYPAL.apps.ButtonFactory', function () {
2830
2931} ) ;
3032
33+
3134// Test the create method
3235describe ( 'PAYPAL.apps.ButtonFactory.create' , function ( ) {
33-
3436 'use strict' ;
3537
3638 it ( 'Should be a function' , function ( ) {
@@ -44,80 +46,67 @@ describe('PAYPAL.apps.ButtonFactory.create', function () {
4446 } ) ;
4547} ) ;
4648
49+
4750// Test the buttons counter object
4851describe ( 'PAYPAL.apps.ButtonFactory.buttons' , function ( ) {
49-
52+
5053 'use strict' ;
51-
54+
5255 var buttons = PAYPAL . apps . ButtonFactory . buttons ;
53-
56+
5457 it ( 'Should have four buy now buttons' , function ( ) {
55- buttons . buynow . should . equal ( 4 ) ;
58+ buttons . buynow . should . equal ( 6 ) ;
5659 } ) ;
57-
60+
5861 it ( 'Should have three cart buttons' , function ( ) {
59- buttons . cart . should . equal ( 3 ) ;
62+ buttons . cart . should . equal ( 2 ) ;
6063 } ) ;
61-
64+
6265 it ( 'Should have three hosted buttons' , function ( ) {
63- buttons . hosted . should . equal ( 3 ) ;
66+ buttons . hosted . should . equal ( 2 ) ;
6467 } ) ;
65-
68+
6669 it ( 'Should have one QR code' , function ( ) {
6770 buttons . qr . should . equal ( 1 ) ;
6871 } ) ;
6972} ) ;
7073
74+
75+
7176// Test multi-language support
7277describe ( 'Multi-language button images' , function ( ) {
73-
7478 'use strict' ;
75-
76- it ( 'Should have a spanish version of Buy Now button' , function ( ) {
77- var spanishButton = document . getElementById ( 'buynowSpanish' ) ,
78- spanishImage = spanishButton . getElementsByTagName ( 'input' ) [ 0 ] . src ;
79-
80- spanishImage . should . include ( 'es_ES' ) ;
81- } ) ;
82-
83- it ( 'Should have a french version of Cart button' , function ( ) {
84- var frenchButton = document . getElementById ( 'cartFrench' ) ,
85- frenchImage = frenchButton . getElementsByTagName ( 'input' ) [ 0 ] . src ;
86-
87- frenchImage . should . include ( 'fr_FR' ) ;
88- } ) ;
89-
90- it ( 'Should have a german version of Hosted button' , function ( ) {
91- var germanButton = document . getElementById ( 'hostedGerman' ) ,
92- germanImage = germanButton . getElementsByTagName ( 'input' ) [ 0 ] . src ;
93-
94- germanImage . should . include ( 'de_DE' ) ;
95- } ) ;
79+
80+ function testLanguage ( locale , type ) {
81+ it ( 'Should have a ' + locale + ' version of the ' + type + ' button' , function ( ) {
82+ var image = document . querySelector ( '#' + type + '-' + locale + ' input[type="image"]' ) ,
83+ imagePath = image && image . src ;
84+
85+ imagePath . should . include ( locale ) ;
86+ } ) ;
87+ }
88+
89+ testLanguage ( 'es_ES' , 'buynow' ) ;
90+ testLanguage ( 'fr_FR' , 'buynow' ) ;
91+ testLanguage ( 'de_DE' , 'buynow' ) ;
9692} ) ;
9793
94+
9895// Test multiple button image sizes
9996describe ( 'Multiple button image sizes' , function ( ) {
100-
10197 'use strict' ;
102-
103- it ( 'Should have a small version of Buy Now button' , function ( ) {
104- var buynowSmallButton = document . getElementById ( 'buynowSmall' ) ,
105- buynowSmallImg = buynowSmallButton . getElementsByTagName ( 'input' ) [ 0 ] . src ;
106-
107- buynowSmallImg . should . include ( 'SM' ) ;
108- } ) ;
109-
110- it ( 'Should have a small version of Cart button' , function ( ) {
111- var cartSmallButton = document . getElementById ( 'cartSmall' ) ,
112- cartSmallImg = cartSmallButton . getElementsByTagName ( 'input' ) [ 0 ] . src ;
113-
114- cartSmallImg . should . include ( 'SM' ) ;
115- } ) ;
116-
117- it ( 'Should have a small version of Hosted button' , function ( ) {
118- var hostedSmallButton = document . getElementById ( 'hostedSmall' ) ,
119- hostedSmallImg = hostedSmallButton . getElementsByTagName ( 'input' ) [ 0 ] . src ;
120-
121- hostedSmallImg . should . include ( 'SM' ) ;
122- } ) ;
123- } ) ;
98+
99+ function testSize ( size , type ) {
100+ it ( 'Should have a ' + size + ' version of ' + type + ' button' , function ( ) {
101+ var image = document . querySelector ( '#' + type + '-' + size + ' input[type="image"]' ) ,
102+ imagePath = image && image . src ;
103+
104+ imagePath . should . include ( 'SM' ) ;
105+ } ) ;
106+ }
107+
108+ testSize ( 'sm' , 'buynow' ) ;
109+ testSize ( 'sm' , 'cart' ) ;
110+ testSize ( 'sm' , 'hosted' ) ;
111+ } ) ;
112+
0 commit comments