import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { PageBreadcrumbsComponent } from '@components/page/breadcrumds/page-breadcrumbs.component';
import { TranslateService } from '@ngx-translate/core';
import { IRouteData } from '@typings/common/route';
import { BehaviorSubject } from 'rxjs';

describe('PageBreadcrumbsComponent', () => {
    let fixture: ComponentFixture<PageBreadcrumbsComponent>;
    let component: PageBreadcrumbsComponent;

    const data: IRouteData = {};

    const instantMock = jasmine.createSpy('instant');

    beforeEach(async () => {
        await TestBed.configureTestingModule({
            declarations: [PageBreadcrumbsComponent],
            providers: [
                {
                    provide: TranslateService,
                    useValue: {
                        instant: instantMock,
                    },
                },
                {
                    provide: ActivatedRoute,
                    useValue: {
                        data: new BehaviorSubject(data),
                    },
                },
            ],
        }).compileComponents();
    });

    beforeEach(() => {
        fixture = TestBed.createComponent(PageBreadcrumbsComponent);
        component = fixture.componentInstance;

        data.breadcrumbs = undefined;
        instantMock.calls.reset();
    });

    it('should contain only default breadcrumb item', () => {
        component.ngOnInit();
        expect(component.items.length).toBe(1);
    });

    it('should contain default breadcrumb item and items from data.breadcrumbs', () => {
        data.breadcrumbs = [
            {
                label: 'breadcrumb 1',
                url: 'url1',
            },
            {
                label: 'breadcrumb 2',
                url: 'url2',
            },
        ];
        component.ngOnInit();
        expect(component.items.length).toBe(3);
    });
});
