Skip to content

Commit 64756d3

Browse files
committed
Enhance ApiSummary component by adding an agent pill for endpoints with agents, improving visual indication. Update styles for the agent pill and info icon. Refactor tests to include validation for the agent pill rendering.
1 parent e207344 commit 64756d3

File tree

3 files changed

+50
-109
lines changed

3 files changed

+50
-109
lines changed

src/ApiSummary.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,18 +628,22 @@ export class ApiSummary extends AmfHelperMixin(LitElement) {
628628
return html`
629629
<a
630630
href="#${`${endpoint.path}/${item.method}`}"
631-
class="method-label ${item.hasAgent ? "method-label-with-icon" : ""}"
631+
class="method-label"
632632
data-method="${item.method}"
633633
data-id="${item.id}"
634634
data-shape-type="method"
635635
title="Open method documentation"
636-
>${item.method}
637-
${
638-
item.hasAgent
639-
? html`<arc-icon icon="codegenie" class='method-icon'></arc-icon>`
640-
: ""
641-
}
642-
</a>
636+
>${item.method}</a
637+
>
638+
639+
${item.hasAgent
640+
? html`
641+
<span class="agent-pill" title="Enabled for Agent">
642+
Enabled for Agent
643+
<arc-icon icon="infoOutline" class="info-icon"></arc-icon>
644+
</span>
645+
`
646+
: ''}
643647
`;
644648
}
645649

src/Styles.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,27 @@ export default css`
224224
font-size: var(--api-summary-server-description-font-size, 12px);
225225
font-weight: var(--api-summary-server-description-font-weight, 600);
226226
}
227+
228+
.endpoint-header {
229+
display: flex;
230+
align-items: flex-start;
231+
}
232+
233+
.agent-pill {
234+
display: flex;
235+
align-items: center;
236+
padding: 2px 8px;
237+
border-radius: 16px;
238+
background-color: var(--agent-pill-background-color, #e0e0e0);
239+
color: var(--agent-pill-color, #455a64);
240+
font-size: 12px;
241+
margin-left: 8px;
242+
}
243+
244+
.info-icon {
245+
color: var(--agent-pill-info-icon-color, #757575);
246+
width: 16px;
247+
height: 16px;
248+
margin-left: 8px;
249+
}
227250
`;

test/api-summary.test.js

Lines changed: 15 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ describe('ApiSummary', () => {
1414
return fixture(html`<api-summary></api-summary>`);
1515
}
1616

17+
/**
18+
* @returns {Promise<ApiSummary>}
19+
*/
20+
async function agentFixture() {
21+
const amf = await AmfLoader.load(false, 'agents-api');
22+
return fixture(html`<api-summary .amf="${amf}"></api-summary>`);
23+
}
24+
1725
/**
1826
* @param {any} amf
1927
* @returns {Promise<ApiSummary>}
@@ -349,116 +357,22 @@ describe('ApiSummary', () => {
349357
});
350358
});
351359

352-
describe('Endpoints rendering with agents', () => {
360+
describe("Endpoints rendering with agents", () => {
353361
let element = /** @type ApiSummary */ (null);
354-
let amf;
355-
356-
before(async () => {
357-
amf = await AmfLoader.load(compact,'agents-api');
358-
});
359362

360363
beforeEach(async () => {
361-
element = await basicFixture();
362-
element.amf = amf;
364+
element = await agentFixture();
363365
await aTimeout(0);
364366
});
365367

366-
it('adds separator', () => {
367-
const node = element.shadowRoot.querySelector('.separator');
368-
assert.ok(node);
369-
});
370-
371-
it('renders all endpoints', () => {
372-
const nodes = element.shadowRoot.querySelectorAll('.endpoint-item');
368+
it("renders the list of endpoints", async () => {
369+
const nodes = element.shadowRoot.querySelectorAll(".endpoint-item");
373370
assert.lengthOf(nodes, 2);
374371
});
375372

376-
it('renders endpoint name', () => {
377-
const node = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelector('.endpoint-path');
378-
assert.dom.equal(
379-
node,
380-
`<a
381-
class="endpoint-path"
382-
data-shape-type="endpoint"
383-
href="#/reservations/reservationlookup"
384-
title="Open endpoint documentation"
385-
>
386-
/reservations/reservationlookup
387-
</a>`,
388-
{
389-
ignoreAttributes: ['data-id']
390-
}
391-
);
392-
});
393-
394-
it('sets data-id on name', () => {
395-
const node = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelector('.endpoint-path');
396-
assert.ok(node.getAttribute('data-id'));
397-
});
398-
399-
it('sets data-id on path', () => {
400-
const node = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelector('.endpoint-path');
401-
assert.ok(node.getAttribute('data-id'));
402-
});
403-
404-
it('renders list of operations', () => {
405-
const nodes = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelectorAll('.method-label');
406-
assert.lengthOf(nodes, 1);
407-
});
408-
409-
it('renders operation method', () => {
410-
const node = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelector('.method-label');
411-
assert.dom.equal(
412-
node,
413-
`<a
414-
class="method-label method-label-with-icon"
415-
data-method="get"
416-
data-shape-type="method"
417-
href="#/reservations/reservationlookup/get"
418-
title="Open method documentation"
419-
>get
420-
<arc-icon class="method-icon" icon="codegenie"></arc-icon>
421-
</a>`,
422-
{
423-
ignoreAttributes: ['data-id']
424-
}
425-
);
426-
});
427-
428-
it('Click on an endpoint dispatches navigation event', (done) => {
429-
const node = element.shadowRoot.querySelector(`.endpoint-path[data-id]`);
430-
element.addEventListener('api-navigation-selection-changed', (e) => {
431-
// @ts-ignore
432-
const {detail} = e;
433-
assert.typeOf(detail.selected, 'string');
434-
assert.equal(detail.type, 'endpoint');
435-
done();
436-
});
437-
/** @type HTMLElement */ (node).click();
438-
});
439-
440-
it('Click on an endpoint path dispatches navigation event', (done) => {
441-
const node = element.shadowRoot.querySelector(`.endpoint-path[data-id]`);
442-
element.addEventListener('api-navigation-selection-changed', (e) => {
443-
// @ts-ignore
444-
const {detail} = e;
445-
assert.typeOf(detail.selected, 'string');
446-
assert.equal(detail.type, 'endpoint');
447-
done();
448-
});
449-
/** @type HTMLElement */ (node).click();
450-
});
451-
452-
it('Click on a method dispatches navigation event', (done) => {
453-
const node = element.shadowRoot.querySelector(`.method-label[data-id]`);
454-
element.addEventListener('api-navigation-selection-changed', (e) => {
455-
// @ts-ignore
456-
const {detail} = e;
457-
assert.typeOf(detail.selected, 'string');
458-
assert.equal(detail.type, 'method');
459-
done();
460-
});
461-
/** @type HTMLElement */ (node).click();
373+
it('renders the agent pill', async () => {
374+
const node = element.shadowRoot.querySelector('.agent-pill');
375+
assert.ok(node);
462376
});
463377
});
464378

0 commit comments

Comments
 (0)