|
| 1 | +import { Component } from "@angular/core"; |
| 2 | +import { ComponentFixture, TestBed } from "@angular/core/testing"; |
| 3 | +import { By } from "@angular/platform-browser"; |
| 4 | + |
| 5 | +import { I18nModule } from "../i18n/i18n.module"; |
| 6 | +import { Header } from "./header.component"; |
| 7 | +import { Hamburger } from "./ui-shell.module"; |
| 8 | + |
| 9 | +/** |
| 10 | + * Testing component for projecting an ibm-hamburger component |
| 11 | + * inside of an ibm-header component. |
| 12 | + * |
| 13 | + * @class HamburgerTest |
| 14 | + */ |
| 15 | +@Component({ |
| 16 | + selector: "ibm-hamburger-test", |
| 17 | + template: ` |
| 18 | + <ibm-header> |
| 19 | + <ibm-hamburger></ibm-hamburger> |
| 20 | + </ibm-header> |
| 21 | + ` |
| 22 | +}) |
| 23 | +class HamburgerTest { } |
| 24 | + |
| 25 | +describe("UI Shell Header", () => { |
| 26 | + let component: Header; |
| 27 | + let fixture: ComponentFixture<Header>; |
| 28 | + let element: HTMLElement; |
| 29 | + |
| 30 | + beforeEach(() => { |
| 31 | + TestBed.configureTestingModule({ |
| 32 | + declarations: [Hamburger, HamburgerTest, Header], |
| 33 | + imports: [I18nModule], |
| 34 | + providers: [] |
| 35 | + }); |
| 36 | + |
| 37 | + fixture = TestBed.createComponent(Header); |
| 38 | + component = fixture.componentInstance; |
| 39 | + element = fixture.debugElement.query(By.css(".bx--header")).nativeElement; |
| 40 | + fixture.detectChanges(); |
| 41 | + }); |
| 42 | + |
| 43 | + it("should work", () => { |
| 44 | + expect(component instanceof Header).toBe(true); |
| 45 | + }); |
| 46 | + |
| 47 | + it("should have a default brand of 'IBM'", () => { |
| 48 | + const brandElement = element.querySelector(".bx--header__name--prefix"); |
| 49 | + expect(brandElement).toBeDefined(); |
| 50 | + expect(brandElement.textContent.trim()).toEqual("IBM"); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should be able to set a custom brand", () => { |
| 54 | + const brand = "Foo Brand"; |
| 55 | + component.brand = brand; |
| 56 | + fixture.detectChanges(); |
| 57 | + |
| 58 | + const brandElement = element.querySelector(".bx--header__name--prefix"); |
| 59 | + expect(brandElement).toBeDefined(); |
| 60 | + expect(brandElement.textContent.trim()).toEqual(brand); |
| 61 | + }); |
| 62 | + |
| 63 | + it("should be able to set a custom name", () => { |
| 64 | + const name = "Foo Name"; |
| 65 | + component.name = name; |
| 66 | + fixture.detectChanges(); |
| 67 | + |
| 68 | + const nameElement = element.querySelector(".bx--header__name"); |
| 69 | + expect(nameElement).toBeDefined(); |
| 70 | + expect(nameElement.textContent).toContain(name); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should project a hamburger component", () => { |
| 74 | + const headerWithHamburger = TestBed.createComponent(HamburgerTest); |
| 75 | + const element = headerWithHamburger.nativeElement; |
| 76 | + |
| 77 | + expect(element.querySelector("header > ibm-hamburger")).toBeDefined(); |
| 78 | + }); |
| 79 | +}); |
0 commit comments