Skip to content

Commit 9a87a71

Browse files
author
Jeff Harrell
committed
Cleaning up test cases
1 parent 49cd8b5 commit 9a87a71

2 files changed

Lines changed: 74 additions & 84 deletions

File tree

test/index.html

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<body>
99
<script src="../lib/MiniCart/minicart.js"></script>
1010

11-
<div id="buynowSmall">
11+
<div id="buynow-sm">
1212
<h2>Buy Now (Small)</h2>
1313
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
1414
data-button="buynow"
@@ -18,7 +18,7 @@ <h2>Buy Now (Small)</h2>
1818
></script>
1919
</div>
2020

21-
<div id="buynowLarge">
21+
<div id="buynow-lg">
2222
<h2>Buy Now (Large)</h2>
2323
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
2424
data-button="buynow"
@@ -27,7 +27,7 @@ <h2>Buy Now (Large)</h2>
2727
></script>
2828
</div>
2929

30-
<div id="buynowSpanish">
30+
<div id="buynow-es_ES">
3131
<h2>Buy Now (Spanish)</h2>
3232
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
3333
data-button="buynow"
@@ -37,7 +37,27 @@ <h2>Buy Now (Spanish)</h2>
3737
></script>
3838
</div>
3939

40-
<div id="buynowEditable">
40+
<div id="buynow-fr_FR">
41+
<h2>Buy Now (French)</h2>
42+
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
43+
data-button="buynow"
44+
data-name="Buy now!"
45+
data-amount="1.00"
46+
data-lang="fr_FR"
47+
></script>
48+
</div>
49+
50+
<div id="buynow-de_DE">
51+
<h2>Buy Now (German)</h2>
52+
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
53+
data-button="buynow"
54+
data-name="Buy now!"
55+
data-amount="1.00"
56+
data-lang="de_DE"
57+
></script>
58+
</div>
59+
60+
<div id="buynow-editable">
4161
<h2>Buy Now (Editable)</h2>
4262
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
4363
data-button="buynow"
@@ -48,7 +68,7 @@ <h2>Buy Now (Editable)</h2>
4868
></script>
4969
</div>
5070

51-
<div id="cartSmall">
71+
<div id="cart-sm">
5272
<h2>Cart (Small)</h2>
5373
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
5474
data-button="cart"
@@ -58,7 +78,7 @@ <h2>Cart (Small)</h2>
5878
></script>
5979
</div>
6080

61-
<div id="cartLarge">
81+
<div id="cart-lg">
6282
<h2>Cart (Large)</h2>
6383
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
6484
data-button="cart"
@@ -68,17 +88,7 @@ <h2>Cart (Large)</h2>
6888
></script>
6989
</div>
7090

71-
<div id="cartFrench">
72-
<h2>Cart (French)</h2>
73-
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
74-
data-button="cart"
75-
data-name="Add to cart!"
76-
data-amount="1.00"
77-
data-lang="fr_FR"
78-
></script>
79-
</div>
80-
81-
<div id="hostedSmall">
91+
<div id="hosted-sm">
8292
<h2>Hosted (Small)</h2>
8393
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
8494
data-button="cart"
@@ -87,23 +97,14 @@ <h2>Hosted (Small)</h2>
8797
></script>
8898
</div>
8999

90-
<div id="hostedLarge">
100+
<div id="hosted-lg">
91101
<h2>Hosted</h2>
92102
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
93103
data-button="cart"
94104
data-id="8R63A645E2QB6"
95105
></script>
96106
</div>
97107

98-
<div id="hostedGerman">
99-
<h2>Hosted (German)</h2>
100-
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
101-
data-button="cart"
102-
data-id="8R63A645E2QB6"
103-
data-lang="de_DE"
104-
></script>
105-
</div>
106-
107108
<div id="qr">
108109
<h2>QR Code</h2>
109110
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"

test/test.js

Lines changed: 46 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
var 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

1012
eval(fs.readFileSync('src/paypal-button.js').toString());
1113

14+
1215
// Test the object's integrity
1316
describe('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
3235
describe('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
4851
describe('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
7277
describe('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
9996
describe('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

Comments
 (0)