Skip to content

Commit 22f84f7

Browse files
authored
test(APIC-723): add test for Async APIs (#733)
* test(APIC-723): add test for Async APIs * test: add waitUntil to fix test * test: add waitUntil to fix test * test: add waitUntil to fix test
1 parent 3d0c4a5 commit 22f84f7

File tree

3 files changed

+160
-4
lines changed

3 files changed

+160
-4
lines changed

test/api-console-documentation.test.js

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { fixture, assert, html, aTimeout, waitUntil, nextFrame } from '@open-wc/
22
import { AmfLoader, ApiDescribe } from './amf-loader.js';
33
import '../api-console.js';
44
import {
5-
documentationDocument, documentationEndpoint, documentationMethod,
5+
documentationDocument,
6+
documentationEndpoint,
7+
documentationMethod,
68
documentationPanel,
79
documentationSecurity,
810
documentationSummary,
911
documentationType,
1012
navigationSelectDocumentation,
11-
navigationSelectDocumentationSection, navigationSelectEndpointMethod,
13+
navigationSelectDocumentationSection,
14+
navigationSelectEndpointMethod,
1215
navigationSelectEndpointOverview,
1316
navigationSelectSecurity,
1417
navigationSelectSecuritySection,
@@ -132,6 +135,7 @@ describe('API Console documentation', () => {
132135
});
133136

134137
it('should render basic summary documentation', async () => {
138+
await waitUntil(() => Boolean(documentationSummary(element)));
135139
const summaryShadowRoot = documentationSummary(element).shadowRoot;
136140
await waitUntil(() => Boolean(summaryShadowRoot.querySelector('.api-title')));
137141
assert.equal(summaryShadowRoot.querySelector('.api-title').textContent.trim(), 'API title:\n Google Drive');
@@ -777,4 +781,77 @@ describe('API Console documentation', () => {
777781
});
778782
});
779783
});
784+
785+
[
786+
new ApiDescribe('Regular model'),
787+
new ApiDescribe('Compact model', true)
788+
].forEach(({ label, compact }) => {
789+
describe(label, () => {
790+
let docShadowRoot;
791+
792+
before(async () => {
793+
amf = await AmfLoader.load({ compact, fileName: 'streetlights' });
794+
});
795+
796+
describe('Async APIs', () => {
797+
describe('Subscribe', () => {
798+
beforeEach(async () => {
799+
element = await amfFixture(amf);
800+
await navigationSelectEndpointMethod(element, 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured', 'subscribe');
801+
await aTimeout(100);
802+
const item = documentationMethod(element);
803+
docShadowRoot = item.shadowRoot;
804+
});
805+
806+
it('should render URL', async () => {
807+
await waitUntil(() => Boolean(docShadowRoot.querySelector('api-url')));
808+
const apiUrl = docShadowRoot.querySelector('api-url').shadowRoot;
809+
assert.equal(apiUrl.querySelector('.url-channel-value').innerText.trim(), 'Channel\nsmartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured');
810+
assert.equal(apiUrl.querySelector('.url-server-value').innerText.trim(), 'Server\nmqtt://api.streetlights.smartylighting.com:{port}');
811+
});
812+
813+
it('should render description', async () => {
814+
await waitUntil(() => Boolean(docShadowRoot.querySelector('arc-marked')));
815+
assert.equal(docShadowRoot.querySelector('arc-marked').querySelector('.markdown-body').innerText.trim(), 'The topic on which measured values may be produced and consumed.');
816+
});
817+
818+
it('should render methods', async () => {
819+
await waitUntil(() => Boolean(docShadowRoot.querySelector('.request-documentation')));
820+
const requestDocumentation = docShadowRoot.querySelector('.request-documentation');
821+
assert.exists(requestDocumentation);
822+
assert.exists(requestDocumentation.querySelector('.security'));
823+
assert.exists(requestDocumentation.querySelector('api-parameters-document'));
824+
assert.exists(requestDocumentation.querySelector('api-headers-document'));
825+
assert.exists(requestDocumentation.querySelector('api-body-document'));
826+
});
827+
});
828+
829+
describe('Publish', () => {
830+
beforeEach(async () => {
831+
await navigationSelectEndpointMethod(element, 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on', 'publish');
832+
await aTimeout(100);
833+
const item = documentationMethod(element);
834+
docShadowRoot = item.shadowRoot;
835+
});
836+
837+
it('should render URL', async () => {
838+
await waitUntil(() => Boolean(docShadowRoot.querySelector('api-url')));
839+
const apiUrl = docShadowRoot.querySelector('api-url').shadowRoot;
840+
assert.equal(apiUrl.querySelector('.url-channel-value').innerText.trim(), 'Channelsmartylighting/streetlights/1/0/action/{streetlightId}/turn/on');
841+
assert.equal(apiUrl.querySelector('.url-server-value').innerText.trim(), 'Servermqtt://api.streetlights.smartylighting.com:{port}');
842+
});
843+
844+
it('should render methods', async () => {
845+
await waitUntil(() => Boolean(docShadowRoot.querySelector('.request-documentation')));
846+
const requestDocumentation = docShadowRoot.querySelector('.request-documentation');
847+
assert.exists(requestDocumentation);
848+
assert.exists(requestDocumentation.querySelector('.security'));
849+
assert.exists(requestDocumentation.querySelector('api-parameters-document'));
850+
assert.exists(requestDocumentation.querySelector('api-headers-document'));
851+
assert.exists(requestDocumentation.querySelector('api-body-document'));
852+
});
853+
});
854+
});
855+
});
856+
});
780857
});

