import { TranslatePipe } from '@ngx-translate/core';
import { RouteTypeLegacy } from '../enumerators';
import { Transfer } from '../models-legacy';
import { TransferTypePipe } from './transfer-type.pipe';

describe('TransferTypePipe', () => {
    let translate: TranslatePipe;
    let pipe: TransferTypePipe;

    const transfer = {
        departure: {
            scheduled: {
                airport: 'Москва',
            },
        },
        arrival: {
            scheduled: {
                airport: 'Санкт-Петербург',
            },
        },
    } as any as Transfer;

    beforeEach(() => {
        translate = {
            transform: jasmine
                .createSpy('transform')
                .withArgs('SHARED.FLIGHT-TRANSFER-PLURAL-ONE')
                .and.returnValue('Пересадка')
                .withArgs('SHARED.FLIGHT-TRANSFER-PLURAL-FEW')
                .and.returnValue('Пересадки')
                .withArgs('SHARED.FLIGHT-TRANSFER-PLURAL-OTHER')
                .and.returnValue('Пересадок')
                .withArgs('SHARED.INTERMEDIATE-LANDING-PLURAL-ONE')
                .and.returnValue('Промежуточная посадка')
                .withArgs('SHARED.INTERMEDIATE-LANDING-PLURAL-FEW')
                .and.returnValue('Промежуточные посадки')
                .withArgs('SHARED.INTERMEDIATE-LANDING-PLURAL-OTHER')
                .and.returnValue('Промежуточных посадок'),
        } as any;
        pipe = new TransferTypePipe(translate);
    });

    it('should return empty string if no transfer given', () => {
        expect(pipe.transform(null, null)).toBe('');
        expect(pipe.transform(null, RouteTypeLegacy.MultiLeg)).toBe('');
        expect(pipe.transform(null, RouteTypeLegacy.Connecting)).toBe('');
        expect(pipe.transform(undefined, RouteTypeLegacy.MultiLeg)).toBe('');
        expect(pipe.transform(undefined, RouteTypeLegacy.Connecting)).toBe('');
        expect(pipe.transform([], RouteTypeLegacy.MultiLeg)).toBe('');
    });

    it('should return empty string for transfer with route type Direct', () => {
        expect(pipe.transform([transfer], RouteTypeLegacy.Direct)).toBe('');
    });

    it('should return proper message for transfer(s) with route type Connecting', () => {
        expect(pipe.transform([transfer], RouteTypeLegacy.Connecting)).toBe('Пересадка');

        [2, 3, 4].forEach((count) => {
            expect(pipe.transform(Array(count).fill(transfer), RouteTypeLegacy.Connecting)).toBe('Пересадки');
        });

        expect(pipe.transform(Array(5).fill(transfer), RouteTypeLegacy.Connecting)).toBe('Пересадок');
    });

    it('should return proper message for transfer(s) with route type MultiLeg', () => {
        expect(pipe.transform([transfer], RouteTypeLegacy.MultiLeg)).toBe('Промежуточная посадка');

        [2, 3, 4].forEach((count) => {
            expect(pipe.transform(Array(count).fill(transfer), RouteTypeLegacy.MultiLeg)).toBe('Промежуточные посадки');
        });

        expect(pipe.transform(Array(5).fill(transfer), RouteTypeLegacy.MultiLeg)).toBe('Промежуточных посадок');
    });
});
