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

import { FlightNumberRequestComponent } from './flight-number-request.component';

describe('FlightNumberRequestComponent', () => {
    let component: FlightNumberRequestComponent;
    let fixture: ComponentFixture<FlightNumberRequestComponent>;
    const flightNumberRequest: IPopularFlightNumberRequest = {
        mode: RequestMode.FLIGHT_NUMBER,
        carrier: 'SU',
        flightNumber: '0001',
        type: 'Onlineboard',
    };

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

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

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

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

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

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

    it('should format request correctly', () => {
        component.request = flightNumberRequest;
        expect(component.flightInfo).toBe('SU\u00a00001');
    });
});
