forked from jbillimoria/JavaScriptButtons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
112 lines (79 loc) · 2.68 KB
/
Copy pathtest.js
File metadata and controls
112 lines (79 loc) · 2.68 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*jshint node:true, evil:true */
/*global describe:true, it:true, PAYPAL:true, document:true, window:true */
var fs = require('fs'),
should = require('should'),
jsdom = require('jsdom').jsdom,
jsdomOptions = { features: { QuerySelector: true }},
testFile = fs.readFileSync('./test/index.html').toString(),
document = jsdom(testFile, null, jsdomOptions),
window = document.createWindow();
eval(fs.readFileSync('src/paypal-button.js').toString());
// Test the object's integrity
describe('PAYPAL.apps.ButtonFactory', function () {
'use strict';
it('Should have a PAYPAL object', function () {
PAYPAL.should.be.a('object');
});
it('Should have a PAYPAL.apps object', function () {
PAYPAL.apps.should.be.a('object');
});
it('Should have a PAYPAL.apps.ButtonFactory object', function () {
PAYPAL.apps.ButtonFactory.should.be.a('object');
});
});
// Test the create method
describe('PAYPAL.apps.ButtonFactory.create', function () {
'use strict';
it('Should be a function', function () {
PAYPAL.apps.ButtonFactory.create.should.be.a('function');
});
it('Should return false if no parameters', function () {
var result = PAYPAL.apps.ButtonFactory.create();
result.should.equal(false);
});
});
// Test the buttons counter object
describe('PAYPAL.apps.ButtonFactory.buttons', function () {
'use strict';
var buttons = PAYPAL.apps.ButtonFactory.buttons;
it('Should have four buy now buttons', function () {
buttons.buynow.should.equal(6);
});
it('Should have three cart buttons', function () {
buttons.cart.should.equal(2);
});
it('Should have three hosted buttons', function () {
buttons.hosted.should.equal(2);
});
it('Should have one QR code', function () {
buttons.qr.should.equal(1);
});
});
// Test multi-language support
describe('Multi-language button images', function () {
'use strict';
function testLanguage(locale, type) {
it('Should have a ' + locale + ' version of the ' + type + ' button', function () {
var image = document.querySelector('#' + type + '-' + locale + ' input[type="image"]'),
imagePath = image && image.src;
imagePath.should.include(locale);
});
}
testLanguage('es_ES', 'buynow');
testLanguage('fr_FR', 'buynow');
testLanguage('de_DE', 'buynow');
});
// Test multiple button image sizes
describe('Multiple button image sizes', function () {
'use strict';
function testSize(size, type) {
it('Should have a ' + size + ' version of ' + type + ' button', function () {
var image = document.querySelector('#' + type + '-' + size + ' input[type="image"]'),
imagePath = image && image.src;
imagePath.should.include('SM');
});
}
testSize('sm', 'buynow');
testSize('sm', 'cart');
testSize('sm', 'hosted');
});