import { Injector } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AppSettings } from '../models-legacy';
import { APP_SETTINGS, settingsProvider } from './settings.provider';

describe('settingsProvider', () => {
    const expected: AppSettings = {} as any;
    it('should provide settings from parent route', () => {
        const route: ActivatedRoute = {
            parent: {
                snapshot: {
                    data: {
                        settings: expected,
                    },
                },
            },
        } as any as ActivatedRoute;
        const injector = Injector.create({
            providers: [settingsProvider, { provide: ActivatedRoute, useValue: route }],
        });
        const actual = injector.get(APP_SETTINGS);
        expect(actual).toBe(expected);
    });

    it('should provide settings from child route', () => {
        const route: ActivatedRoute = {
            children: [
                {
                    snapshot: {
                        data: {
                            settings: expected,
                        },
                    },
                },
            ],
        } as any as ActivatedRoute;
        const injector = Injector.create({
            providers: [settingsProvider, { provide: ActivatedRoute, useValue: route }],
        });
        const actual = injector.get(APP_SETTINGS);
        expect(actual).toBe(expected);
    });
});
