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

import { ArrivalRequestComponent } from './arrival-request.component';

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

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

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

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

        const arrivalRequest: IPopularArrivalRequest = {
            mode: RequestMode.ARRIVAL,
            arrival: 'MOW',
            type: 'Onlineboard',
        };
        component.request = arrivalRequest;
        fixture.detectChanges();

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

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