import { RouteTypeLegacy } from '../enumerators';
import { FlightModel, ScheduleSortMode } from '../models-legacy';
import { SortFlightsByPipe } from './sort-flights-by.pipe';

describe('SortFlightsByPipe', () => {
    const a: FlightModel = {
        pId: 'a',
        routeType: RouteTypeLegacy.Direct,
        duration: { hours: 5, minutes: 10 },
        leg: {
            arrival: { times: { scheduled: { utc: new Date(2021, 1, 1) } } },
            departure: { times: { scheduled: { utc: new Date(2020, 1, 1) } } },
        },
    } as any;
    const b: FlightModel = {
        pId: 'b',
        routeType: RouteTypeLegacy.Direct,
        duration: { hours: 10, minutes: 20 },
        leg: {
            arrival: { times: { scheduled: { utc: new Date(2022, 1, 1) } } },
            departure: { times: { scheduled: { utc: new Date(2021, 1, 1) } } },
        },
    } as any;
    it('create an instance', () => {
        const pipe = new SortFlightsByPipe();
        expect(pipe).toBeTruthy();
    });

    [
        { source: [b, a], sortBy: ScheduleSortMode.departureUp, expected: [a, b] },
        { source: [a, b], sortBy: ScheduleSortMode.departureDown, expected: [b, a] },

        { source: [b, a], sortBy: ScheduleSortMode.timeUp, expected: [a, b] },
        { source: [a, b], sortBy: ScheduleSortMode.timeDown, expected: [b, a] },

        { source: [b, a], sortBy: ScheduleSortMode.arrivalUp, expected: [a, b] },
        { source: [a, b], sortBy: ScheduleSortMode.arrivalDown, expected: [b, a] },
    ].forEach(({ source, sortBy, expected }) => {
        it(`should sort flights ${JSON.stringify(source.map((f) => f.id))} by ${sortBy} as ${JSON.stringify(
            expected.map((f) => f.id),
        )}`, () => {
            const pipe = new SortFlightsByPipe();
            expect(pipe.transform(source, sortBy)).toEqual(expected);
        });
    });
});
