import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RequestInfoComponent } from '@app/features/popular-requests/components/request-info/request-info.component';
import { IPopularRouteRequest } from '@typings/popular-request';
import { getMockPipe } from '@shared/pipes/pipe.mock';
import { RequestMode } from '@typings/enums';

import { RouteRequestComponent } from './route-request.component';

describe('RouteRequestComponent', () => {
    let component: RouteRequestComponent;
    let fixture: ComponentFixture<RouteRequestComponent>;
    let routeRequest: IPopularRouteRequest;

    beforeEach(async () => {
        await TestBed.configureTestingModule({
            declarations: [
                RouteRequestComponent,
                RequestInfoComponent,
                getMockPipe('translate'),
                getMockPipe('cityName'),
            ],
        }).compileComponents();
    });

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

        routeRequest = {
            mode: RequestMode.ROUTE,
            arrival: 'MOW',
            departure: 'KUF',
            type: 'Onlineboard',
        };
    });

    it('should emit request on host click', () => {
        const emitMock = jasmine.createSpy('emit');
        component.onClick = {
            emit: emitMock,
        } as any;

        component.request = routeRequest;
        fixture.detectChanges();

        const requestInfo = document.querySelector('request-info');
        (requestInfo as any).click();

        expect(emitMock).toHaveBeenCalledWith(routeRequest);
    });

    it('should return appropriate label', () => {
        component.request = routeRequest;
        expect(component.label).toBe('BOARD.ROUTE');

        routeRequest.type = 'Schedule';
        expect(component.label).toBe('SCHEDULE.SCHEDULE-OUTBOUND');

        routeRequest.mode = RequestMode.SCHEDULE_ROUTE_BOTH_DIRECTIONS;
        expect(component.label).toBe('SCHEDULE.SCHEDULE-FULL-ROUTE');
    });
});
