forked from juju/juju-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-charges.js
360 lines (344 loc) · 12.5 KB
/
test-charges.js
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*
This file is part of the Juju GUI, which lets users view and manage Juju
environments within a graphical interface (https://launchpad.net/juju-gui).
Copyright (C) 2017 Canonical Ltd.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License version 3, as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
General Public License for more details.
You should have received a copy of the GNU Affero General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
var juju = {components: {}}; // eslint-disable-line no-unused-vars
chai.config.includeStack = true;
chai.config.truncateThreshold = 0;
describe('AccountPaymentCharges', function() {
let acl;
beforeAll(function(done) {
// By loading this file it adds the component to the juju components.
YUI().use('account-payment-charges', function() { done(); });
});
beforeEach(() => {
acl = {isReadOnly: sinon.stub().returns(false)};
});
it('can display the loading spinner', function() {
const renderer = jsTestUtils.shallowRender(
<juju.components.AccountPaymentCharges
acl={acl}
addNotification={sinon.stub()}
getCharges={sinon.stub()}
getReceipt={sinon.stub()}
username="spinach" />, true);
const output = renderer.getRenderOutput();
const expected = (
<juju.components.Spinner />);
expect(output.props.children.props.children[1]).toEqualJSX(expected);
});
it('can display charges', function() {
const getCharges = sinon.stub().callsArgWith(1, null, [{
id: 'TEST-12344',
statementId: '12344',
price: 10000,
vat: 2000,
currency: 'USD',
for: '2016-01-02T15:04:05Z',
lineItems: [{
name: 'this is line 1',
details: 'a bit more details for line 1',
usage: 'something',
price: '48'
}]
}]);
const renderer = jsTestUtils.shallowRender(
<juju.components.AccountPaymentCharges
acl={acl}
addNotification={sinon.stub()}
getCharges={getCharges}
getReceipt={sinon.stub()}
username="spinach" />, true);
const output = renderer.getRenderOutput();
const expected = (
<div className="account-payment-charges">
<div className="account__section">
<h2 className="account__title twelve-col">
Charges
</h2>
<ul className="user-profile__list twelve-col">
<li className="user-profile__list-header twelve-col">
<div className="two-col no-margin-bottom">
ID
</div>
<div className="two-col no-margin-bottom">
Date
</div>
<div className="two-col no-margin-bottom">
Price
</div>
<div className="two-col no-margin-bottom">
VAT
</div>
<div className="two-col last-col no-margin-bottom">
Total
</div>
</li>
<juju.components.ExpandingRow
classes={{
'twelve-col': true,
'user-profile__list-row': true
}}
clickable={true}
key="TEST-12344">
<div>
<div className="two-col no-margin-bottom">
12344
</div>
<div className="two-col no-margin-bottom">
<juju.components.DateDisplay
date="2016-01-02T15:04:05Z"
relative={true} />
</div>
<div className="two-col no-margin-bottom">
{100} {'USD'}
</div>
<div className="two-col no-margin-bottom">
{20} {'USD'}
</div>
<div className="two-col last-col no-margin-bottom">
{120} {'USD'}
</div>
<div className="two-col last-col no-margin-bottom">
<juju.components.GenericButton
action={
output.props.children.props.children[1]
.props.children[1][0].props.children[0]
.props.children[5].props.children.props.action}
disabled={false}
type="inline-neutral"
title="Show receipt" />
</div>
</div>
<div className="twelve-col">
<div className="account-payment-charges__line-items">
<h4>Charges for:</h4>
<ul className="user-profile__list twelve-col">
<li className="user-profile__list-header twelve-col">
<div className="three-col no-margin-bottom">
Name
</div>
<div className="three-col no-margin-bottom">
Details
</div>
<div className="three-col no-margin-bottom">
Usage
</div>
<div className="three-col last-col no-margin-bottom">
Price
</div>
</li>
<li className="user-profile__list-row twelve-col"
key="this is line 10">
<div className="three-col no-margin-bottom">
this is line 1
</div>
<div className="three-col no-margin-bottom">
a bit more details for line 1
</div>
<div className="three-col no-margin-bottom">
something
</div>
<div className="three-col last-col no-margin-bottom">
48
</div>
</li>
</ul>
</div>
</div>
</juju.components.ExpandingRow>
</ul>
{null}
</div>
</div>);
expect(output).toEqualJSX(expected);
});
it('can display when there are no charges', function() {
const getCharges = sinon.stub().callsArgWith(1, null, []);
const renderer = jsTestUtils.shallowRender(
<juju.components.AccountPaymentCharges
acl={acl}
addNotification={sinon.stub()}
getCharges={getCharges}
getReceipt={sinon.stub()}
username="spinach" />, true);
const output = renderer.getRenderOutput();
const expected = (
<div className="account-payment-charges">
<div className="account__section">
<h2 className="account__title twelve-col">
Charges
</h2>
<div>
You do not have any charges.
</div>
{null}
</div>
</div>);
expect(output).toEqualJSX(expected);
});
it('can display when there are no line items', function() {
const getCharges = sinon.stub().callsArgWith(1, null, [{
id: 'TEST-12344',
statementId: '12344',
price: 10000,
vat: 2000,
currency: 'USD',
for: '2016-01-02T15:04:05Z',
lineItems: []
}]);
const renderer = jsTestUtils.shallowRender(
<juju.components.AccountPaymentCharges
acl={acl}
addNotification={sinon.stub()}
getCharges={getCharges}
getReceipt={sinon.stub()}
username="spinach" />, true);
const output = renderer.getRenderOutput();
const expected = (
<div className="account-payment-charges">
<div className="account__section">
<h2 className="account__title twelve-col">
Charges
</h2>
<ul className="user-profile__list twelve-col">
<li className="user-profile__list-header twelve-col">
<div className="two-col no-margin-bottom">
ID
</div>
<div className="two-col no-margin-bottom">
Date
</div>
<div className="two-col no-margin-bottom">
Price
</div>
<div className="two-col no-margin-bottom">
VAT
</div>
<div className="two-col last-col no-margin-bottom">
Total
</div>
</li>
<juju.components.ExpandingRow
classes={{
'twelve-col': true,
'user-profile__list-row': true
}}
clickable={true}
key="TEST-12344">
<div>
<div className="two-col no-margin-bottom">
12344
</div>
<div className="two-col no-margin-bottom">
<juju.components.DateDisplay
date="2016-01-02T15:04:05Z"
relative={true} />
</div>
<div className="two-col no-margin-bottom">
{100} {'USD'}
</div>
<div className="two-col no-margin-bottom">
{20} {'USD'}
</div>
<div className="two-col last-col no-margin-bottom">
{120} {'USD'}
</div>
<div className="two-col last-col no-margin-bottom">
<juju.components.GenericButton
action={
output.props.children.props.children[1]
.props.children[1][0].props.children[0]
.props.children[5].props.children.props.action}
disabled={false}
type="inline-neutral"
title="Show receipt" />
</div>
</div>
<div className="twelve-col">
<div className="account-payment-charges__line-items">
There are no items for this charge.
</div>
</div>
</juju.components.ExpandingRow>
</ul>
{null}
</div>
</div>);
expect(output).toEqualJSX(expected);
});
it('can handle errors when getting the charges', function() {
const addNotification = sinon.stub();
const getCharges = sinon.stub().callsArgWith(1, 'Uh oh!', null);
jsTestUtils.shallowRender(
<juju.components.AccountPaymentCharges
acl={acl}
addNotification={addNotification}
getCharges={getCharges}
getReceipt={sinon.stub()}
username="spinach" />);
assert.equal(addNotification.callCount, 1);
assert.deepEqual(addNotification.args[0][0], {
title: 'Could not load the list of charges',
message: 'Could not load the list of charges: Uh oh!',
level: 'error'
});
});
it('can display the popup', function() {
const getCharges = sinon.stub().callsArgWith(1, null, [{
id: 'TEST-12344',
statementId: '12344',
price: 10000,
vat: 2000,
currency: 'USD',
for: '2016-01-02T15:04:05Z',
lineItems: []
}]);
const addNotification = sinon.stub();
const getReceipt = sinon.stub();
const renderer = jsTestUtils.shallowRender(
<juju.components.AccountPaymentCharges
acl={acl}
addNotification={addNotification}
getCharges={getCharges}
getReceipt={getReceipt}
username="spinach" />, true);
const instance = renderer.getMountedInstance();
let output = renderer.getRenderOutput();
output.props.children.props.children[1]
.props.children[1][0].props.children[0]
.props.children[5].props.children.props.action();
output = renderer.getRenderOutput();
const expected = (
<juju.components.ReceiptPopup
addNotification={addNotification}
close={instance._togglePopup}
chargeId="TEST-12344"
getReceipt={getReceipt} />);
expect(output.props.children.props.children[2]).toEqualJSX(expected);
});
it('can abort requests when unmounting', function() {
const abort = sinon.stub();
const getCharges = sinon.stub().returns({abort: abort});
const renderer = jsTestUtils.shallowRender(
<juju.components.AccountPaymentCharges
acl={acl}
addNotification={sinon.stub()}
getCharges={getCharges}
getReceipt={sinon.stub()}
username="spinach" />, true);
renderer.unmount();
assert.equal(abort.callCount, 1);
});
});