import { Component } from '@angular/core' ; import { HttpModule } from '@angular/http' ; import { APP_BASE_HREF } from '@angular/common' ; import { ComponentFixture , TestBed } from '@angular/core/testing' ; import { RouterModule } from '@angular/router' ; import { TruncatePipe } from '../../pipes/truncate' ; import { LanguageIconPipe } from '../../pipes/language-icon' ; import { ClientService } from '../../services/client' ; import { RepoListItemComponent } from './' ; @ Component ( { selector : 'test-component-wrapper' , template : '<repo-list-item [repo]="repo"></repo-list-item>' } ) class TestComponentWrapper { repo = { repositoryURL : '' , permissions : { usageType : 'openSource' , licenses : [ { name : 'CC0' , URL : 'https://github.com/GSA/code-gov-web/blob/master/LICENSE.md' , } ] , } , agency : 'GSA' , } ; } describe ( 'RepoListItemComponent' , ( ) => { let component ; let fixture ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { declarations : [ TruncatePipe , LanguageIconPipe , RepoListItemComponent , TestComponentWrapper , ] , imports : [ HttpModule , RouterModule . forRoot ( [ ] ) , ] , providers : [ { provide : APP_BASE_HREF , useValue : '/' } , ClientService , ] , schemas : [ ] , } ) ; fixture = TestBed . createComponent ( TestComponentWrapper ) ; component = fixture . debugElement . children [ 0 ] . componentInstance ; fixture . detectChanges ( ) ; } ) ; describe ( 'isGitHubRepo()' , ( ) => { function testUrl ( url , isGitHubRepo ) { fixture . componentInstance . repo . repositoryURL = url ; expect ( component . isGitHubRepo ( ) ) . toBe ( isGitHubRepo ) ; } it ( 'should return true if it has a repositoryURL from GitHub' , ( ) => { testUrl ( 'https://github.com/gsa/code-gov-web' , true ) ; } ) ; it ( 'should return false if the repositoryURL is not from GitHub' , ( ) => { testUrl ( 'https://gsa.gov/repositories/gsa/code-gov-web' , false ) ; } ) ; } ) ; } ) ;