import { ComponentFixture, TestBed } from '@angular/core/testing'; import { InfoBoxComponent } from './info-box.component'; import {MatIconTestingModule} from '@angular/material/icon/testing'; import {MatIconModule} from '@angular/material/icon'; import {By} from '@angular/platform-browser'; import {DataCardService} from '../api/data-card.service'; import SpyObj = jasmine.SpyObj; import createSpyObj = jasmine.createSpyObj; import {of} from 'rxjs/internal/observable/of'; import {HttpClientTestingModule} from '@angular/common/http/testing'; import {getPropertyAsSpy} from '../../utils/spy'; describe('InfoBoxComponent', () => { let component: InfoBoxComponent; let fixture: ComponentFixture; let dataCardServiceStub: SpyObj; beforeEach(async () => { dataCardServiceStub = createSpyObj( 'DataCardService', { }, { selectedDataCard$: of(undefined) } ); await TestBed.configureTestingModule({ declarations: [ InfoBoxComponent ], imports: [MatIconModule, MatIconTestingModule, HttpClientTestingModule], providers: [ {provide: DataCardService, useValue: dataCardServiceStub}, ] }) .compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(InfoBoxComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); describe('when edit-link is provided', () => { beforeEach(() => { component.editLink = '/whatever'; }); describe('and selected dataCard is NOT closed', () => { beforeEach(() => { getPropertyAsSpy(dataCardServiceStub, 'selectedDataCard$').and.returnValue(of({ documentStatus: 'ACTIVE' } as any)); }); it('renders', () => { fixture.detectChanges(); const button = fixture.debugElement.query(By.css('a')); expect(button).toBeDefined(); }); }); describe('and selected dataCard is closed', () => { beforeEach(() => { getPropertyAsSpy(dataCardServiceStub, 'selectedDataCard$').and.returnValue(of({ documentStatus: 'CLOSED' } as any)); }); it('does not render', () => { fixture.detectChanges(); const button = fixture.debugElement.query(By.css('a')); expect(button).toBeFalsy(); }); }); }); });