import { TestBed } from '@angular/core/testing';
import { OnlineBoardUrlParserService } from '@online-board/services/url/url-parser.service';

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

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [OnlineBoardUrlParserService],
        });

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

    it('should parse arrival search url params without time range', () => {
        const urlParams = 'MOW-20200528';
        const result = service.parseArrivalSearchUrlParams(urlParams);

        expect(result).toEqual({
            arrival: 'MOW',
            date: new Date(2020, 4, 28),
            timeFrom: undefined,
            timeTo: undefined,
        });
    });

    it('should parse arrival search url params with time range', () => {
        const urlParams = 'MOW-20200528-06002200';
        const result = service.parseArrivalSearchUrlParams(urlParams);

        expect(result).toEqual({
            arrival: 'MOW',
            date: new Date(2020, 4, 28),
            timeFrom: '0600',
            timeTo: '2200',
        });
    });

    it('should parse departure search url params without time range', () => {
        const urlParams = 'MOW-20200528';
        const result = service.parseDepartureSearchUrlParams(urlParams);

        expect(result).toEqual({
            departure: 'MOW',
            date: new Date(2020, 4, 28),
            timeFrom: undefined,
            timeTo: undefined,
        });
    });

    it('should parse departure search url params with time range', () => {
        const urlParams = 'MOW-20200528-06002200';
        const result = service.parseDepartureSearchUrlParams(urlParams);

        expect(result).toEqual({
            departure: 'MOW',
            date: new Date(2020, 4, 28),
            timeFrom: '0600',
            timeTo: '2200',
        });
    });

    it('should parse route search url params without time range', () => {
        const urlParams = 'LED-KGD-20220425';
        const result = service.parseRouteSearchUrlParams(urlParams);

        expect(result).toEqual({
            departure: 'LED',
            arrival: 'KGD',
            date: new Date(2022, 3, 25),
            timeFrom: undefined,
            timeTo: undefined,
        });
    });

    it('should parse departure search url params with time range', () => {
        const urlParams = 'LED-KGD-20220425-06002200';
        const result = service.parseRouteSearchUrlParams(urlParams);

        expect(result).toEqual({
            departure: 'LED',
            arrival: 'KGD',
            date: new Date(2022, 3, 25),
            timeFrom: '0600',
            timeTo: '2200',
        });
    });

    it('should parse station search params without time range', () => {
        const urlParams = 'MOW-20200528';
        const result = service.parseStationSearchUrlParams(urlParams);

        expect(result).toEqual({
            station: 'MOW',
            date: new Date(2020, 4, 28),
            timeFrom: undefined,
            timeTo: undefined,
        });
    });

    it('should parse station search params with time range', () => {
        const urlParams = 'MOW-20200528-06002200';
        const result = service.parseStationSearchUrlParams(urlParams);

        expect(result).toEqual({
            station: 'MOW',
            date: new Date(2020, 4, 28),
            timeFrom: '0600',
            timeTo: '2200',
        });
    });
});