test/api-console-navigation.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,4 +555,55 @@ describe('API Console navigation', () => {
555555
});
556556
});
557557
});
558+
559+
[
560+
new ApiDescribe('Regular model'),
561+
new ApiDescribe('Compact model', true)
562+
].forEach(({ label, compact }) => {
563+
describe(label, () => {
564+
let element;
565+
let amf;
566+
567+
describe('Async APIs', () => {
568+
before(async () => {
569+
amf = await AmfLoader.load({ compact, fileName: 'streetlights' });
570+
});
571+
572+
beforeEach(async () => {
573+
element = await amfFixture(amf);
574+
});
575+
576+
it('should render all sections', () => {
577+
assert.ok(navigationSummarySection(element));
578+
assert.ok(navigationEndpointsSection(element));
579+
assert.notOk(navigationDocumentationSection(element));
580+
assert.ok(navigationTypesSection(element));
581+
assert.ok(navigationSecuritySection(element));
582+
});
583+
584+
it('should list all channels', () => {
585+
const endpointsList = navigationEndpointsList(element);
586+
assert.ok(endpointsList);
587+
assert.lengthOf(endpointsList, 4);
588+
589+
[
590+
['smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured', 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured'],
591+
['smartylighting/streetlights/1/0/action/{streetlightId}/turn/on', 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/on'],
592+
['smartylighting/streetlights/1/0/action/{streetlightId}/turn/off', 'smartylighting/streetlights/1/0/action/{streetlightId}/turn/off'],
593+
['smartylighting/streetlights/1/0/action/{streetlightId}/dim', 'smartylighting/streetlights/1/0/action/{streetlightId}/dim'],
594+
].forEach((([path, name], index) => testEndpoint(endpointsList[index], path, name)));
595+
});
596+
597+
it('should list all security items', () => {
598+
const securityList = navigationSecurityList(element);
599+
assert.ok(securityList);
600+
assert.lengthOf(securityList, 3);
601+
602+
assert.equal(securityList[0].textContent.trim(), 'apiKey - Api Key');
603+
assert.equal(securityList[1].textContent.trim(), 'supportedOauthFlows - OAuth 2.0');
604+
assert.equal(securityList[2].textContent.trim(), 'openIdConnectWellKnown - OpenID Connect');
605+
});
606+
});
607+
});
608+
});
558609
});

test/api-console-request.test.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
requestBodySection, requestCredentialsSection,
99
requestHeadersSection, requestPanel,
1010
requestQueryParamSection, requestSendButton,
11-
requestUrlSection,
11+
requestUrlSection
1212
} from './testHelper.js';
1313

1414
/** @typedef {import('..').ApiConsole} ApiConsole */
@@ -170,7 +170,8 @@ describe('API Console request', () => {
170170
assert.exists(credentialsSection);
171171
});
172172

173-
it('should render auth label', () => {
173+
it('should render auth label', async () => {
174+
await waitUntil(() => Boolean(credentialsSection.shadowRoot.querySelector('.auth-selector-label')));
174175
assert.equal(credentialsSection.shadowRoot.querySelector('.auth-selector-label').innerText, 'x-custom');
175176
});
176177

@@ -297,6 +298,7 @@ describe('API Console request', () => {
297298
});
298299

299300
it('should render scheme fields', async () => {
301+
await waitUntil(() => Boolean(credentialsSection.shadowRoot.querySelector('api-authorization-method')));
300302
const authorizationMethod = credentialsSection.shadowRoot.querySelector('api-authorization-method');
301303
await waitUntil(() => Boolean(authorizationMethod.shadowRoot.querySelector('form')));
302304
const authorizationMethodForm = authorizationMethod.shadowRoot.querySelector('form');
@@ -679,4 +681,30 @@ describe('API Console request', () => {
679681
});
680682
});
681683
});
684+
685+
[
686+
new ApiDescribe('Regular model'),
687+
new ApiDescribe('Compact model', true)
688+
].forEach(({ label, compact }) => {
689+
describe(label, () => {
690+
let element;
691+
let amf;
692+
693+
describe('Async APIs', () => {
694+
before(async () => {
695+
amf = await AmfLoader.load({ compact, fileName: 'streetlights' });
696+
});
697+
698+
beforeEach(async () => {
699+
element = await amfFixture(amf);
700+
await navigationSelectEndpointMethod(element, 'smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured', 'subscribe');
701+
await aTimeout(50);
702+
});
703+
704+
it('should not render request panel', () => {
705+
assert.notExists(requestPanel(element));
706+
});
707+
});
708+
});
709+
});
682710
});

0 commit comments

Comments
 (0)