import { TestBed } from '@angular/core/testing';
import { OnlineBoardRouteUrlParamsResolver } from '@online-board/resolvers/url-params/route-url-params.resolver';
import { OnlineBoardUrlParserService } from '@online-board/services/url';

describe('OnlineBoardRouteUrlParamsResolver', () => {
    let service: OnlineBoardRouteUrlParamsResolver;
    const parseRouteSearchUrlParamsMock = jasmine.createSpy(
        'parseRouteSearchUrlParams',
    );

    beforeEach(() => {
        TestBed.configureTestingModule({
            providers: [
                OnlineBoardRouteUrlParamsResolver,
                {
                    provide: OnlineBoardUrlParserService,
                    useValue: {
                        parseRouteSearchUrlParams:
                            parseRouteSearchUrlParamsMock,
                    },
                },
            ],
        });

        service = TestBed.inject(OnlineBoardRouteUrlParamsResolver);
        parseRouteSearchUrlParamsMock.calls.reset();
    });

    it('should return online board url params with data for route search', () => {
        const paramsMock = {
            arrival: 'MOW',
            departure: 'MRS',
            date: new Date(2022, 4, 28),
        };
        parseRouteSearchUrlParamsMock.withArgs({}).and.returnValue(paramsMock);

        expect(service.resolve({ params: { params: {} } } as any)).toEqual({
            route: paramsMock,
        });
    });
});
