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

import { TestParameterResolve } from './testparam.resolve';

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

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

    let activatedRouteSnapshotStub: ActivatedRouteSnapshotMock;

    beforeEach(() => {
        activatedRouteSnapshotStub = new ActivatedRouteSnapshotMock();
    });

    it('chech testparam done with test value', async(() => {
        activatedRouteSnapshotStub.params = { test: 'test' };
        let resolver: TestParameterResolve = new TestParameterResolve();
        resolver.resolve(activatedRouteSnapshotStub).then(
            (r: string) => expect(r).toEqual(activatedRouteSnapshotStub.params.test),
            (e: {}) => console.log('err', e)
        );
    }));
    it('chech testparam done with empty string', async(() => {
        activatedRouteSnapshotStub.params = { test: '' };
        let resolver: TestParameterResolve = new TestParameterResolve();
        resolver.resolve(activatedRouteSnapshotStub).then(
            (r: string) => expect(r).toEqual(activatedRouteSnapshotStub.params.test),
            (e: {}) => fail(e)
        );
    }));
    it('chech testparam done with empty params', async(() => {
        activatedRouteSnapshotStub.params = {};
        let resolver: TestParameterResolve = new TestParameterResolve();
        resolver.resolve(activatedRouteSnapshotStub).then(
            (r: string) => expect(r).toEqual(''),
            (e: {}) => fail(e)
        );
    }));
    it('chech testparam fail with string not empty or test', async(() => {
        activatedRouteSnapshotStub.params = { test: 'tst2' };
        let resolver: TestParameterResolve = new TestParameterResolve();
        resolver.resolve(activatedRouteSnapshotStub).then(
            () => fail('promise not rejected'),
            (e: string) => expect(e).toEqual('notfound')
        );
    }));
    it('chech testparam done with params not have test param', async(() => {
        activatedRouteSnapshotStub.params = { custom: 'tst2' };
        let resolver: TestParameterResolve = new TestParameterResolve();
        resolver.resolve(activatedRouteSnapshotStub).then(
            (r: string) => expect(r).toEqual(''),
            (e: object) => fail(e)
        );
    }));
});
