-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eede495
commit 465e119
Showing
5 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...sign-system/button-toggle/src/lib/button-toggle-size/button-toggle-size.directive.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: `<div hraButtonToggleSize="large" data-testid="dir"></div>`, | ||
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)'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 37 additions & 13 deletions
50
libs/design-system/expansion-panel/src/lib/expansion-panel.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ExpansionPanelComponent>; | ||
async function setup(options?: RenderComponentOptions<ExpansionPanelComponent>) { | ||
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters