|
| 1 | +import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; |
| 2 | +import { provideLocationMocks } from '@angular/common/testing'; |
| 3 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 4 | +import { provideRouter } from '@angular/router'; |
| 5 | +import { expectAsync } from '@skyux-sdk/testing'; |
| 6 | +import { SkyActionHubHarness } from '@skyux/pages/testing'; |
| 7 | + |
| 8 | +import { Hub } from './hub'; |
| 9 | +import { MockData } from '../services/data/mock-data'; |
| 10 | +import { Data } from '../services/data/data'; |
| 11 | + |
| 12 | +describe('Hub', () => { |
| 13 | + let component: Hub; |
| 14 | + let fixture: ComponentFixture<Hub>; |
| 15 | + let harness: SkyActionHubHarness; |
| 16 | + |
| 17 | + beforeEach(async () => { |
| 18 | + TestBed.configureTestingModule({ |
| 19 | + imports: [Hub], |
| 20 | + providers: [ |
| 21 | + provideLocationMocks(), |
| 22 | + provideRouter([]), |
| 23 | + MockData, |
| 24 | + { |
| 25 | + provide: Data, |
| 26 | + useExisting: MockData, |
| 27 | + }, |
| 28 | + ], |
| 29 | + }); |
| 30 | + fixture = TestBed.createComponent(Hub); |
| 31 | + component = fixture.componentInstance; |
| 32 | + fixture.detectChanges(); |
| 33 | + harness = await TestbedHarnessEnvironment.loader(fixture).getHarness( |
| 34 | + SkyActionHubHarness.with({ |
| 35 | + dataSkyId: 'action-hub', |
| 36 | + }), |
| 37 | + ); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should show a count of animals needing attention', async () => { |
| 41 | + expect(component).toBeTruthy(); |
| 42 | + const dataService = TestBed.inject(Data); |
| 43 | + dataService.load([]); |
| 44 | + fixture.detectChanges(); |
| 45 | + await fixture.whenStable(); |
| 46 | + const items = await harness.getNeedsAttentionItems(); |
| 47 | + expect(items).toHaveSize(1); |
| 48 | + expect(await items[0].getText()).toEqual('0 animals need attention'); |
| 49 | + dataService.load([ |
| 50 | + { |
| 51 | + bio: 'bio', |
| 52 | + createdAt: new Date(), |
| 53 | + updatedAt: new Date(), |
| 54 | + breed: 'breed', |
| 55 | + gender: '', |
| 56 | + images: [], |
| 57 | + name: 'name1', |
| 58 | + id: 'id1', |
| 59 | + needsAttention: true, |
| 60 | + }, |
| 61 | + { |
| 62 | + bio: 'bio', |
| 63 | + createdAt: new Date(), |
| 64 | + updatedAt: new Date(), |
| 65 | + breed: 'breed', |
| 66 | + gender: '', |
| 67 | + images: [], |
| 68 | + name: 'name2', |
| 69 | + id: 'id2', |
| 70 | + needsAttention: false, |
| 71 | + }, |
| 72 | + ]); |
| 73 | + fixture.detectChanges(); |
| 74 | + await fixture.whenStable(); |
| 75 | + expect(await (await harness.getNeedsAttentionItems())[0].getText()).toEqual( |
| 76 | + '1 animal needs attention', |
| 77 | + ); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should be accessible', async () => { |
| 81 | + await fixture.whenStable(); |
| 82 | + const element = fixture.nativeElement as HTMLElement; |
| 83 | + await expectAsync(element).toBeAccessible(); |
| 84 | + }); |
| 85 | +}); |
0 commit comments