Skip to content

Commit acfed89

Browse files
authored
test(APIC-722): test request panel body (#737)
* test(APIC-722): test request panel body * test: waitUntil added to fix tests * test: waitUntil added to fix tests
1 parent d3cb70f commit acfed89

File tree

4 files changed

+54
-18
lines changed

4 files changed

+54
-18
lines changed

demo/models/test-api/test-api.raml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,12 @@ securitySchemes:
231231
get:
232232
queryString:
233233
type: string
234+
/songs:
235+
post:
236+
body:
237+
application/json:
238+
example: |
239+
{
240+
"songId": "550e8400-e29b-41d4-a716-446655440000",
241+
"songTitle": "Get Lucky",
242+
}

test/api-console-documentation.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ describe('API Console documentation', () => {
233233
testCollapsibleSection(headers, 'Headers');
234234
};
235235

236-
const testSecurityResponses = (elem, expectedTabs, selectedTabContent) => {
236+
const testSecurityResponses = async (elem, expectedTabs, selectedTabContent) => {
237+
await waitUntil(() => Boolean(documentationSecurity(elem)));
237238
const item = documentationSecurity(elem);
238239
const securityShadowRoot = item.shadowRoot;
239240
const responses = securityShadowRoot.querySelector('.response-documentation');
@@ -277,8 +278,8 @@ describe('API Console documentation', () => {
277278
await testTypeDocumentExample(collapse, 'special-token');
278279
});
279280

280-
it('should render responses', () => {
281-
testSecurityResponses(element, ['401', '403'], 'Bad token.');
281+
it('should render responses', async () => {
282+
await testSecurityResponses(element, ['401', '403'], 'Bad token.');
282283
});
283284
});
284285

@@ -388,8 +389,8 @@ describe('API Console documentation', () => {
388389
]);
389390
});
390391

391-
it('should render responses', () => {
392-
testSecurityResponses(element, ['401', '403'], 'Bad or expired token. This can happen if the user or Dropbox\nrevoked or expired an access token. To fix, re-authenticate\nthe user.');
392+
it('should render responses', async () => {
393+
await testSecurityResponses(element, ['401', '403'], 'Bad or expired token. This can happen if the user or Dropbox\nrevoked or expired an access token. To fix, re-authenticate\nthe user.');
393394
});
394395
});
395396
});

test/api-console-navigation.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,15 @@ describe('API Console navigation', () => {
501501
it('should list all endpoints', () => {
502502
const endpointsList = navigationEndpointsList(element);
503503
assert.ok(endpointsList);
504-
assert.lengthOf(endpointsList, 8);
504+
assert.lengthOf(endpointsList, 9);
505505

506506
[
507507
['/test-custom-scheme', 'Custom security scheme'],
508508
['/test-headers', 'Headers V2'],
509509
['/test-oauth20-scheme', 'Oauth 2.0 security scheme'],
510510
['/test-oauth10-scheme', 'Oauth 1.0 security scheme'],
511511
['/test-pass-through-scheme', 'Digest pass through scheme'],
512+
['/songs', '/songs'],
512513
['/test-query-parameters', 'Query parameters'],
513514
['/test-basic-scheme', 'Basic security scheme'],
514515
['/test-digest-scheme', 'Digest security scheme'],

test/api-console-request.test.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,44 @@ describe('API Console request', () => {
118118
});
119119

120120
describe('Body', () => {
121-
beforeEach(async () => {
122-
await navigationSelectEndpointMethod(element, '/test-headers', 'post');
123-
// @ts-ignore
124-
(await documentationTryItButton(element)).click();
125-
await aTimeout(50);
126-
});
121+
describe('Sections', () => {
122+
beforeEach(async () => {
123+
await navigationSelectEndpointMethod(element, '/test-headers', 'post');
124+
// @ts-ignore
125+
(await documentationTryItButton(element)).click();
126+
await aTimeout(50);
127+
});
127128

128-
it('should render body section', () => {
129-
assert.exists(requestBodySection(element));
129+
it('should render body section', () => {
130+
assert.exists(requestBodySection(element));
131+
});
132+
133+
it('should render raw editor', () => {
134+
const body = requestBodySection(element);
135+
assert.exists(body.shadowRoot.querySelector('raw-payload-editor'));
136+
});
130137
});
131138

132-
it('should render raw editor', () => {
133-
const body = requestBodySection(element);
134-
assert.exists(body.shadowRoot.querySelector('raw-payload-editor'));
139+
describe('Request', () => {
140+
beforeEach(async () => {
141+
await navigationSelectEndpointMethod(element, '/songs', 'post');
142+
// @ts-ignore
143+
(await documentationTryItButton(element)).click();
144+
await aTimeout(50);
145+
146+
spy = sinon.spy();
147+
document.body.addEventListener('api-request', spy);
148+
});
149+
150+
it('should add body to request', async () => {
151+
// @ts-ignore
152+
requestSendButton(element).click();
153+
await nextFrame();
154+
155+
const body = '{\n "songId": "550e8400-e29b-41d4-a716-446655440000",\n "songTitle": "Get Lucky"\n}';
156+
assert.isTrue(spy.called);
157+
assert.equal(spy.getCall(0).args[0].detail.payload, body);
158+
});
135159
});
136160
});
137161

@@ -236,7 +260,8 @@ describe('API Console request', () => {
236260
assert.exists(credentialsSection);
237261
});
238262

239-
it('should render auth label', () => {
263+
it('should render auth label', async () => {
264+
await waitUntil(() => Boolean(credentialsSection.shadowRoot.querySelector('.auth-selector-label')));
240265
assert.equal(credentialsSection.shadowRoot.querySelector('.auth-selector-label').innerText, 'OAuth 1.0');
241266
});
242267

0 commit comments

Comments
 (0)