Skip to content

Commit cfc79e1

Browse files
committed
test: - coverage;
1 parent 0c1a483 commit cfc79e1

13 files changed

Lines changed: 179 additions & 100 deletions

File tree

src/components/organisms/accordion/accordion.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,9 @@ describe('ForgeAccordion', () => {
420420

421421
const aiState = el.aiState;
422422

423-
expect(aiState.panelCount).to.equal(4);
424-
expect(aiState.expandedCount).to.equal(0);
425-
expect(aiState.multiple).to.be.false;
426-
expect(aiState.multiple).to.be.false;
423+
expect(aiState.state.panelCount).to.equal(4);
424+
expect(aiState.state.expandedCount).to.equal(0);
425+
expect(aiState.state.multiple).to.be.false;
427426
});
428427

429428
it('should provide possible actions', async () => {

src/components/organisms/accordion/accordion.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,12 @@ export class ForgeAccordion extends BaseElement {
143143
override get aiState(): AIComponentState {
144144
return {
145145
...super.aiState,
146-
panelCount: this.panels.length,
147-
expandedCount: this.expandedPanels.length,
148-
multiple: this.multiple
146+
state: {
147+
...super.aiState.state,
148+
panelCount: this.panels.length,
149+
expandedCount: this.expandedPanels.length,
150+
multiple: this.multiple
151+
}
149152
};
150153
}
151154

@@ -172,7 +175,13 @@ export class ForgeAccordion extends BaseElement {
172175
name: isExpanded ? 'collapse' : 'expand',
173176
description: `${isExpanded ? 'Collapse' : 'Expand'} ${panel.header}`,
174177
available: true,
175-
params: [panel.id]
178+
parameters: [{
179+
name: 'panelId',
180+
type: 'text',
181+
required: true,
182+
defaultValue: panel.id,
183+
description: 'ID of the panel to toggle'
184+
}]
176185
});
177186
}
178187
});

src/components/organisms/data-table/data-table.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ describe('ForgeDataTable', () => {
258258

259259
const aiState = el.aiState;
260260

261-
expect(aiState.rowCount).to.equal(4);
262-
expect(aiState.columnCount).to.equal(5);
263-
expect(aiState.sortable).to.be.true;
264-
expect(aiState.selectable).to.be.false;
261+
expect(aiState.state.rowCount).to.equal(4);
262+
expect(aiState.state.columnCount).to.equal(5);
263+
expect(aiState.state.sortable).to.be.true;
264+
expect(aiState.state.selectable).to.be.false;
265265
});
266266

