import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { NotFoundComponent } from './notfound.component';

import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';

import { BaseRequestOptions, HttpModule, Http,  Response, ResponseOptions, XHRBackend } from '@angular/http';
import { HttpClient, HttpClientModule} from '@angular/common/http';
//import { MockBackend, MockConnection } from '@angular/http/testing';
import { ConnectionBackend, RequestOptions } from '@angular/http';
import {TranslateLoaderMock} from '../../../../mocks'

describe('notfound component test', () => {
    let notfoundComponent: ComponentFixture<NotFoundComponent>;
    let translateService: TranslateService;
    //let mockBackend: MockBackend;
    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [NotFoundComponent],
            imports: [HttpModule, HttpClientModule, TranslateModule.forRoot({
                loader: {
                    provide: TranslateLoader,
                    useClass: TranslateLoaderMock
                    //useFactory: (http: HttpClient) => new TranslateHttpLoader(http),
                    //deps: [HttpClient]
                }
            })],
            providers: [
                //MockBackend, BaseRequestOptions,
               // {
                //    provide: Http,
                //    deps: [MockBackend, BaseRequestOptions],
                //    useFactory: (backend: XHRBackend, defaultOptions: BaseRequestOptions) => {
                //        return new Http(backend, defaultOptions);
                //    }
                //}
            ]
        }).compileComponents().then(() => {
            notfoundComponent = TestBed.createComponent(NotFoundComponent);
            translateService = TestBed.get(TranslateService);
            //mockBackend = TestBed.get(ConnectionBackend);
        });
    }));
    it('translate', fakeAsync(() => {
        
        //this.mockBackend.connections.subscribe((connection: MockConnection) => {
        //    connection.mockRespond(new Response(new ResponseOptions({
        //        body: { '[page not found]': 'page not found2'}
        //    })));
        
        translateService.use('en');
        tick();
        notfoundComponent.detectChanges();
        expect(notfoundComponent.debugElement.query(By.css('h1')).nativeElement.innerHTML).toBe('page not found');
    }));
});
