|
| 1 | +import { fakeAsync, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | +import { ThyActionMenuModule } from '../action-menu.module'; |
| 3 | +import { NgModule, Component, DebugElement } from '@angular/core'; |
| 4 | +import { By } from '@angular/platform-browser'; |
| 5 | +import { ThyActionMenuComponent } from '../action-menu.component'; |
| 6 | + |
| 7 | +describe('ThyActionMenu', () => { |
| 8 | + let fixture: ComponentFixture<ThyDemoActionMenuComponent>; |
| 9 | + let testComponent: ThyDemoActionMenuComponent; |
| 10 | + let actionMenuComponent: DebugElement; |
| 11 | + let actionMenuItems: DebugElement[]; |
| 12 | + |
| 13 | + beforeEach(fakeAsync(() => { |
| 14 | + TestBed.configureTestingModule({ |
| 15 | + imports: [ThyActionMenuModule, ActionMenuTestModule] |
| 16 | + }); |
| 17 | + TestBed.compileComponents(); |
| 18 | + })); |
| 19 | + |
| 20 | + beforeEach(() => { |
| 21 | + fixture = TestBed.createComponent(ThyDemoActionMenuComponent); |
| 22 | + testComponent = fixture.debugElement.componentInstance; |
| 23 | + actionMenuComponent = fixture.debugElement.query(By.directive(ThyActionMenuComponent)); |
| 24 | + actionMenuItems = actionMenuComponent.queryAll(By.all()); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should create', () => { |
| 28 | + expect(actionMenuComponent).toBeTruthy(); |
| 29 | + expect(actionMenuItems).toBeTruthy(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should have correct class when type is danger', () => { |
| 33 | + testComponent.type = `danger`; |
| 34 | + fixture.detectChanges(); |
| 35 | + expect(actionMenuItems.every(item => item.nativeElement.classList.contains('action-menu-item--danger'))).toBe( |
| 36 | + true |
| 37 | + ); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should have correct class when type is success', () => { |
| 41 | + testComponent.type = `success`; |
| 42 | + fixture.detectChanges(); |
| 43 | + expect(actionMenuItems.every(item => item.nativeElement.classList.contains('action-menu-item--success'))).toBe( |
| 44 | + true |
| 45 | + ); |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +@Component({ |
| 50 | + selector: 'thy-demo-action-menu', |
| 51 | + template: ` |
| 52 | + <thy-action-menu> |
| 53 | + <a thyActionMenuItem [thyType]="type" href="javascript:;"> </a> |
| 54 | + <a thyActionMenuItem [thyType]="type" href="javascript:;"> </a> |
| 55 | + </thy-action-menu> |
| 56 | + ` |
| 57 | +}) |
| 58 | +class ThyDemoActionMenuComponent { |
| 59 | + type = ``; |
| 60 | +} |
| 61 | + |
| 62 | +@NgModule({ |
| 63 | + imports: [ThyActionMenuModule], |
| 64 | + declarations: [ThyDemoActionMenuComponent], |
| 65 | + exports: [ThyDemoActionMenuComponent] |
| 66 | +}) |
| 67 | +export class ActionMenuTestModule {} |
0 commit comments