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

import { DepartureRequestComponent } from './departure-request.component';

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

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

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

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

        const departureRequest: IPopularDepartureRequest = {
            mode: RequestMode.DEPARTURE,
            departure: 'MOW',
            type: 'Onlineboard',
        };
        component.request = departureRequest;
        fixture.detectChanges();

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

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