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
237 lines (170 loc) · 6.17 KB
/
Copy pathtest.js
File metadata and controls
237 lines (170 loc) · 6.17 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*jshint node:true, evil:true */
/*global describe:true, it:true, paypal:true, document:true, window:true, before:true, beforeEach:true */
'use strict';
if (typeof window === 'undefined') {
var fs = require('fs'),
should = require('should'),
jsdom = require('jsdom').jsdom,
jsdomOptions = { features: { QuerySelector: true }},
testFile = fs.readFileSync('./test/functional/index.html').toString(),
document = jsdom(testFile, null, jsdomOptions),
window = document.createWindow();
eval(fs.readFileSync('dist/button.js').toString());
}
// Test the object's integrity
describe('JavaScript API', function () {
var namespace;
before(function () {
namespace = window.paypal;
});
it('Should have a paypal namespace', function () {
namespace.should.be.an.Object;
});
it('Should have a create method', function () {
namespace.button.create.should.be.a.Function;
});
it('Create return false if no parameters', function () {
var result = namespace.button.create();
result.should.equal(false);
});
});
// Test the buttons counter object
describe('Test page button counter', function () {
var buttons;
before(function () {
buttons = window.paypal.button.counter;
});
it('Should have seven buy now buttons', function () {
buttons.buynow.should.equal(15);
});
it('Should have two cart buttons', function () {
buttons.cart.should.equal(3);
});
it('Should have two donation buttons', function () {
buttons.donate.should.equal(3);
});
it('Should have two subscribe buttons', function () {
buttons.subscribe.should.equal(3);
});
});
// Test environments
describe('Environments', function () {
var sandbox, www;
before(function () {
sandbox = document.querySelector('#sandbox form');
www = document.querySelector('#buynow-sm form');
});
it('Should be a sandbox button', function () {
sandbox.action.should.include('//www.sandbox.paypal');
});
it('Should be a www button', function () {
www.action.should.include('//www.paypal');
});
});
// Test different forms
describe('Form factors', function () {
it('Should produce a valid form', function () {
document.querySelectorAll('#buynow-sm form').length.should.equal(1);
});
it('Should produce a single button', function () {
document.querySelectorAll('#button form').length.should.equal(0);
document.querySelectorAll('#button button').length.should.equal(1);
});
it('Should produce a valid QR code', function () {
document.querySelector('#qr img').src.should.include('//www.paypal.com');
});
});
// Test editable fields
describe('Editable buttons', function () {
var inputs;
before(function () {
inputs = document.querySelectorAll('#buynow-editable input[type=text]');
});
it('Should have three inputs', function () {
inputs.length.should.equal(3);
});
it('Should have a CSS class on the input', function () {
inputs[0].className.should.include('paypal-input');
});
it('Should have a CSS class on the label', function () {
inputs[0].parentNode.className.should.include('paypal-label');
});
it('Should have proper labels', function () {
var labels = document.querySelectorAll('#buynow-editable label');
labels[0].textContent.replace(/^\s+/, '').replace(/\s+$/, '').should.equal('Item');
labels[1].textContent.replace(/^\s+/, '').replace(/\s+$/, '').should.equal('Amount');
labels[2].textContent.replace(/^\s+/, '').replace(/\s+$/, '').should.equal('Quantity');
});
it('Should have a CSS class on the container', function () {
inputs[0].parentNode.parentNode.className.should.include('paypal-group');
});
});
// Test multi-language support
describe('Multi-language button images', function () {
function testLanguage(locale, type, expected) {
it('Should have a ' + locale + ' version of the ' + type + ' button', function () {
var button = document.querySelector('#' + type + '-' + locale + ' button[type=submit] .paypal-button-content'),
buttonText = button && button.textContent;
buttonText.should.equal(expected);
});
}
testLanguage('es_ES', 'buynow', 'Comprar con ');
testLanguage('de_DE', 'buynow', 'Kaufen mit ');
testLanguage('ja_JP', 'buynow', 'で購入手続きに進む');
});
// Test multiple button image sizes
describe('Multiple button image sizes', function () {
function testSize(size, type, expected) {
it('Should have a ' + size + ' version of ' + type + ' button', function () {
var button = document.querySelector('#' + type + '-' + size + ' button[type=submit]'),
buttonClass = button && button.className;
buttonClass.should.include(expected);
});
}
testSize('sm', 'buynow', 'small');
testSize('md', 'buynow', 'medium');
testSize('lg', 'buynow', 'large');
testSize('sm', 'buynow-secondary', 'small');
testSize('md', 'buynow-secondary', 'medium');
testSize('lg', 'buynow-secondary', 'large');
testSize('sm', 'cart', 'small');
testSize('md', 'cart', 'medium');
testSize('lg', 'cart', 'large');
testSize('sm', 'donate', 'small');
testSize('md', 'donate', 'medium');
testSize('lg', 'donate', 'large');
testSize('sm', 'subscribe', 'small');
testSize('md', 'subscribe', 'medium');
testSize('lg', 'subscribe', 'large');
});
// Test button styles
describe('Styled buttons', function () {
var primary, secondary;
before(function () {
primary = document.querySelectorAll('.paypal-style-primary');
secondary = document.querySelectorAll('.paypal-style-secondary');
});
it('Should have primary buttons', function () {
primary.length.should.equal(20);
});
it('Should have secondary buttons', function () {
secondary.length.should.equal(3);
});
});
describe('Options buttons', function () {
var form = document.getElementById('button-options');
var selects = form.getElementsByTagName('select');
it('Should have two selects', function () {
selects.length.should.equal(2);
});
it('Should have the right number of options per select', function () {
selects[0].options.length.should.equal(3);
selects[1].options.length.should.equal(5);
});
it('Should have the right values per options', function () {
selects[0].options[0].textContent.should.equal('Blue 8.00');
selects[0].options[0].value.should.equal('Blue');
selects[1].options[0].textContent.should.equal('Tiny');
selects[1].options[0].value.should.equal('Tiny');
});
});