import { TestBed , ComponentFixture } from '@angular/core/testing' ; import { ConfigureBitbucketComponent } from './configure-bitbucket.component' ; import { async } from 'q' ; import { DeploymentCenterStateManager } from '../../wizard-logic/deployment-center-state-manager' ; import { TranslateModule } from '@ngx-translate/core' ; import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs/Observable' ; import { CacheService } from '../../../../../shared/services/cache.service' ; import { FormsModule , ReactiveFormsModule , FormBuilder , FormGroup } from '@angular/forms' ; import { NgSelectModule } from '@ng-select/ng-select' ; import { LogService } from '../../../../../shared/services/log.service' ; import { WizardForm } from '../../wizard-logic/deployment-center-setup-models' ; import { MockLogService } from '../../../../../test/mocks/log.service.mock' ; import { NgSelectTestHelpers , KeyCode } from '../../../../../test/mocks/ng-select-helpers.mock' ; import { Subject } from 'rxjs/Subject' ; describe ( 'ConfigureBitbucketComponent' , ( ) => { let component ; let testFixture ; beforeEach ( async ( ( ) => { TestBed . configureTestingModule ( { declarations : [ ConfigureBitbucketComponent ] , providers : [ { provide : DeploymentCenterStateManager , useClass : MockDeploymentCenterStateManager } , { provide : CacheService , useClass : MockCacheService } , { provide : LogService , useClass : MockLogService } , FormBuilder , ] , imports : [ TranslateModule . forRoot ( ) , FormsModule , ReactiveFormsModule , NgSelectModule ] , } ) . compileComponents ( ) ; } ) ) ; beforeEach ( ( ) => { testFixture = TestBed . createComponent ( ConfigureBitbucketComponent ) ; component = testFixture . componentInstance ; testFixture . detectChanges ( ) ; } ) ; describe ( 'init' , ( ) => { it ( 'BranchList should start empty' , ( ) => { expect ( component . BranchList . length ) . toBe ( 0 ) ; } ) ; it ( 'should start with nothing selected' , ( ) => { const mockDeploymentCenterStateManager = TestBed . get ( DeploymentCenterStateManager ) ; expect ( component . selectedBranch ) . toBeNull ( ) ; expect ( component . selectedRepo ) . toBeNull ( ) ; expect ( mockDeploymentCenterStateManager . wizardValues . sourceSettings . repoUrl ) . toBeNull ( ) ; expect ( mockDeploymentCenterStateManager . wizardValues . sourceSettings . branch ) . toBeNull ( ) ; } ) ; } ) ; describe ( 'Selection Behavior' , ( ) => { it ( 'branch list should be populated with correct branches when repo is selected' , ( ) => { NgSelectTestHelpers . selectOption ( testFixture , 'configure-bitbucket-repo-select' , KeyCode . ArrowDown , 0 ) ; component . BranchList . forEach ( x => { expect ( x . value ) . toContain ( `-testfullname1` ) ; } ) ; } ) ; } ) ; describe ( 'Form Validation' , ( ) => { } ) ; } ) ; @ Injectable ( ) class MockDeploymentCenterStateManager { public wizardForm : FormGroup ; public updateSourceProviderConfig$ = new Subject ( ) ; constructor ( _fb ) { this . wizardForm = _fb . group ( { sourceProvider : [ null ] , buildProvider : [ 'kudu' ] , sourceSettings : _fb . group ( { repoUrl : [ 'github' ] , branch : [ null ] , isManualIntegration : [ false ] , deploymentRollbackEnabled : [ false ] , isMercurial : [ false ] , } ) , buildSettings : _fb . group ( { createNewVsoAccount : [ false ] , vstsAccount : [ 'account' ] , vstsProject : [ null ] , location : [ null ] , applicationFramework : [ null ] , workingDirectory : [ null ] , pythonSettings : _fb . group ( { framework : [ null ] , version : [ null ] , flaskProjectName : [ 'flaskProjectName' ] , djangoSettingsModule : [ 'DjangoProjectName.settings' ] , } ) , nodejsTaskRunner : [ null ] , } ) , deploymentSlotSetting : _fb . group ( { newDeploymentSlot : [ false ] , deploymentSlotEnabled : [ false ] , deploymentSlot : [ 'slot' ] , } ) , } ) ; } public get wizardValues ( ) : WizardForm { return this . wizardForm . value ; } public get sourceSettings ( ) : FormGroup { return ( this . wizardForm && ( this . wizardForm . controls . sourceSettings as FormGroup ) ) || null ; } public getToken ( ) { return '' ; } } @ Injectable ( ) class MockCacheService { public siteObject = { location : 'loc' , properties : { sku : 'sku' , } , } ; get ( url , force ? , headers ? , invokeApi ? ) { return Observable . of ( null ) ; } post ( url , force ? , headers ? , content ? ) { if ( content . url . includes ( '/repositories?role=admin' ) ) { return Observable . of ( { json : ( ) => { return { values : [ { name : 'testName1' , full_name : 'testfullname1' , } , { name : 'testName2' , full_name : 'testfullname2' , } , { name : 'testName3' , full_name : 'testfullname3' , } , { name : 'testName4' , full_name : 'testfullname4' , } , ] , } ; } , } ) ; } else if ( content . url . includes ( '/refs/branches' ) ) { const repo = content . url . split ( '/' ) [ 5 ] ; return Observable . of ( { json : ( ) => { return { values : [ { name : `testBranch1-${ repo }` , } , { name : `testBranch1-${ repo }` , } , { name : `testBranch1-${ repo }` , } , { name : `testBranch1-${ repo }` , } , ] , } ; } , } ) ; } return Observable . of ( null ) ; } getArm ( resourceId , force ? , apiVersion ? , invokeApi ? ) { return Observable . of ( { json : ( ) => { return this . siteObject ; } , } ) ; } postArm ( resourceId , force ? , apiVersion ? , content ? ) { return Observable . of ( null ) ; } putArm ( resourceId , apiVersion ? , content ? ) { return Observable . of ( { json : ( ) => { return content ; } , } ) ; } }