Skip to content

Commit 47efa95

Browse files
committed
Updating tests
1 parent e4896c8 commit 47efa95

File tree

8 files changed

+247
-21
lines changed

8 files changed

+247
-21
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
.imdone
55
node_modules
66
bower_components
7-
build
8-
dist
7+
coverage

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ language: node_js
22
node_js: 8
33
sudo: required
44
before_script:
5-
- npm install -g polymer-cli
6-
- polymer install --variants
5+
- npm install -g polymer-cli istanbul wct-istanbub
6+
- polymer install
77
addons:
88
firefox: latest
99
apt:

api-console.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,12 @@ <h1 class="method-title">[[methodName]]</h1>
724724
xhr.addEventListener('error', (error) => this._apiLoadErrorHandler(error));
725725
xhr.addEventListener('loadend', () => this._apiLoadEndHandler(xhr));
726726
xhr.open('GET', url, true);
727-
try {
728-
xhr.send();
729-
} catch (e) {
730-
this._apiLoadErrorHandler(e);
731-
}
727+
xhr.send();
732728
}
733-
729+
/**
730+
* Called by `_modelLocationChanged` when model data are read from remote location.
731+
* @param {XMLHttpRequest} xhr
732+
*/
734733
_apiLoadEndHandler(xhr) {
735734
let data;
736735
try {
@@ -870,7 +869,7 @@ <h1 class="method-title">[[methodName]]</h1>
870869
*/
871870
_noExtBannerChanged(value) {
872871
if (value && this.extensionBannerActive) {
873-
this.extensionBannerActive = false;
872+
this._setExtensionBannerActive(false);
874873
}
875874
}
876875
/**

test/amf-computations-test.html

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
77
<script src="../../web-component-tester/browser.js"></script>
88
<link rel="import" href="../../raml-aware/raml-aware.html">
9+
<link rel="import" href="../../arc-polyfills/arc-polyfills.html">
910
<link rel="import" href="../api-console.html">
1011
<script src="amf-loader.js"></script>
1112
</head>
@@ -33,17 +34,58 @@
3334
});
3435
});
3536

36-
setup(() => {
37-
element = fixture('Basic');
38-
element.amfModel = amf;
39-
});
37+
suite('Basics', () => {
38+
setup(() => {
39+
element = fixture('Basic');
40+
element.amfModel = amf;
41+
});
42+
43+
test('webApi is computed', function() {
44+
assert.typeOf(element.webApi, 'object');
45+
});
4046

41-
test('webApi is computed', function() {
42-
assert.typeOf(element.webApi, 'object');
47+
test('apiTitle is computed', function() {
48+
assert.typeOf(element.apiTitle, 'string');
49+
});
4350
});
4451

45-
test('apiTitle is computed', function() {
46-
assert.typeOf(element.apiTitle, 'string');
52+
suite('_computeMethodName', () => {
53+
let webApi;
54+
let id;
55+
setup(() => {
56+
element = fixture('Basic');
57+
element.amfModel = amf;
58+
webApi = element._computeWebApi(amf);
59+
const endpoint = element._computeEndpointByPath(webApi, '/people');
60+
const opKey = element._getAmfKey(element.ns.w3.hydra.supportedOperation);
61+
const op = endpoint[opKey][0];
62+
id = op['@id'];
63+
});
64+
65+
test('Returns undefined when no isMethod', () => {
66+
const result = element._computeMethodName(false, id, webApi);
67+
assert.isUndefined(result);
68+
});
69+
70+
test('Returns undefined when no selected', () => {
71+
const result = element._computeMethodName(true, undefined, webApi);
72+
assert.isUndefined(result);
73+
});
74+
75+
test('Returns undefined when no webApi', () => {
76+
const result = element._computeMethodName(true, id);
77+
assert.isUndefined(result);
78+
});
79+
80+
test('Returns undefined when unknown selection', () => {
81+
const result = element._computeMethodName(true, 'non-existing', webApi);
82+
assert.isUndefined(result);
83+
});
84+
85+
test('Returns method name', () => {
86+
const result = element._computeMethodName(true, id, webApi);
87+
assert.equal(result, 'List people');
88+
});
4789
});
4890
});
4991
});

test/attribution-test.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
77
<script src="../../web-component-tester/browser.js"></script>
88
<script src="../../iron-test-helpers/test-helpers.js"></script>
9+
<link rel="import" href="../../arc-polyfills/arc-polyfills.html">
910
<link rel="import" href="../api-console.html">
1011
</head>
1112
<body>

test/basic-test.html

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<script src="../../web-component-tester/browser.js"></script>
88
<script src="../../iron-test-helpers/test-helpers.js"></script>
99
<script src="../../iron-test-helpers/mock-interactions.js"></script>
10+
<link rel="import" href="../../arc-polyfills/arc-polyfills.html">
1011
<link rel="import" href="../api-console.html">
1112
</head>
1213

@@ -269,6 +270,169 @@
269270
element._notifyApicExtension();
270271
});
271272
});
273+
274+
suite('_modelLocationChanged()', () => {
275+
let element;
276+
let xhr;
277+
let requests;
278+
setup(() => {
279+
requests = [];
280+
element = fixture('Basic');
281+
});
282+
283+
suiteSetup(() => {
284+
xhr = sinon.useFakeXMLHttpRequest();
285+
xhr.onCreate = function(xhr) {
286+
requests.push(xhr);
287+
};
288+
});
289+
290+
suiteTeardown(() => {
291+
xhr.restore();
292+
});
293+
294+
test('Do nothing when no argument', () => {
295+
element._modelLocationChanged();
296+
assert.equal(requests.length, 0);
297+
});
298+
299+
test('Downloads model from remote location', () => {
300+
element._modelLocationChanged('apip.json');
301+
assert.equal(requests.length, 1);
302+
requests[0].respond(200, {
303+
'Content-Type': 'application/json'},
304+
'[{"@context":{}, "@id": "","@type": []}]');
305+
assert.typeOf(element.amfModel, 'array');
306+
});
307+
308+
test('Calls _apiLoadErrorHandler() when url is invalid', () => {
309+
const callback = sinon.spy(element, '_apiLoadErrorHandler');
310+
element._modelLocationChanged('error.json');
311+
requests[0].respond(404, {
312+
'Content-Type': 'text/plain'},
313+
'nothing');
314+
assert.isTrue(callback.called);
315+
});
316+
});
317+
318+
suite('_apiLoadEndHandler()', () => {
319+
let element;
320+
setup(() => {
321+
element = fixture('Basic');
322+
});
323+
324+
test('Sets amfModel property', () => {
325+
element._apiLoadEndHandler({
326+
response: '[{"@context":{}, "@id": "","@type": []}]'
327+
});
328+
assert.typeOf(element.amfModel, 'array');
329+
});
330+
331+
test('Calles _apiLoadErrorHandler when response is not valid', () => {
332+
const callback = sinon.spy(element, '_apiLoadErrorHandler');
333+
element._apiLoadEndHandler({
334+
response: '[{"@context":'
335+
});
336+
assert.isTrue(callback.called);
337+
});
338+
});
339+
340+
suite('_apiLoadErrorHandler()', () => {
341+
let element;
342+
setup(() => {
343+
element = fixture('Basic');
344+
});
345+
346+
test('Sets message on the toast', () => {
347+
element._apiLoadErrorHandler(new Error('test'));
348+
assert.typeOf(element.$.apiLoadErrorToast.text, 'string');
349+
});
350+
351+
test('The toast is opened', () => {
352+
element._apiLoadErrorHandler(new Error('test'));
353+
assert.isTrue(element.$.apiLoadErrorToast.opened);
354+
});
355+
});
356+
357+
suite('resetLayout()', () => {
358+
let element;
359+
setup((done) => {
360+
element = fixture('Basic');
361+
flush(() => done());
362+
});
363+
364+
test('Resets layout', () => {
365+
element.resetLayout();
366+
// no error is thrown
367+
});
368+
});
369+
370+
suite('_noExtBannerChanged()', () => {
371+
let element;
372+
setup(() => {
373+
element = fixture('Basic');
374+
element._setExtensionBannerActive(true);
375+
});
376+
377+
test('Sets extensionBannerActive to false', () => {
378+
element._noExtBannerChanged(true);
379+
assert.isFalse(element.extensionBannerActive);
380+
});
381+
382+
test('Does nothing if argument is false', () => {
383+
element._noExtBannerChanged(false);
384+
assert.isTrue(element.extensionBannerActive);
385+
});
386+
});
387+
388+
suite('_computeRenderInlineTryIt()', () => {
389+
let element;
390+
setup(() => {
391+
element = fixture('Basic');
392+
});
393+
394+
test('Return false whem no "wideLayout"', () => {
395+
const result = element._computeRenderInlineTryIt(false);
396+
assert.isFalse(result);
397+
});
398+
399+
test('Return false whem no "isMethod"', () => {
400+
const result = element._computeRenderInlineTryIt(true, true, false);
401+
assert.isFalse(result);
402+
});
403+
404+
test('Return false whem no "app"', () => {
405+
const result = element._computeRenderInlineTryIt(true, false, true);
406+
assert.isFalse(result);
407+
});
408+
409+
test('Return false whem "inlineMethods"', () => {
410+
const result = element._computeRenderInlineTryIt(true, true, true, true);
411+
assert.isFalse(result);
412+
});
413+
414+
test('Return true to inline methods', () => {
415+
const result = element._computeRenderInlineTryIt(true, true, true, false);
416+
assert.isTrue(result);
417+
});
418+
});
419+
420+
suite('_computeNoTryItValue()', () => {
421+
let element;
422+
setup(() => {
423+
element = fixture('Basic');
424+
});
425+
426+
test('Returns true when renderInlineTyit', () => {
427+
const result = element._computeNoTryItValue(false, true);
428+
assert.isTrue(result);
429+
});
430+
431+
test('Returns value io noTryIt', () => {
432+
const result = element._computeNoTryItValue(false);
433+
assert.isFalse(result);
434+
});
435+
});
272436
</script>
273437
</body>
274438

test/raml-aware-test.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
66
<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
77
<script src="../../web-component-tester/browser.js"></script>
8+
<link rel="import" href="../../arc-polyfills/arc-polyfills.html">
89
<link rel="import" href="../../raml-aware/raml-aware.html">
910
<link rel="import" href="../api-console.html">
1011
<script src="amf-loader.js"></script>

wct.conf.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"version": ""
1414
}, {
1515
"browserName": "internet explorer",
16-
"platform": "Windows 8.1",
17-
"version": "11.0"
16+
"platform": "Windows 10",
17+
"version": "11.285"
1818
}, {
1919
"browserName": "firefox",
2020
"platform": "Windows 10",
@@ -44,6 +44,26 @@
4444
"platform": "macOS 10.13",
4545
"version": "11.1"
4646
}]
47+
},
48+
"istanbub": {
49+
"dir": "./coverage",
50+
"reporters": ["text-summary", "lcov"],
51+
"include": [
52+
"**/*.html"
53+
],
54+
"exclude": [
55+
"**/test/**",
56+
"**/demo/**",
57+
"**/tasks/**"
58+
],
59+
"thresholds": {
60+
"global": {
61+
"statements": 80,
62+
"branches": 80,
63+
"functions": 90,
64+
"lines": 80
65+
}
66+
}
4767
}
4868
}
4969
}

0 commit comments

Comments
 (0)