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

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

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

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

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' };
        let resolver: LanguageResolve = new LanguageResolve(translateService);
        resolver.resolve(activatedRouteSnapshotStub).subscribe(
            r => expect(r).toEqual(translations),
            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();
    }));

});
