diff --git a/libs/design-system/button-toggle/src/lib/button-toggle-size/button-toggle-size.directive.spec.ts b/libs/design-system/button-toggle/src/lib/button-toggle-size/button-toggle-size.directive.spec.ts new file mode 100644 index 000000000..8c50ea6da --- /dev/null +++ b/libs/design-system/button-toggle/src/lib/button-toggle-size/button-toggle-size.directive.spec.ts @@ -0,0 +1,20 @@ +import { Component } from '@angular/core'; +import { render, screen } from '@testing-library/angular'; +import { ToggleButtonSizeDirective } from './button-toggle-size.directive'; + +describe('ButtonToggleSizeDirective', () => { + it('should apply the styles based on the directive', async () => { + @Component({ + template: `
`, + imports: [ToggleButtonSizeDirective], + standalone: true, + }) + class ButtonToggleComponent {} + + await render(ButtonToggleComponent); + + const directive = screen.getByTestId('dir'); + expect(directive.getAttribute('hrabuttontogglesize')).toBe('large'); + expect(directive.style.font).toBe('var(--sys-label-large)'); + }); +}); diff --git a/libs/design-system/button-toggle/src/lib/button-toggle-size/button-toggle-size.directive.ts b/libs/design-system/button-toggle/src/lib/button-toggle-size/button-toggle-size.directive.ts index b2597f08e..fb34ec3ca 100644 --- a/libs/design-system/button-toggle/src/lib/button-toggle-size/button-toggle-size.directive.ts +++ b/libs/design-system/button-toggle/src/lib/button-toggle-size/button-toggle-size.directive.ts @@ -43,9 +43,6 @@ export class ToggleButtonSizeDirective { /** Size of icon button to use */ readonly size = input.required({ alias: 'hraButtonToggleSize' }); - /** Gets size of button in rem */ - protected readonly buttonSize = computed(() => BUTTON_CONFIG[this.size()]); - /** Gets the font variable for the current button size */ protected readonly fontVar = computed(() => `var(${BUTTON_CONFIG[this.size()].font})`); diff --git a/libs/design-system/expansion-panel/src/lib/expansion-panel.component.html b/libs/design-system/expansion-panel/src/lib/expansion-panel.component.html index 2bf385fa5..473b82f36 100644 --- a/libs/design-system/expansion-panel/src/lib/expansion-panel.component.html +++ b/libs/design-system/expansion-panel/src/lib/expansion-panel.component.html @@ -4,11 +4,12 @@ tabindex="0" [attr.aria-expanded]="accordionItem.expanded" [attr.aria-controls]="bodyId" + [expanded]="expanded" >
@if (!disabled()) { - @@ -35,6 +36,7 @@ [@bodyExpansion]="accordionItem.expanded ? 'expanded' : 'collapsed'" (@bodyExpansion.start)="animationStart($event)" (@bodyExpansion.done)="animationDone($event)" + data-testid="body" >
diff --git a/libs/design-system/expansion-panel/src/lib/expansion-panel.component.spec.ts b/libs/design-system/expansion-panel/src/lib/expansion-panel.component.spec.ts index 49d99307d..bcc14d4aa 100644 --- a/libs/design-system/expansion-panel/src/lib/expansion-panel.component.spec.ts +++ b/libs/design-system/expansion-panel/src/lib/expansion-panel.component.spec.ts @@ -1,21 +1,45 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { AnimationDriver } from '@angular/animations/browser'; +import { MockAnimationDriver, MockAnimationPlayer } from '@angular/animations/browser/testing'; +import { provideDesignSystem } from '@hra-ui/design-system'; +import { render, RenderComponentOptions, screen } from '@testing-library/angular'; +import { userEvent } from '@testing-library/user-event'; import { ExpansionPanelComponent } from './expansion-panel.component'; describe('ExpansionPanelComponent', () => { - let component: ExpansionPanelComponent; - let fixture: ComponentFixture; + async function setup(options?: RenderComponentOptions) { + return render(ExpansionPanelComponent, { + ...options, + inputs: { + title: 'Test Title', + ...options?.inputs, + }, + providers: [ + provideDesignSystem(), + { + provide: AnimationDriver, + useClass: MockAnimationDriver, + }, + ], + }); + } - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [ExpansionPanelComponent], - }).compileComponents(); - - fixture = TestBed.createComponent(ExpansionPanelComponent); - component = fixture.componentInstance; - fixture.detectChanges(); + it('should render the expansion panel', async () => { + await setup(); + const title = screen.getByText('Test Title'); + expect(title).toBeInTheDocument(); }); - it('should create', () => { - expect(component).toBeTruthy(); + it('should set inert attribute on body element when animation starts', async () => { + await setup(); + + const button = screen.getByTestId('toggle'); + await userEvent.click(button); + + const player = MockAnimationDriver.log.pop() as MockAnimationPlayer; + const element = player.element as HTMLElement; + + expect(element).toHaveAttribute('inert'); + player.finish(); + expect(element).not.toHaveAttribute('inert'); }); }); diff --git a/libs/design-system/expansion-panel/src/lib/expansion-panel.component.ts b/libs/design-system/expansion-panel/src/lib/expansion-panel.component.ts index 3fc88d07e..d124a796b 100644 --- a/libs/design-system/expansion-panel/src/lib/expansion-panel.component.ts +++ b/libs/design-system/expansion-panel/src/lib/expansion-panel.component.ts @@ -52,6 +52,10 @@ export class ExpansionPanelHeaderContentComponent {} export class ExpansionPanelComponent { /** Title of the expansion panel */ readonly title = input.required(); + + /** Flag to check if the body is expanded */ + readonly expanded = input(true, { transform: booleanAttribute }); + /** Flag to denote panel as disabled */ readonly disabled = input(false, { transform: booleanAttribute });