import { TestBed } from '@angular/core/testing';
import { ScheduleDetailsUrlParamsResolver } from '@schedule/resolvers/url-params/details-url-params.resolver';
import { FLIGHTS_INFO_PARAM } from '@schedule/services/url/flights-info-param';
import { ScheduleUrlParserService } from '@schedule/services/url/url-parser.service';

describe('ScheduleDetailsUrlParamsResolver', () => {
    let service: ScheduleDetailsUrlParamsResolver;
    const parseFlightDetailsParamsMock = jasmine.createSpy(
        'parseFlightDetailsParams',
    );
    const paramName = 'flightsInfo';

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
                ScheduleDetailsUrlParamsResolver,
                {
                    provide: FLIGHTS_INFO_PARAM,
                    useValue: paramName,
                },
                {
                    provide: ScheduleUrlParserService,
                    useValue: {
                        parseFlightDetailsParams: parseFlightDetailsParamsMock,
                    },
                },
            ],
        });

        service = TestBed.inject(ScheduleDetailsUrlParamsResolver);
        parseFlightDetailsParamsMock.calls.reset();
    });

    it('should return url params with details field', () => {
        const paramsString = 'SU0001-20220528';
        const activatedRoute = {
            params: {
                [paramName]: paramsString,
            },
        };

        const parsedParams = {
            flightNumber: '0001',
            carrier: 'SU',
            date: new Date(2022, 4, 28),
        };

        parseFlightDetailsParamsMock
            .withArgs(paramsString)
            .and.returnValue([parsedParams]);

        expect(service.resolve(activatedRoute as any)).toEqual({
            details: [parsedParams],
        });
    });
});
