import { Location } from '@angular/common' ; import { ActivatedRoute , Router } from '@angular/router' ; import { BehaviorSubject } from 'rxjs' ; import { Session } from '../../../../services/session' ; import { DialogService } from '../../../../common/services/confirm-leave-dialog.service' ; import { ConfigsService } from '../../../../common/services/configs.service' ; import { FormToastService } from '../../../../common/services/form-toast.service' ; import { BlogsEditService } from './blog-edit.service' ; import { MockComponent , MockService } from '../../../../utils/mock' ; import { BlogEditorV2Component } from './editor-base.component' ; import { ComponentFixture , TestBed , inject } from '@angular/core/testing' ; import { RouterTestingModule } from '@angular/router/testing' ; import { composerMockService } from '../../../../mocks/modules/composer/services/composer.service.mock' ; import { ComposerService } from '../../../composer/services/composer.service' ; import { ButtonComponent } from '../../../../common/components/button/button.component' ; import { FormsModule } from '@angular/forms' ; const content$ = new BehaviorSubject < string > ( '' ) ; const title$ = new BehaviorSubject < string > ( '' ) ; const banner$ = new BehaviorSubject < string > ( '' ) ; const blogsEditServiceMock = MockService ( BlogsEditService , { has : [ 'content$' , 'title$' , 'nsfw$' ] , props : { content$ : { get : ( ) => content$ } , title$ : { get : ( ) => title$ } , banner$ : { get : ( ) => banner$ } , } , } ) ; describe ( 'BlogEditorV2Component' , ( ) => { let comp ; let fixture ; beforeEach ( ( ) => { TestBed . overrideProvider ( ComposerService , { useValue : composerMockService , } ) ; TestBed . configureTestingModule ( { declarations : [ BlogEditorV2Component , ButtonComponent , MockComponent ( { selector : 'm-blog__editor' , inputs : [ 'content' ] } ) , MockComponent ( { selector : 'm-blogEditor__bottomBar' } ) , MockComponent ( { selector : 'm-blogEditor__dropdown' } ) , ] , imports : [ RouterTestingModule , FormsModule ] , providers : [ { provide : Session , useValue : MockService ( Session , { getLoggedInUser : ( ) => { return { username : 'test' , email_confirmed : true , } ; } , } ) , } , { provide : ActivatedRoute , useValue : MockService ( ActivatedRoute ) } , { provide : DialogService , useValue : MockService ( DialogService ) } , { provide : ConfigsService , useValue : MockService ( ConfigsService ) } , { provide : Location , useValue : MockService ( Location ) } , { provide : FormToastService , useValue : MockService ( FormToastService ) } , { provide : BlogsEditService , useValue : blogsEditServiceMock } , { provide : ComposerService , useValue : composerMockService } , ] , } ) . compileComponents ( ) ; } ) ; beforeEach ( done => { jasmine . MAX_PRETTY_PRINT_DEPTH = 10 ; jasmine . clock ( ) . uninstall ( ) ; jasmine . clock ( ) . install ( ) ; TestBed . overrideComponent ( BlogEditorV2Component , { set : { providers : [ { provide : BlogsEditService , useValue : blogsEditServiceMock } , { provide : ComposerService , useValue : composerMockService } , ] , } , } ) ; fixture = TestBed . createComponent ( BlogEditorV2Component ) ; comp = fixture . componentInstance ; fixture . detectChanges ( ) ; if ( fixture . isStable ( ) ) { done ( ) ; } else { fixture . whenStable ( ) . then ( ( ) => { done ( ) ; } ) ; } } ) ; afterEach ( ( ) => { jasmine . clock ( ) . uninstall ( ) ; } ) ; it ( 'should instantiate' , ( ) => { expect ( comp ) . toBeTruthy ( ) ; } ) ; it ( 'should detect whether a user is verified when determining whether they can create a blog' , ( ) => { expect ( comp . canCreateBlog ( ) ) . toBeTruthy ( ) ; } ) ; it ( 'should dispatch content changes to service' , ( ) => { comp . onContentChange ( '1' ) ; expect ( comp . service . content$ . getValue ( ) ) . toBe ( '1' ) ; } ) ; it ( 'should dispatch title changes to service' , ( ) => { comp . onTitleChange ( '1' ) ; expect ( comp . service . title$ . getValue ( ) ) . toBe ( '1' ) ; } ) ; it ( 'should dispatch content changes to service' , ( ) => { comp . onContentChange ( '1' ) ; expect ( comp . service . content$ . getValue ( ) ) . toBe ( '1' ) ; } ) ; } ) ;