|
| 1 | +import { TestBed } from "@angular/core/testing"; |
| 2 | + |
| 3 | +import { StaticIconModule } from "./../icon/static-icon.module"; |
| 4 | + |
| 5 | +import { Notification, NotificationService } from "./notification.module"; |
| 6 | +import { I18nModule } from "../i18n/i18n.module"; |
| 7 | + |
| 8 | + |
| 9 | +describe("Notification", () => { |
| 10 | + beforeEach(() => { |
| 11 | + TestBed.configureTestingModule({ |
| 12 | + declarations: [Notification], |
| 13 | + providers: [NotificationService], |
| 14 | + imports: [ |
| 15 | + StaticIconModule, |
| 16 | + I18nModule |
| 17 | + ] |
| 18 | + }); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should work", () => { |
| 22 | + const fixture = TestBed.createComponent(Notification); |
| 23 | + expect(fixture.componentInstance instanceof Notification).toBe(true); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should render info notification", () => { |
| 27 | + const fixture = TestBed.createComponent(Notification); |
| 28 | + fixture.componentInstance.notificationObj = { |
| 29 | + type: "info", |
| 30 | + title: "sample", |
| 31 | + message: "sample message" |
| 32 | + }; |
| 33 | + fixture.detectChanges(); |
| 34 | + |
| 35 | + expect(fixture.nativeElement.classList.contains("bx--inline-notification--info")).toBeTruthy(); |
| 36 | + }); |
| 37 | + |
| 38 | + it("should render danger notification", () => { |
| 39 | + const fixture = TestBed.createComponent(Notification); |
| 40 | + fixture.componentInstance.notificationObj = { |
| 41 | + type: "error", |
| 42 | + title: "sample", |
| 43 | + message: "sample message" |
| 44 | + }; |
| 45 | + fixture.detectChanges(); |
| 46 | + |
| 47 | + expect(fixture.nativeElement.classList.contains("bx--inline-notification--error")).toBeTruthy(); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should render info warning notification", () => { |
| 51 | + const fixture = TestBed.createComponent(Notification); |
| 52 | + fixture.componentInstance.notificationObj = { |
| 53 | + type: "warning", |
| 54 | + title: "sample", |
| 55 | + message: "sample message" |
| 56 | + }; |
| 57 | + fixture.detectChanges(); |
| 58 | + |
| 59 | + expect(fixture.nativeElement.classList.contains("bx--inline-notification--warning")).toBeTruthy(); |
| 60 | + }); |
| 61 | + |
| 62 | + it("should render info success notification", () => { |
| 63 | + const fixture = TestBed.createComponent(Notification); |
| 64 | + fixture.componentInstance.notificationObj = { |
| 65 | + type: "success", |
| 66 | + title: "sample", |
| 67 | + message: "sample message" |
| 68 | + }; |
| 69 | + fixture.detectChanges(); |
| 70 | + |
| 71 | + expect(fixture.nativeElement.classList.contains("bx--inline-notification--success")).toBeTruthy(); |
| 72 | + }); |
| 73 | + |
| 74 | + it("should display correct message", () => { |
| 75 | + const fixture = TestBed.createComponent(Notification); |
| 76 | + fixture.componentInstance.notificationObj = { |
| 77 | + type: "success", |
| 78 | + title: "sample", |
| 79 | + message: "sample message" |
| 80 | + }; |
| 81 | + fixture.detectChanges(); |
| 82 | + |
| 83 | + let p = fixture.nativeElement.querySelector(".bx--inline-notification__subtitle"); |
| 84 | + |
| 85 | + expect(p.innerHTML.trim()).toEqual("sample message"); |
| 86 | + }); |
| 87 | + |
| 88 | + it("should emit change when close button is clicked", () => { |
| 89 | + const fixture = TestBed.createComponent(Notification); |
| 90 | + fixture.componentInstance.notificationObj = { |
| 91 | + type: "success", |
| 92 | + title: "sample", |
| 93 | + message: "sample message" |
| 94 | + }; |
| 95 | + fixture.detectChanges(); |
| 96 | + |
| 97 | + spyOn(fixture.componentInstance.close, "emit"); |
| 98 | + |
| 99 | + let button = fixture.nativeElement.querySelector(".bx--inline-notification__close-button"); |
| 100 | + |
| 101 | + button.click(); |
| 102 | + expect(fixture.componentInstance.close.emit).toHaveBeenCalled(); |
| 103 | + }); |
| 104 | + |
| 105 | + it("should emit change when notification is closed programmatically", () => { |
| 106 | + const fixture = TestBed.createComponent(Notification); |
| 107 | + fixture.componentInstance.notificationObj = { |
| 108 | + type: "info", |
| 109 | + title: "sample", |
| 110 | + message: "sample message" |
| 111 | + }; |
| 112 | + fixture.detectChanges(); |
| 113 | + |
| 114 | + fixture.componentInstance.destroy(); |
| 115 | + |
| 116 | + expect(fixture.componentInstance); |
| 117 | + }); |
| 118 | +}); |
0 commit comments