import { async, TestBed } from '@angular/core/testing';

import { LanguageResolve } from './language.resolve';

import { ActivatedRouteSnapshotMock, ActivatedRouteMock, TranslateLoaderMock } from '../../../../mocks';

import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
import { Router } from '@angular/router';

describe('Language resolve checking', () => {

    let activatedRouteSnapshotStub: ActivatedRouteSnapshotMock;
    let translateService: TranslateService;
    beforeEach(async(() => {
        TestBed.configureTestingModule({
            imports: [TranslateModule.forRoot({
                loader: {
                    provide: TranslateLoader,
                    useClass: TranslateLoaderMock
                }
            })
        ]
        });
        activatedRouteSnapshotStub = new ActivatedRouteSnapshotMock();
        translateService = TestBed.get(TranslateService);
    }));

    it('check language done with en language', async(() => {
        activatedRouteSnapshotStub.params = { lang: 'en' };
        // let translations: { [name: string]: string } = { '[page not found]': 'page not found' };
        // translateService.addLangs(["en", "ru"]);
        translateService.use("en");
        let resolver: LanguageResolve = new LanguageResolve(translateService);
        resolver.resolve(activatedRouteSnapshotStub).subscribe(
            r => expect(r).toEqual('en'),
            e => console.log('err', e)
        );
    }));

    it('check language throw exception with ru language', async(() => {
        activatedRouteSnapshotStub.params = { lang: 'ru' };
        let resolver: LanguageResolve = new LanguageResolve(translateService);
        expect(resolver.resolve).toThrow();
    }));

});
