import { TestBed } from '@angular/core/testing';
import { TimeRangeValidationService } from '@shared/services/validators/time-range.service';

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

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

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

    it('should return true because empty time range is valid', () => {
        expect(service.isTimeRangeValid()).toBe(true);
    });

    it('should return false because one part of time range cannot be empty', () => {
        expect(service.isTimeRangeValid(undefined, '0030')).toBe(false);
        expect(service.isTimeRangeValid('0030')).toBe(false);
    });

    it('should return true because time range is valid', () => {
        expect(service.isTimeRangeValid('0000', '0030')).toBe(true);
        expect(service.isTimeRangeValid('0030', '2400')).toBe(true);
    });

    it('should return false because timeFrom is more than timeTo', () => {
        expect(service.isTimeRangeValid('0045', '0030')).toBe(false);
    });

    it('should return false because timeFrom contains invalid number of minutes', () => {
        expect(service.isTimeRangeValid('0061', '2330')).toBe(false);
        expect(service.isTimeRangeValid('0060', '2330')).toBe(false);
    });

    it('should return false because timeTo contains invalid number of hours', () => {
        expect(service.isTimeRangeValid('0030', '2430')).toBe(false);
        expect(service.isTimeRangeValid('0030', '2500')).toBe(false);
    });

    it('should return false because timeTo contains invalid number of minutes', () => {
        expect(service.isTimeRangeValid('0030', '0061')).toBe(false);
        expect(service.isTimeRangeValid('0030', '0060')).toBe(false);
    });
});
