|
| 1 | +import { Component, Type } from "@angular/core"; |
| 2 | +import { ComponentFixture, TestBed } from "@angular/core/testing"; |
| 3 | +import { FormsModule } from "@angular/forms"; |
| 4 | +import { By } from "@angular/platform-browser"; |
| 5 | +import { I18nTestingModule } from "@batch-flask/core/testing"; |
| 6 | +import { ButtonsModule } from "../buttons"; |
| 7 | +import { DropdownComponent } from "./dropdown.component"; |
| 8 | + |
| 9 | +describe("DropdownComponent", () => { |
| 10 | + let fixture: ComponentFixture<Component>; |
| 11 | + |
| 12 | + function createComponent(comp: Type<Component>) { |
| 13 | + TestBed.configureTestingModule({ |
| 14 | + imports: [FormsModule, ButtonsModule, I18nTestingModule], |
| 15 | + declarations: [DropdownComponent, comp], |
| 16 | + }); |
| 17 | + fixture = TestBed.createComponent(comp); |
| 18 | + fixture.detectChanges(); |
| 19 | + } |
| 20 | + |
| 21 | + function $(selector) { |
| 22 | + return fixture.debugElement.query(By.css("bl-dropdown")) |
| 23 | + .nativeElement.querySelector(selector); |
| 24 | + } |
| 25 | + |
| 26 | + it("uses a default title", () => { |
| 27 | + createComponent(TestComponent); |
| 28 | + |
| 29 | + expect($(".dropdown-btn-container").getAttribute("title")) |
| 30 | + .toEqual("dropdown.button-title"); |
| 31 | + }); |
| 32 | + it("uses a host button title", () => { |
| 33 | + createComponent(TestComponentWithButton); |
| 34 | + |
| 35 | + expect($(".dropdown-btn-container").getAttribute("title")) |
| 36 | + .toEqual("Host title"); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +@Component({ template: `<bl-dropdown [title]="title"></bl-dropdown>` }) |
| 41 | +class TestComponent { } |
| 42 | + |
| 43 | +@Component({ |
| 44 | + template: `<bl-dropdown [title]="title"> |
| 45 | + <div bl-dropdown-btn button-title="Host title">Button</div> |
| 46 | + </bl-dropdown>` |
| 47 | +}) |
| 48 | +class TestComponentWithButton { } |
0 commit comments