import { TranslatePipe } from '@ngx-translate/core';
import { RouteTypeLegacy } from '../../../shared/enumerators';
import { FlightModel } from '../../../shared/models-legacy';
import { FlightTitlePipe } from './flight-title.pipe';
import { ViewType } from '../../../shared/enumerators/flight-request-type.enum';

describe('FlightTitlePipe', () => {
    type TestCase = {
        flight: Partial<FlightModel>;
        expected: string;
        viewType: ViewType;
    };
    const translate: TranslatePipe = {
        transform: jasmine
            .createSpy('transform')
            .withArgs('SCHEDULE.SCHEDULE-FLIGHTS')
            .and.returnValue('Flights schedule')
            .withArgs('SHARED.SCHEDULE-FLIGHT')
            .and.returnValue('Flight schedule')
            .withArgs('SHARED.FLIGHT-INFO')
            .and.returnValue('Flight info')
            .withArgs('SHARED.FLIGHTS-INFO')
            .and.returnValue('FlightS info'),
    } as any;

    let pipe: FlightTitlePipe;
    beforeEach(() => {
        pipe = new FlightTitlePipe(translate);
    });
    it('should return empty on empty input', () => {
        expect(pipe.transform(null)).toBe('');
        expect(pipe.transform(undefined)).toBe('');
        expect(pipe.transform('' as any)).toBe('');
        expect(pipe.transform({} as any)).toBe('');
    });

    const cases: TestCase[] = [
        {
            viewType: ViewType.Onlineboard,
            expected: 'Flight info: SU\u00a01234, Ryazan - Prague',
            flight: {
                flightId: { flightNumber: '1234', carrier: 'SU' },
                routeType: RouteTypeLegacy.Direct,
                leg: {
                    arrival: { latest: { city: 'Prague' } },
                    departure: { latest: { city: 'Ryazan' } },
                },
            } as any,
        },
        {
            viewType: ViewType.Onlineboard,
            expected: 'FlightS info: SU\u00a01234, SU\u00a04321, Ryazan - Prague',
            flight: {
                flights: [
                    {
                        flightId: { flightNumber: '1234', carrier: 'SU' },
                        routeType: RouteTypeLegacy.Direct,
                        leg: {
                            arrival: { latest: { city: 'London' } },
                            departure: { latest: { city: 'Ryazan' } },
                        },
                    },
                    {
                        flightId: { flightNumber: '4321', carrier: 'SU' },
                        routeType: RouteTypeLegacy.Direct,
                        leg: {
                            arrival: { latest: { city: 'Prague' } },
                            departure: { latest: { city: 'London' } },
                        },
                    },
                ],
                routeType: RouteTypeLegacy.Connecting,
            } as any,
        },
        {
            viewType: ViewType.Onlineboard,
            expected: 'Flight info: SU\u00a01234, Ryazan - Prague',
            flight: {
                flightId: { flightNumber: '1234', carrier: 'SU' },
                legs: [
                    {
                        arrival: { latest: { city: 'London' } },
                        departure: { latest: { city: 'Ryazan' } },
                    },
                    {
                        arrival: { latest: { city: 'Prague' } },
                        departure: { latest: { city: 'London' } },
                    },
                ],
                routeType: RouteTypeLegacy.MultiLeg,
            } as any,
        },
        {
            viewType: ViewType.Schedule,
            expected: 'Flights schedule: SU\u00a01234, SU\u00a04321',
            flight: {
                flights: [
                    {
                        flightId: { flightNumber: '1234', carrier: 'SU' },
                        routeType: RouteTypeLegacy.Direct,
                        leg: {
                            arrival: { latest: { city: 'London' } },
                            departure: { latest: { city: 'Ryazan' } },
                        },
                    },
                    {
                        flightId: { flightNumber: '4321', carrier: 'SU' },
                        routeType: RouteTypeLegacy.Direct,
                        leg: {
                            arrival: { latest: { city: 'Prague' } },
                            departure: { latest: { city: 'London' } },
                        },
                    },
                ],
                routeType: RouteTypeLegacy.Connecting,
            } as any,
        },
        {
            viewType: ViewType.Schedule,
            expected: 'Flight schedule: SU\u00a01234, Ryazan - Prague',
            flight: {
                flightId: { flightNumber: '1234', carrier: 'SU' },
                legs: [
                    {
                        arrival: { latest: { city: 'London' } },
                        departure: { latest: { city: 'Ryazan' } },
                    },
                    {
                        arrival: { latest: { city: 'Prague' } },
                        departure: { latest: { city: 'London' } },
                    },
                ],
                routeType: RouteTypeLegacy.MultiLeg,
            } as any,
        },
    ];

    cases.forEach(({ flight, viewType, expected }) => {
        it(`should return ${expected} for flight ${JSON.stringify(flight)} and viewType ${viewType}`, () => {
            expect(pipe.transform(flight as any, viewType)).toBe(expected);
        });
    });
});
