|
| 1 | +import { ComponentFixture, TestBed, tick, fakeAsync } from "@angular/core/testing"; |
| 2 | +import { GoabxWorkSideMenu } from "./work-side-menu"; |
| 3 | +import { Component } from "@angular/core"; |
| 4 | +import { By } from "@angular/platform-browser"; |
| 5 | + |
| 6 | +@Component({ |
| 7 | + standalone: true, |
| 8 | + imports: [GoabxWorkSideMenu], |
| 9 | + template: ` |
| 10 | + <goabx-work-side-menu |
| 11 | + [open]="open" |
| 12 | + [heading]="heading" |
| 13 | + [url]="url" |
| 14 | + [userName]="userName" |
| 15 | + [userSecondaryText]="userSecondaryText" |
| 16 | + [testId]="testId" |
| 17 | + [primaryContent]="primaryTemplate" |
| 18 | + [secondaryContent]="secondaryTemplate" |
| 19 | + [accountContent]="accountTemplate" |
| 20 | + > |
| 21 | + </goabx-work-side-menu> |
| 22 | + <ng-template #primaryTemplate> |
| 23 | + <div>Primary content</div> |
| 24 | + </ng-template> |
| 25 | + <ng-template #secondaryTemplate> |
| 26 | + <div>Secondary content</div> |
| 27 | + </ng-template> |
| 28 | + <ng-template #accountTemplate> |
| 29 | + <div>Account content</div> |
| 30 | + </ng-template> |
| 31 | + `, |
| 32 | +}) |
| 33 | +class TestWorkSideMenuComponent { |
| 34 | + open = true; |
| 35 | + heading = "Test heading"; |
| 36 | + url = "/test"; |
| 37 | + userName = "Test User"; |
| 38 | + userSecondaryText = "test@example.com"; |
| 39 | + testId = "test-id"; |
| 40 | +} |
| 41 | +describe("GoabxBWorkSideMenu", () => { |
| 42 | + let fixture: ComponentFixture<TestWorkSideMenuComponent>; |
| 43 | + let component: TestWorkSideMenuComponent; |
| 44 | + |
| 45 | + beforeEach(fakeAsync(() => { |
| 46 | + TestBed.configureTestingModule({ |
| 47 | + imports: [TestWorkSideMenuComponent], |
| 48 | + }).compileComponents(); |
| 49 | + |
| 50 | + fixture = TestBed.createComponent(TestWorkSideMenuComponent); |
| 51 | + component = fixture.componentInstance; |
| 52 | + fixture.detectChanges(); |
| 53 | + tick(); // Wait for setTimeout in ngOnInit |
| 54 | + fixture.detectChanges(); |
| 55 | + })); |
| 56 | + |
| 57 | + it("should render and set the props correctly", () => { |
| 58 | + const menuElement = fixture.debugElement.query( |
| 59 | + By.css("goa-work-side-menu"), |
| 60 | + ).nativeElement; |
| 61 | + expect(menuElement.getAttribute("heading")).toBe("Test heading"); |
| 62 | + expect(menuElement.getAttribute("url")).toBe("/test"); |
| 63 | + expect(menuElement.getAttribute("user-name")).toBe("Test User"); |
| 64 | + expect(menuElement.getAttribute("user-secondary-text")).toBe("test@example.com"); |
| 65 | + expect(menuElement.getAttribute("testId")).toBe("test-id"); |
| 66 | + }); |
| 67 | +}); |
0 commit comments