267267
it('should provide possible actions', async () => {

src/components/organisms/data-table/data-table.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ export class ForgeDataTable extends BaseElement {
342342
const columnId = header.getAttribute('data-column-id');
343343
const column = this.columns.find(col => col.id === columnId);
344344
if (column?.sortable) {
345-
header.style.cursor = 'pointer';
346-
header.onclick = () => this.handleSort(column);
345+
(header as HTMLElement).style.cursor = 'pointer';
346+
(header as HTMLElement).onclick = () => this.handleSort(column);
347347
}
348348
});
349349
}
@@ -773,17 +773,20 @@ export class ForgeDataTable extends BaseElement {
773773
override get aiState(): AIComponentState {
774774
return {
775775
...super.aiState,
776-
rowCount: this.rows.length,
777-
columnCount: this.columns.length,
778-
selectedCount: this.selectedRows.size,
779-
expandedCount: this.expandedRows.size,
780-
sortColumn: this.sortColumn,
781-
sortDirection: this.sortDirection,
782-
currentPage: this.currentPage,
783-
loading: this.loading,
784-
sortable: this.columns.some(col => col.sortable),
785-
selectable: this.selectable,
786-
expandable: this.expandable
776+
state: {
777+
...super.aiState.state,
778+
rowCount: this.rows.length,
779+
columnCount: this.columns.length,
780+
selectedCount: this.selectedRows.size,
781+
expandedCount: this.expandedRows.size,
782+
sortColumn: this.sortColumn,
783+
sortDirection: this.sortDirection,
784+
currentPage: this.currentPage,
785+
loading: this.loading,
786+
sortable: this.columns.some(col => col.sortable),
787+
selectable: this.selectable,
788+
expandable: this.expandable
789+
}
787790
};
788791
}
789792

src/components/organisms/navigation-bar/navigation-bar.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,11 @@ describe('ForgeNavigationBar', () => {
526526

527527
const aiState = el.aiState;
528528

529-
expect(aiState.itemCount).to.be.a('number');
530-
expect(aiState.hasUser).to.be.a('boolean');
531-
expect(aiState.position).to.equal('static');
532-
expect(aiState.showSearch).to.be.false;
533-
expect(aiState.showThemeToggle).to.be.false;
529+
expect(aiState.state.itemCount).to.be.a('number');
530+
expect(aiState.state.hasUser).to.be.a('boolean');
531+
expect(aiState.state.position).to.equal('static');
532+
expect(aiState.state.showSearch).to.be.false;
533+
expect(aiState.state.showThemeToggle).to.be.false;
534534
});
535535

536536
it('should explain state in natural language', async () => {

src/components/organisms/navigation-bar/navigation-bar.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LitElement, html, css } from 'lit';
1+
import { LitElement, html, css, TemplateResult } from 'lit';
22
import { customElement, property, state } from 'lit/decorators.js';
33
import { classMap } from 'lit/directives/class-map.js';
44
import { BaseElement } from '../../../core/BaseElement';
@@ -312,17 +312,20 @@ export class ForgeNavigationBar extends BaseElement {
312312
override get aiState(): AIComponentState {
313313
return {
314314
...super.aiState,
315-
activeRoute: this.activeRoute,
316-
mobileOpen: this.mobileOpen,
317-
itemCount: this.items.length,
318-
position: this.position,
319-
hasUser: !!this.userName,
320-
showSearch: this.showSearch,
321-
showThemeToggle: this.showThemeToggle
315+
state: {
316+
...super.aiState.state,
317+
activeRoute: this.activeRoute,
318+
mobileOpen: this.mobileOpen,
319+
itemCount: this.items.length,
320+
position: this.position,
321+
hasUser: !!this.userName,
322+
showSearch: this.showSearch,
323+
showThemeToggle: this.showThemeToggle
324+
}
322325
};
323326
}
324327

325-
override explainState(): AIComponentStateExplanation {
328+
override explainState(): AIStateExplanation {
326329
const parts = ['Navigation bar'];
327330

328331
if (this.title) {
@@ -394,7 +397,13 @@ export class ForgeNavigationBar extends BaseElement {
394397
name: 'navigateTo',
395398
description: `Navigate to ${item.label}`,
396399
available: true,
397-
params: [item.href]
400+
parameters: [{
401+
name: 'href',
402+
type: 'url',
403+
required: true,
404+
defaultValue: item.href,
405+
description: 'URL to navigate to'
406+
}]
398407
});
399408
}
400409
});
@@ -625,7 +634,7 @@ export class ForgeNavigationBar extends BaseElement {
625634
`;
626635
}
627636

628-
private renderDrawerItem(item: NavItem) {
637+
private renderDrawerItem(item: NavItem): TemplateResult {
629638
return html`
630639
<li class="drawer-item">
631640
<a
@@ -642,7 +651,7 @@ export class ForgeNavigationBar extends BaseElement {
642651
643652
${item.items && item.items.length > 0 ? html`
644653
<ul class="drawer-menu" style="padding-left: var(--forge-spacing-lg, 24px);">
645-
${item.items.map(subItem => this.renderDrawerItem(subItem))}
654+
${item.items.map((subItem: NavItem) => this.renderDrawerItem(subItem))}
646655
</ul>
647656
` : ''}
648657
</li>

src/components/organisms/pagination/pagination.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ describe('ForgePagination', () => {
203203

204204
const aiState = el.aiState;
205205

206-
expect(aiState.currentPage).to.equal(3);
207-
expect(aiState.totalPages).to.equal(10);
208-
expect(aiState.pageSize).to.equal(25);
209-
expect(aiState.totalItems).to.equal(250);
210-
expect(aiState.mode).to.equal('pagination');
206+
expect(aiState.state.currentPage).to.equal(3);
207+
expect(aiState.state.totalPages).to.equal(10);
208+
expect(aiState.state.pageSize).to.equal(25);
209+
expect(aiState.state.totalItems).to.equal(250);
210+
expect(aiState.state.mode).to.equal('pagination');
211211
});
212212

213213
it('should explain state in natural language', async () => {
@@ -222,10 +222,10 @@ describe('ForgePagination', () => {
222222

223223
const explanation = el.explainState();
224224

225-
expect(explanation).to.include('Pagination component');
226-
expect(explanation).to.include('page 3 of 10');
227-
expect(explanation).to.include('25 items per page');
228-
expect(explanation).to.include('showing items 51-75 of 250');
225+
expect(explanation.stateDescription).to.include('Pagination component');
226+
expect(explanation.stateDescription).to.include('page 3 of 10');
227+
expect(explanation.stateDescription).to.include('25 items per page');
228+
expect(explanation.stateDescription).to.include('showing items 51-75 of 250');
229229
});
230230

231231
it('should provide possible actions', async () => {

src/components/organisms/pagination/pagination.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { LitElement, html, css } from 'lit';
22
import { customElement, property, state } from 'lit/decorators.js';
33
import { classMap } from 'lit/directives/class-map.js';
44
import { BaseElement } from '../../../core/BaseElement';
5-
import type { AIComponentState, AIAction } from '../../../core/ai-metadata.types';
5+
import type { AIComponentState, AIAction, AIStateExplanation } from '../../../core/ai-metadata.types';
66
import '../../atoms/button/button';
77
import '../../atoms/select/select';
88
import '../../atoms/input/input';
@@ -323,17 +323,20 @@ export class ForgePagination extends BaseElement {
323323
override get aiState(): AIComponentState {
324324
return {
325325
...super.aiState,
326-
currentPage: this.currentPage,
327-
totalPages: this.totalPages,
328-
pageSize: this.pageSize,
329-
totalItems: this.totalItems,
330-
mode: this.mode,
331-
loading: this.loading,
332-
hasMore: this.hasMore
326+
state: {
327+
...super.aiState.state,
328+
currentPage: this.currentPage,
329+
totalPages: this.totalPages,
330+
pageSize: this.pageSize,
331+
totalItems: this.totalItems,
332+
mode: this.mode,
333+
loading: this.loading,
334+
hasMore: this.hasMore
335+
}
333336
};
334337
}
335338

336-
override explainState(): string {
339+
override explainState(): AIStateExplanation {
337340
const parts = ['Pagination component'];
338341

339342
if (this.mode === 'pagination') {
@@ -355,7 +358,11 @@ export class ForgePagination extends BaseElement {
355358

356359
if (this.loading) parts.push('loading');
357360

358-
return parts.join(', ');
361+
return {
362+
currentState: this.loading ? 'loading' : 'ready',
363+
possibleStates: ['loading', 'ready'],
364+
stateDescription: parts.join(', ')
365+
};
359366
}
360367

361368
override getPossibleActions(): AIAction[] {
@@ -395,7 +402,12 @@ export class ForgePagination extends BaseElement {
395402
name: 'jumpToPage',
396403
description: 'Jump to specific page',
397404
available: true,
398-
params: ['pageNumber']
405+
parameters: [{
406+
name: 'pageNumber',
407+
type: 'number',
408+
required: true,
409+
description: 'Page number to navigate to'
410+
}]
399411
});
400412
}
401413

@@ -404,7 +416,12 @@ export class ForgePagination extends BaseElement {
404416
name: 'changePageSize',
405417
description: 'Change items per page',
406418
available: true,
407-
params: ['size']
419+
parameters: [{
420+
name: 'size',
421+
type: 'number',
422+
required: true,
423+
description: 'Number of items per page'
424+
}]
408425
});
409426
}
410427
} else if (this.mode === 'load-more' && this.hasMore && !this.loading) {

src/components/organisms/tabs/tabs.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,11 @@ describe('ForgeTabs', () => {
165165

166166
const aiState = el.aiState;
167167

168-
expect(aiState.activeTab).to.equal('tab2');
169-
expect(aiState.tabCount).to.equal(4);
170-
expect(aiState.orientation).to.equal('horizontal');
171-
expect(aiState.hasCloseable).to.be.true;
172-
expect(aiState.hasDisabled).to.be.true;
168+
expect(aiState.state.activeTab).to.equal('tab2');
169+
expect(aiState.state.tabCount).to.equal(4);
170+
expect(aiState.state.orientation).to.equal('horizontal');
171+
expect(aiState.state.hasCloseable).to.be.true;
172+
expect(aiState.state.hasDisabled).to.be.true;
173173
});
174174

175175
it('should explain state in natural language', async () => {

src/components/organisms/tabs/tabs.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,15 @@ export class ForgeTabs extends BaseElement {
437437
override get aiState(): AIComponentState {
438438
return {
439439
...super.aiState,
440-
activeTab: this.activeTab,
441-
tabCount: this.tabs.length,
442-
orientation: this.orientation,
443-
reorderable: this.reorderable,
444-
hasCloseable: this.tabs.some(t => t.closeable),
445-
hasDisabled: this.tabs.some(t => t.disabled)
440+
state: {
441+
...super.aiState.state,
442+
activeTab: this.activeTab,
443+
tabCount: this.tabs.length,
444+
orientation: this.orientation,
445+
reorderable: this.reorderable,
446+
hasCloseable: this.tabs.some(t => t.closeable),
447+
hasDisabled: this.tabs.some(t => t.disabled)
448+
}
446449
};
447450
}
448451

@@ -475,7 +478,13 @@ export class ForgeTabs extends BaseElement {
475478
name: 'selectTab',
476479
description: 'Switch to ' + tab.label + ' tab',
477480
available: true,
478-
params: [tab.id]
481+
parameters: [{
482+
name: 'tabId',
483+
type: 'text',
484+
required: true,
485+
defaultValue: tab.id,
486+
description: 'ID of the tab to interact with'
487+
}]
479488
});
480489
}
481490

@@ -484,7 +493,13 @@ export class ForgeTabs extends BaseElement {
484493
name: 'closeTab',
485494
description: 'Close ' + tab.label + ' tab',
486495
available: true,
487-
params: [tab.id]
496+
parameters: [{
497+
name: 'tabId',
498+
type: 'text',
499+
required: true,
500+
defaultValue: tab.id,
501+
description: 'ID of the tab to interact with'
502+
}]
488503
});
489504
}
490505
});

0 commit comments

Comments
 (0)