Skip to content

Commit 715f997

Browse files
authored
test(APIC-741): run tests for flattened model (#741)
* test(APIC-741): run tests for flattened model * test: add waitUntil * test: add waitUntil
1 parent 67e54b2 commit 715f997

File tree

8 files changed

+126
-73
lines changed

8 files changed

+126
-73
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@ dist/
6161

6262
# AMF models
6363
demo/models/*.json
64+
demo/models/flattened/*.json
6465

6566
.idea/

demo/flattened-apis.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"models/demo-api/demo-api.raml": { "type": "RAML 1.0", "flattened": true},
3+
"models/google-drive-api/google-drive-api.raml": { "type": "RAML 1.0", "flattened": true},
4+
"models/multi-server/multi-server.yaml": { "type": "OAS 3.0", "mime": "application/yaml", "flattened": true },
5+
"models/async-api/async-api.yaml": { "type": "ASYNC 2.0", "flattened": true },
6+
"models/APIC-553/APIC-553.raml": { "type": "RAML 1.0", "flattened": true},
7+
"models/APIC-554/APIC-554.raml": { "type": "RAML 1.0", "flattened": true},
8+
"models/APIC-557/APIC-557.yaml": { "type": "OAS 3.0", "flattened": true },
9+
"models/anyOf/anyOf.yaml": { "type": "ASYNC 2.0", "flattened": true },
10+
"models/streetlights/streetlights.yaml": { "type": "ASYNC 2.0", "flattened": true },
11+
"models/test-api/test-api.raml": { "type": "RAML 1.0", "flattened": true},
12+
"models/test-api/basicAuth.raml": { "type": "RAML 1.0", "flattened": true},
13+
"models/test-api/documentation.raml": { "type": "RAML 1.0", "flattened": true},
14+
"models/test-api/extension.raml": { "type": "RAML 1.0", "flattened": true},
15+
"models/test-api/library.raml": { "type": "RAML 1.0", "flattened": true},
16+
"models/test-api/overlay.raml": { "type": "RAML 1.0", "flattened": true},
17+
"models/test-api/person.raml": { "type": "RAML 1.0", "flattened": true},
18+
"models/representative-service/representative-service.yaml": { "type": "OAS 3.0", "flattened": true },
19+
"models/APIC-763/APIC-763.raml": { "type": "RAML 1.0", "flattened": true},
20+
"models/multipart-api/multipart-api.raml": { "type": "RAML 1.0", "flattened": true}
21+
}

demo/model.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
/* eslint-disable no-console */
2+
// eslint-disable-next-line no-undef
13
const generator = require('@api-components/api-model-generator');
24
generator('demo/apis.json', {
35
dest: 'demo/models/'
4-
})
5-
.then(() => console.log('Models created'))
6-
.catch((cause) => console.error(cause));
6+
}).
7+
then(() => console.log('Models created')).
8+
catch((cause) => console.error(cause));
9+
10+
generator('demo/flattened-apis.json', {
11+
dest: 'demo/models/flattened/'
12+
}).
13+
then(() => console.log('Models created')).
14+
catch((cause) => console.error(cause));

