Skip to content

Commit 294ae4b

Browse files
committed
New: Added detailed tests to the arc-console-request
1 parent 91cc4b0 commit 294ae4b

File tree

3 files changed

+230
-1
lines changed

3 files changed

+230
-1
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"undef": true,
1515
"unused": true,
1616
"newcap": false,
17+
"mocha": true,
1718
"globals": {
1819
"Polymer": true,
1920
"ArcBehaviors": true,

test/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
'basic-test.html',
2525
'basic-test.html?dom=shadow',
2626
'raml-aware-test.html',
27-
'raml-aware-test.html?dom=shadow'
27+
'raml-aware-test.html?dom=shadow',
28+
'request-test.html',
29+
'request-test.html?dom=shadow'
2830
]);
2931
</script>
3032
</body>

test/request-test.html

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
5+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8+
Code distributed by Google as part of the polymer project is also
9+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10+
-->
11+
<html>
12+
13+
<head>
14+
<meta charset="utf-8">
15+
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
16+
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
17+
<script src="../../web-component-tester/browser.js"></script>
18+
<script src="../../iron-test-helpers/test-helpers.js"></script>
19+
<script src="../../iron-test-helpers/mock-interactions.js"></script>
20+
<link rel="import" href="../../raml-js-parser/raml-js-parser.html">
21+
<link rel="import" href="../../raml-json-enhance/raml-json-enhance.html">
22+
<link rel="import" href="../api-console-request.html">
23+
</head>
24+
25+
<body>
26+
<test-fixture id="parser">
27+
<template>
28+
<raml-js-parser json></raml-js-parser>
29+
</template>
30+
</test-fixture>
31+
<test-fixture id="enhancer">
32+
<template>
33+
<raml-json-enhance></raml-json-enhance>
34+
</template>
35+
</test-fixture>
36+
<test-fixture id="basic">
37+
<template>
38+
<api-console-request></api-console-request>
39+
</template>
40+
</test-fixture>
41+
<test-fixture id="banner">
42+
<template>
43+
<api-console-request></api-console-request>
44+
</template>
45+
</test-fixture>
46+
<test-fixture id="redirect">
47+
<template>
48+
<api-console-request bower-location="test/"></api-console-request>
49+
</template>
50+
</test-fixture>
51+
<test-fixture id="proxy">
52+
<template>
53+
<api-console-request proxy="https://domain.com/"></api-console-request>
54+
</template>
55+
</test-fixture>
56+
<script>
57+
/* global fixture, assert, TestHelpers */
58+
suite('basic', function() {
59+
var element;
60+
61+
setup(function() {
62+
element = fixture('basic');
63+
});
64+
65+
test('responseIsXhr is true by default', function() {
66+
assert.isTrue(element.responseIsXhr);
67+
});
68+
69+
test('hasResponse is undefined', function() {
70+
assert.isUndefined(element.hasResponse);
71+
});
72+
73+
test('redirectUrl has default value', function() {
74+
assert.typeOf(element.redirectUrl, 'string');
75+
});
76+
});
77+
78+
suite('Response handling', function() {
79+
var element;
80+
var response = new Response('test', {
81+
statusCode: 200,
82+
headers: {
83+
'content-type': 'x-test'
84+
}
85+
});
86+
87+
setup(function() {
88+
element = fixture('basic');
89+
element.response = response;
90+
TestHelpers.forceXIfStamp(element);
91+
});
92+
93+
test('Computes hasResponse', function() {
94+
assert.isTrue(element.hasResponse);
95+
});
96+
97+
test('The response-view is rendered', function() {
98+
var elm = Polymer.dom(element.root).querySelector('response-view');
99+
assert.ok(elm);
100+
});
101+
102+
test('Handles api-console-response-ready custom event', function(done) {
103+
TestHelpers.fireEvent('api-console-response-ready', {}, document);
104+
setTimeout(function() {
105+
// There's nothing to test here.
106+
// If console.error wasn't present until now then it's alright
107+
done();
108+
}, 5);
109+
});
110+
});
111+
112+
suite('Extension banner', function() {
113+
var element;
114+
115+
setup(function() {
116+
element = fixture('banner');
117+
});
118+
119+
function isChrome() {
120+
return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
121+
}
122+
123+
test('Should display extension banner', TestHelpers.skipUnless(isChrome, function(done) {
124+
this.timeout(2000);
125+
setTimeout(function() {
126+
var elm = Polymer.dom(element.root).querySelector('.extension-banner');
127+
assert.isTrue(elm.classList.contains('active'));
128+
done();
129+
}, 1001);
130+
}));
131+
132+
test('Should hide extension banner', TestHelpers.skipUnless(isChrome, function(done) {
133+
this.timeout(2000);
134+
element.noExtensionBanner = true;
135+
setTimeout(function() {
136+
var elm = Polymer.dom(element.root).querySelector('.extension-banner');
137+
assert.isFalse(elm.classList.contains('active'));
138+
done();
139+
}, 1001);
140+
}));
141+
});
142+
suite('redirect url', function() {
143+
var element;
144+
145+
setup(function() {
146+
element = fixture('redirect');
147+
});
148+
149+
test('Should use bowerLocation property', function() {
150+
assert.isAbove(element.redirectUrl.indexOf('test/oauth-authorization/oauth-popup.html'), 0);
151+
});
152+
153+
test('Should change redirect URL with bower location', function() {
154+
element.bowerLocation = 'other';
155+
assert.isAbove(element.redirectUrl.indexOf('other/oauth-authorization/oauth-popup.html'), 0);
156+
});
157+
});
158+
159+
suite('Proxy settings', function() {
160+
var element;
161+
var event;
162+
163+
setup(function() {
164+
element = fixture('proxy');
165+
event = new CustomEvent('event', {
166+
bubbles: true,
167+
cancelable: true,
168+
detail: {
169+
url: 'http://test.domain.com/?param=value'
170+
}
171+
});
172+
});
173+
174+
test('Sets proxy to the request URL (event)', function() {
175+
element._appendProxy(event);
176+
assert.equal(event.detail.url, 'https://domain.com/http://test.domain.com/?param=value');
177+
});
178+
179+
test('Encodes URL for proxy', function() {
180+
element.proxyEncodeUrl = true;
181+
element._appendProxy(event);
182+
assert.equal(event.detail.url, 'https://domain.com/http%3A%2F%2Ftest.domain.com%2F%3Fparam%3Dvalue');
183+
});
184+
});
185+
186+
suite('Default headers', function() {
187+
var element;
188+
var event;
189+
190+
setup(function() {
191+
element = fixture('basic');
192+
element.appendHeaders = [{
193+
name: 'x-test',
194+
value: 'x-value'
195+
}];
196+
event = new CustomEvent('event', {
197+
bubbles: true,
198+
cancelable: true,
199+
detail: {
200+
url: 'http://test.domain.com/?param=value',
201+
headers: ''
202+
}
203+
});
204+
});
205+
206+
test('Appends default headers to empty list', function() {
207+
element._appendConsoleHeaders(event);
208+
assert.equal(event.detail.headers, 'x-test: x-value');
209+
});
210+
211+
test('Appends default headers to not empty list', function() {
212+
event.detail.headers = 'Content-Type: test';
213+
element._appendConsoleHeaders(event);
214+
assert.equal(event.detail.headers, 'Content-Type: test\nx-test: x-value');
215+
});
216+
217+
test('Replaces headers to default ones', function() {
218+
event.detail.headers = 'x-test: error';
219+
element._appendConsoleHeaders(event);
220+
assert.equal(event.detail.headers, 'x-test: x-value');
221+
});
222+
});
223+
</script>
224+
</body>
225+
226+
</html>

0 commit comments

Comments
 (0)