import { IArrivalStation } from '../models-legacy';
import { AirportTerminalPipe } from './airport-terminal.pipe';

describe('AirportTerminalPipe', () => {
    let pipe: AirportTerminalPipe;

    const arrival: IArrivalStation = {
        latest: {
            airport: 'Москва',
        },
        scheduled: {
            airport: 'Санкт-Петербург',
        },
        terminal: '2C',
    } as any;

    beforeEach(() => {
        pipe = new AirportTerminalPipe();
    });

    it('should return empty string on empty input or missing properties', () => {
        expect(pipe.transform(null, null)).toBe('');
        expect(pipe.transform(undefined, undefined)).toBe('');
        expect(pipe.transform({} as any as IArrivalStation, null)).toBe('');
    });

    it('should return valid airport with proper formatting with dash', () => {
        expect(pipe.transform(arrival, 'dash')).toBe('Москва - 2C');
    });

    it('should return valid airport with proper formatting with brackets', () => {
        expect(pipe.transform(arrival, 'brackets')).toBe('Москва (2C)');
    });

    it('should return valid airport with proper formatting with dash when no latest airport given', () => {
        const airportInfo = {
            scheduled: {
                airport: 'Санкт-Петербург',
            },
            terminal: '2C',
        };

        expect(pipe.transform(airportInfo as any as IArrivalStation, 'dash')).toBe('Санкт-Петербург - 2C');
    });

    it('should return valid airport with proper formatting with brackets when no latest airport given', () => {
        const airportInfo = {
            scheduled: {
                airport: 'Санкт-Петербург',
            },
            terminal: '2C',
        } as IArrivalStation;

        expect(pipe.transform(airportInfo, 'brackets')).toBe('Санкт-Петербург (2C)');
    });

    it('should return only airport if no terminal given', () => {
        const testCases = [
            {
                scheduled: {
                    airport: 'Санкт-Петербург',
                },
            } as IArrivalStation,
            {
                scheduled: {
                    airport: 'Санкт-Петербург',
                },
                terminal: null,
            } as IArrivalStation,
            {
                scheduled: {
                    airport: 'Санкт-Петербург',
                },
                terminal: undefined,
            } as IArrivalStation,
        ];

        testCases.forEach((testCase) => {
            expect(pipe.transform(testCase, 'dash')).toBe('Санкт-Петербург');
            expect(pipe.transform(testCase, 'brackets')).toBe('Санкт-Петербург');
        });
    });

    it('should return only terminal without formatting if onlyTerminal set to true', () => {
        const station = {
            scheduled: {
                airport: 'Санкт-Петербург',
            },
            terminal: 'Пулково-1',
        } as IArrivalStation;

        expect(pipe.transform(station, 'dash', true)).toBe('Пулково-1');
        expect(pipe.transform(station, 'brackets', true)).toBe('Пулково-1');
    });
});