test/amf-loader.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ export class ApiDescribe {
99
/**
1010
* @param {string} label
1111
* @param {boolean} compact
12+
* @param {boolean} flattened
1213
*/
13-
constructor(label, compact=false) {
14+
constructor(label, compact=false, flattened=false) {
1415
/**
1516
* @type {string}
1617
*/
@@ -19,6 +20,10 @@ export class ApiDescribe {
1920
* @type {boolean}
2021
*/
2122
this.compact = compact;
23+
/**
24+
* @type {boolean}
25+
*/
26+
this.flattened = flattened;
2227
}
2328
}
2429

@@ -35,6 +40,7 @@ const helper = new HelperElement();
3540
* @typedef {Object} ApiLoadOptions
3641
* @property {boolean=} compact Whether to download a compact version of an API
3742
* @property {string=} fileName Name of the API file, without the extension
43+
* @property {boolean=} flattened Whether to generate flattened model or not
3844
*/
3945

4046
/**
@@ -80,10 +86,10 @@ const helper = new HelperElement();
8086
* @return {Promise<ApiModel>} Promise resolved to API object.
8187
*/
8288
AmfLoader.load = async (config = {}) => {
83-
const { compact=false, fileName='demo-api' } = config;
89+
const { compact=false, fileName='demo-api', flattened=false } = config;
8490
const suffix = compact ? '-compact' : '';
8591
const file = `${fileName}${suffix}.json`;
86-
const url = `${window.location.protocol }//${ window.location.host }/base/demo/models/${ file}`;
92+
const url = `${window.location.protocol}//${window.location.host}/base/demo/models/${flattened? 'flattened/' : ''}${file}`;
8793
const response = await fetch(url);
8894
if (!response.ok) {
8995
throw new Error(`Unable to download ${url}`);
@@ -97,7 +103,7 @@ AmfLoader.load = async (config = {}) => {
97103
* @param {ApiModel} model Api model.
98104
* @return {WebApiModel} Model for the WebApi
99105
*/
100-
AmfLoader.lookupWebApi = function(model) {
106+
AmfLoader.lookupWebApi = (model) => {
101107
helper.amf = model;
102108
return helper._computeApi(model);
103109
};
@@ -108,7 +114,7 @@ AmfLoader.lookupWebApi = function(model) {
108114
* @param {string} endpoint Endpoint path
109115
* @return {EndpointModel|undefined} Model for the endpoint
110116
*/
111-
AmfLoader.lookupEndpoint = function(model, endpoint) {
117+
AmfLoader.lookupEndpoint = (model, endpoint) => {
112118
helper.amf = model;
113119
const webApi = helper._computeApi(model);
114120
return helper._computeEndpointByPath(webApi, endpoint);
@@ -121,7 +127,7 @@ AmfLoader.lookupEndpoint = function(model, endpoint) {
121127
* @param {string} operation Operation name (the verb, lowercase)
122128
* @return {OperationModel|undefined} Model for the endpoint
123129
*/
124-
AmfLoader.lookupOperation = function(model, endpoint, operation) {
130+
AmfLoader.lookupOperation = (model, endpoint, operation) => {
125131
const endPoint = AmfLoader.lookupEndpoint(model, endpoint);
126132
const opKey = helper._getAmfKey(helper.ns.aml.vocabularies.apiContract.supportedOperation);
127133
const ops = helper._ensureArray(endPoint[opKey]);
@@ -135,7 +141,7 @@ AmfLoader.lookupOperation = function(model, endpoint, operation) {
135141
* @param {string} operation Operation name (the verb, lowercase)
136142
* @return {PayloadModel[]|undefined} Model for the payload
137143
*/
138-
AmfLoader.lookupPayload = function(model, endpoint, operation) {
144+
AmfLoader.lookupPayload = (model, endpoint, operation) => {
139145
const op = AmfLoader.lookupOperation(model, endpoint, operation);
140146
const expects = helper._computeExpects(op);
141147
return helper._ensureArray(helper._computePayload(expects));
@@ -154,7 +160,7 @@ AmfLoader.lookupPayload = function(model, endpoint, operation) {
154160
* @param {string} operation Operation name (the verb, lowercase)
155161
* @return {Array<EndpointModel|OperationModel>} First item is the endpoint model and the second is the operation model.
156162
*/
157-
AmfLoader.lookupEndpointOperation = function(model, endpoint, operation) {
163+
AmfLoader.lookupEndpointOperation = (model, endpoint, operation) => {
158164
const endPoint = AmfLoader.lookupEndpoint(model, endpoint);
159165
const opKey = helper._getAmfKey(helper.ns.aml.vocabularies.apiContract.supportedOperation);
160166
const ops = helper._ensureArray(endPoint[opKey]);
@@ -168,11 +174,9 @@ AmfLoader.lookupEndpointOperation = function(model, endpoint, operation) {
168174
* @param {string} name Name of the security scheme
169175
* @return {SecurityModel}
170176
*/
171-
AmfLoader.lookupSecurity = function(model, name) {
177+
AmfLoader.lookupSecurity = (model, name) => {
172178
helper.amf = model;
173-
const webApi = helper._hasType(model, helper.ns.aml.vocabularies.document.Document) ?
174-
helper._computeApi(model) :
175-
model;
179+
const webApi = helper._hasType(model, helper.ns.aml.vocabularies.document.Document)? helper._computeApi(model): model;
176180
const declares = helper._computeDeclares(webApi) || [];
177181
let result = declares.find((item) => {
178182
if (item instanceof Array) {
@@ -208,11 +212,9 @@ AmfLoader.lookupSecurity = function(model, name) {
208212
* @param {string} name Name of the data type
209213
* @return {TypeModel}
210214
*/
211-
AmfLoader.lookupType = function(model, name) {
215+
AmfLoader.lookupType = (model, name) => {
212216
helper.amf = model;
213-
const webApi = helper._hasType(model, helper.ns.aml.vocabularies.document.Document) ?
214-
helper._computeApi(model) :
215-
model;
217+
const webApi = helper._hasType(model, helper.ns.aml.vocabularies.document.Document)? helper._computeApi(model): model;
216218
const declares = helper._computeDeclares(webApi) || [];
217219
let result = declares.find((item) => {
218220
if (item instanceof Array) {
@@ -244,7 +246,7 @@ AmfLoader.lookupType = function(model, name) {
244246
* @param {string} name Name of the documentation
245247
* @return {DocumentationModel}
246248
*/
247-
AmfLoader.lookupDocumentation = function(model, name) {
249+
AmfLoader.lookupDocumentation = (model, name) => {
248250
helper.amf = model;
249251
const webApi = helper._computeApi(model);
250252
const key = helper._getAmfKey(helper.ns.aml.vocabularies.core.documentation);
@@ -262,7 +264,7 @@ AmfLoader.lookupDocumentation = function(model, name) {
262264
* @param {ApiModel} model Api model.
263265
* @return {EncodeModel[]}
264266
*/
265-
AmfLoader.lookupEncodes = function(model) {
267+
AmfLoader.lookupEncodes = (model) => {
266268
if (model instanceof Array) {
267269
model = model[0];
268270
}

test/api-console-documentation.test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ describe('API Console documentation', () => {
3434

3535
const googleApi = 'google-drive-api';
3636
const testApi = 'test-api';
37+
const streetlights = 'streetlights';
38+
const representativeService = 'representative-service';
3739
let element;
3840
let amf;
3941

@@ -111,7 +113,7 @@ describe('API Console documentation', () => {
111113

112114
[
113115
new ApiDescribe('Regular model'),
114-
new ApiDescribe('Compact model', true)
116+
new ApiDescribe('Compact model', true),
115117
].forEach(({ label, compact }) => {
116118
describe(label, () => {
117119
before(async () => {
@@ -194,7 +196,7 @@ describe('API Console documentation', () => {
194196

195197
[
196198
new ApiDescribe('Regular model'),
197-
new ApiDescribe('Compact model', true)
199+
new ApiDescribe('Compact model', true),
198200
].forEach(({ label, compact }) => {
199201
describe(label, () => {
200202
before(async () => {
@@ -808,13 +810,14 @@ describe('API Console documentation', () => {
808810

809811
[
810812
new ApiDescribe('Regular model'),
811-
new ApiDescribe('Compact model', true)
812-
].forEach(({ label, compact }) => {
813+
new ApiDescribe('Compact model', true),
814+
new ApiDescribe('Flattened model', false, true),
815+
].forEach(({ label, compact, flattened }) => {
813816
describe(label, () => {
814817
let docShadowRoot;
815818

816819
before(async () => {
817-
amf = await AmfLoader.load({ compact, fileName: 'streetlights' });
820+
amf = await AmfLoader.load({ compact, fileName: streetlights, flattened });
818821
});
819822

820823
describe('Async APIs', () => {
@@ -888,7 +891,7 @@ describe('API Console documentation', () => {
888891
let docShadowRoot;
889892

890893
before(async () => {
891-
amf = await AmfLoader.load({ compact, fileName: 'representative-service' });
894+
amf = await AmfLoader.load({ compact, fileName: representativeService });
892895
});
893896

894897
describe('OAS 3.0', () => {
@@ -921,7 +924,8 @@ describe('API Console documentation', () => {
921924
assert.exists(requestDocumentation.querySelector('.callbacks'));
922925
});
923926

924-
it('should render responses', () => {
927+
it('should render responses', async () => {
928+
await waitUntil(() => Boolean(docShadowRoot.querySelector('.response-documentation')));
925929
assert.exists(docShadowRoot.querySelector('.response-documentation'));
926930
});
927931

test/api-console-navigation.test.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ describe('API Console navigation', () => {
2727

2828
[
2929
new ApiDescribe('Regular model'),
30-
new ApiDescribe('Compact model', true)
31-
].forEach(({ label, compact }) => {
30+
new ApiDescribe('Compact model', true),
31+
new ApiDescribe('Flattened model', false, true),
32+
].forEach(({ label, compact, flattened }) => {
3233
describe(label, () => {
3334
let element;
3435
let amf;
3536

3637
before(async () => {
37-
amf = await AmfLoader.load({ compact, fileName: googleApi });
38+
amf = await AmfLoader.load({ compact, fileName: googleApi, flattened });
3839
});
3940

4041
beforeEach(async () => {
@@ -374,16 +375,17 @@ describe('API Console navigation', () => {
374375

375376
[
376377
new ApiDescribe('Regular model'),
377-
new ApiDescribe('Compact model', true)
378-
].forEach(({ label, compact }) => {
378+
new ApiDescribe('Compact model', true),
379+
new ApiDescribe('Flattened model', false, true),
380+
].forEach(({ label, compact, flattened }) => {
379381
describe(label, () => {
380382
let element;
381383
let amf;
382384

383385
describe('RAML Fragments', () => {
384386
describe('SecurityScheme fragment', () => {
385387
before(async () => {
386-
amf = await AmfLoader.load({ compact, fileName: 'basicAuth' });
388+
amf = await AmfLoader.load({ compact, fileName: 'basicAuth', flattened });
387389
});
388390

389391
beforeEach(async () => {
@@ -408,7 +410,7 @@ describe('API Console navigation', () => {
408410

409411
describe('DocumentationItem fragment', () => {
410412
before(async () => {
411-
amf = await AmfLoader.load({ compact, fileName: 'documentation' });
413+
amf = await AmfLoader.load({ compact, fileName: 'documentation', flattened });
412414
});
413415

414416
beforeEach(async () => {
@@ -433,7 +435,7 @@ describe('API Console navigation', () => {
433435

434436
describe('Extension fragment', () => {
435437
before(async () => {
436-
amf = await AmfLoader.load({ compact, fileName: 'extension' });
438+
amf = await AmfLoader.load({ compact, fileName: 'extension', flattened });
437439
});
438440

439441
beforeEach(async () => {
@@ -458,7 +460,7 @@ describe('API Console navigation', () => {
458460

459461
describe('Library fragment', () => {
460462
before(async () => {
461-
amf = await AmfLoader.load({ compact, fileName: 'library' });
463+
amf = await AmfLoader.load({ compact, fileName: 'library', flattened });
462464
});
463465

464466
beforeEach(async () => {
@@ -483,7 +485,7 @@ describe('API Console navigation', () => {
483485

484486
describe('Overlay fragment', () => {
485487
before(async () => {
486-
amf = await AmfLoader.load({ compact, fileName: 'overlay' });
488+
amf = await AmfLoader.load({ compact, fileName: 'overlay', flattened });
487489
});
488490

489491
beforeEach(async () => {
@@ -531,7 +533,7 @@ describe('API Console navigation', () => {
531533

532534
describe('DataType fragment', () => {
533535
before(async () => {
534-
amf = await AmfLoader.load({ compact, fileName: 'person' });
536+
amf = await AmfLoader.load({ compact, fileName: 'person', flattened });
535537
});
536538

537539
beforeEach(async () => {
@@ -559,15 +561,16 @@ describe('API Console navigation', () => {
559561

560562
[
561563
new ApiDescribe('Regular model'),
562-
new ApiDescribe('Compact model', true)
563-
].forEach(({ label, compact }) => {
564+
new ApiDescribe('Compact model', true),
565+
new ApiDescribe('Flattened model', false, true),
566+
].forEach(({ label, compact, flattened }) => {
564567
describe(label, () => {
565568
let element;
566569
let amf;
567570

568571
describe('Async APIs', () => {
569572
before(async () => {
570-
amf = await AmfLoader.load({ compact, fileName: 'streetlights' });
573+
amf = await AmfLoader.load({ compact, fileName: 'streetlights', flattened });
571574
});
572575

573576
beforeEach(async () => {

test/api-console-request.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,15 +711,16 @@ describe('API Console request', () => {
711711

712712
[
713713
new ApiDescribe('Regular model'),
714-
new ApiDescribe('Compact model', true)
715-
].forEach(({ label, compact }) => {
714+
new ApiDescribe('Compact model', true),
715+
new ApiDescribe('Flattened model', false, true),
716+
].forEach(({ label, compact, flattened }) => {
716717
describe(label, () => {
717718
let element;
718719
let amf;
719720

720721
describe('Async APIs', () => {
721722
before(async () => {
722-
amf = await AmfLoader.load({ compact, fileName: 'streetlights' });
723+
amf = await AmfLoader.load({ compact, fileName: 'streetlights', flattened });
723724
});
724725

725726
beforeEach(async () => {
@@ -800,10 +801,11 @@ describe('API Console request', () => {
800801
await aTimeout(50);
801802
});
802803

803-
it('should render request panel with optional field to overwrite content type', () => {
804+
it('should render request panel with optional field to overwrite content type', async () => {
804805
const requestBody = requestBodySection(element);
805806
assert.exists(requestBody);
806807

808+
await waitUntil(() => Boolean(requestBody.shadowRoot.querySelector('multipart-payload-editor')));
807809
const multipartPayload = requestBody.shadowRoot.querySelector('multipart-payload-editor');
808810
assert.exists(multipartPayload);
809811

0 commit comments

Comments
 (0)