|
| 1 | +import { TestBed, ComponentFixture } from "@angular/core/testing"; |
| 2 | +import { Component, Input, DebugElement } from "@angular/core"; |
| 3 | +import { By } from "@angular/platform-browser"; |
| 4 | + |
| 5 | +import { Link } from "./link.directive"; |
| 6 | + |
| 7 | +describe("Link", () => { |
| 8 | + it("should create a Link", () => { |
| 9 | + TestBed.configureTestingModule({ |
| 10 | + declarations: [TestLinkComponent, Link] |
| 11 | + }); |
| 12 | + |
| 13 | + let fixture: ComponentFixture<TestLinkComponent> = TestBed.createComponent(TestLinkComponent); |
| 14 | + let component: TestLinkComponent = fixture.componentInstance; |
| 15 | + fixture.detectChanges(); |
| 16 | + |
| 17 | + expect(component).toBeTruthy(); |
| 18 | + const directiveEl = fixture.debugElement.query(By.directive(Link)); |
| 19 | + expect(directiveEl).not.toBeNull(); |
| 20 | + expect(directiveEl.attributes["aria-disabled"]).toBe(null); |
| 21 | + expect(directiveEl.attributes["tabindex"]).toBe(null); |
| 22 | + expect(directiveEl.attributes["href"]).toBe("https://angular.carbondesignsystem.com/"); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should create a disabled link", () => { |
| 26 | + TestBed.configureTestingModule({ |
| 27 | + declarations: [TestDisabledLinkComponent, Link] |
| 28 | + }); |
| 29 | + |
| 30 | + let fixture: ComponentFixture<TestDisabledLinkComponent> = TestBed.createComponent(TestDisabledLinkComponent); |
| 31 | + let component: TestDisabledLinkComponent = fixture.componentInstance; |
| 32 | + fixture.detectChanges(); |
| 33 | + |
| 34 | + const directiveEl = fixture.debugElement.query(By.directive(Link)); |
| 35 | + expect(directiveEl.attributes["aria-disabled"]).toBe("true"); |
| 36 | + expect(directiveEl.attributes["tabindex"]).toBe("-1"); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +@Component({ |
| 41 | + template: `<a href="https://angular.carbondesignsystem.com/" ibmLink>link</a>` |
| 42 | +}) |
| 43 | +class TestLinkComponent { |
| 44 | +} |
| 45 | + |
| 46 | +@Component({ |
| 47 | + template: `<a href="https://angular.carbondesignsystem.com/" [disabled]="1+1===2" ibmLink>link</a>` |
| 48 | +}) |
| 49 | +class TestDisabledLinkComponent { |
| 50 | +} |
0 commit comments