import { TestBed } from '@angular/core/testing';
import { IOnlineBoardRoutePageUrlParams } from '@online-board/services/url/types';
import { ONLINE_BOARD_URL_BASE } from '@online-board/services/url/url-base';
import { OnlineBoardUrlBuilderService } from '@online-board/services/url/url-builder.service';
import { IFlightId } from '@typings/flight/flight-id';

describe('OnlineBoardUrlBuilderService', () => {
    let service: OnlineBoardUrlBuilderService;

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
                OnlineBoardUrlBuilderService,
                {
                    provide: ONLINE_BOARD_URL_BASE,
                    useValue: 'onlineboard',
                },
            ],
        });

        service = TestBed.inject(OnlineBoardUrlBuilderService);
    });

    it('should build flight number search page url from params', () => {
        const result = service.getFlightNumberPageUrl({
            flightNumber: '1234',
            carrier: 'SU',
            date: new Date(2020, 4, 28),
        });

        expect(result).toBe('onlineboard/flight/SU1234-20200528');
    });

    it('should build details page url from params', () => {
        const flightId: IFlightId = {
            flightNumber: 'SU1234',
            carrier: '',
            date: '',
        };
        const date = new Date(2020, 4, 28);
        const result = service.getDetailsPageUrl(flightId, date);

        expect(result).toBe('onlineboard/SU1234-20200528');
    });

    it('should build arrival search url page from params without time range', () => {
        const params: IOnlineBoardRoutePageUrlParams = {
            arrival: 'MOW',
            date: new Date(2020, 4, 28),
        };
        const result = service.getRoutePageUrl(params);

        expect(result).toBe('onlineboard/arrival/MOW-20200528');
    });

    it('should build arrival search url page from params with time range', () => {
        const params: IOnlineBoardRoutePageUrlParams = {
            arrival: 'MOW',
            date: new Date(2020, 4, 28),
            timeFrom: '0600',
            timeTo: '2200',
        };
        const result = service.getRoutePageUrl(params);

        expect(result).toBe('onlineboard/arrival/MOW-20200528-06002200');
    });

    it('should build departure search url page from params without time range', () => {
        const params: IOnlineBoardRoutePageUrlParams = {
            departure: 'MOW',
            date: new Date(2020, 4, 28),
        };
        const result = service.getRoutePageUrl(params);

        expect(result).toBe('onlineboard/departure/MOW-20200528');
    });

    it('should build departure search page url from params with time range', () => {
        const params: IOnlineBoardRoutePageUrlParams = {
            departure: 'MOW',
            date: new Date(2020, 4, 28),
            timeFrom: '0600',
            timeTo: '2200',
        };
        const result = service.getRoutePageUrl(params);

        expect(result).toBe('onlineboard/departure/MOW-20200528-06002200');
    });

    it('should build route search page url from params without time range', () => {
        const params: IOnlineBoardRoutePageUrlParams = {
            departure: 'LED',
            arrival: 'KGD',
            date: new Date(2022, 3, 25),
        };
        const result = service.getRoutePageUrl(params);

        expect(result).toBe('onlineboard/route/LED-KGD-20220425');
    });

    it('should build route search page url from params with time range', () => {
        const params: IOnlineBoardRoutePageUrlParams = {
            departure: 'LED',
            arrival: 'KGD',
            date: new Date(2022, 3, 25),
            timeFrom: '0600',
            timeTo: '2200',
        };
        const result = service.getRoutePageUrl(params);

        expect(result).toBe('onlineboard/route/LED-KGD-20220425-06002200');
    });

    it('should build start page url', () => {
        expect(service.getStartPageUrl()).toBe('onlineboard');
    });
});
