Skip to content

Commit 323e1f2

Browse files
committed
test: add unit tests for gRPC API functionality in ApiConsole
1 parent bfd1f1d commit 323e1f2

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

test/api-console.amf.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const selectOperation = (element, endpointName, operationName) => {
3636

3737
describe('ApiConsole', () => {
3838
const asyncApi = 'async-api';
39+
const grpcApi = 'grpc-test';
3940
const multiServer = 'multi-server';
4041
const apic553 = 'APIC-553';
4142
const apic554 = 'APIC-554';
@@ -212,6 +213,56 @@ describe('ApiConsole', () => {
212213
});
213214
});
214215

216+
describe('gRPC API', () => {
217+
[
218+
new ApiDescribe('Regular model'),
219+
new ApiDescribe('Compact model', true),
220+
new ApiDescribe('Flattened model', false, true),
221+
].forEach(({ label, compact, flattened }) => {
222+
describe(label, () => {
223+
let amf;
224+
let element;
225+
226+
before(async () => {
227+
amf = await AmfLoader.load({ compact, fileName: grpcApi, flattened });
228+
});
229+
230+
beforeEach(async () => {
231+
element = await amfFixture(amf);
232+
await aTimeout(0);
233+
});
234+
235+
it('should have _noTryItValue set to true for gRPC API', () => {
236+
assert.isTrue(element._noTryItValue, '_noTryItValue should be true for gRPC API');
237+
});
238+
239+
it('should detect gRPC API correctly', () => {
240+
const isGrpc = element._isGrpcApi(amf);
241+
assert.isTrue(isGrpc, 'Should detect gRPC API');
242+
});
243+
244+
it('should hide try-it button when selecting a method', async () => {
245+
const webApi = AmfLoader.lookupWebApi(amf);
246+
const endpoints = element._computeEndpoints(webApi);
247+
if (endpoints && endpoints.length > 0) {
248+
const operations = element._computePropertyArray(
249+
endpoints[0],
250+
element.ns.aml.vocabularies.apiContract.supportedOperation
251+
);
252+
if (operations && operations.length > 0) {
253+
element.selectedShape = operations[0]['@id'];
254+
element.selectedShapeType = 'method';
255+
await nextFrame();
256+
await nextFrame();
257+
258+
assert.isTrue(element._noTryItValue, 'Try-it button should be hidden for gRPC API method');
259+
}
260+
}
261+
});
262+
});
263+
});
264+
});
265+
215266
describe('APIC-553', () => {
216267
[
217268
new ApiDescribe('Regular model'),

0 commit comments

Comments
 (0)