import { TestBed } from '@angular/core/testing';
import { TranslatePipe } from '@ngx-translate/core';
import { ApiFormatterService } from '@shared/services/api/formatter.service';
import { TimeRangePipe } from './time-range.pipe';

describe('TimeRangePipe', () => {
    let translate: TranslatePipe;
    let pipe: TimeRangePipe;

    beforeEach(() => {
        translate = {
            transform: jasmine
                .createSpy('transform')
                .withArgs('SHARED.ALL_DAY')
                .and.returnValue('allday'),
        } as any;

        TestBed.configureTestingModule({
            providers: [
                ApiFormatterService,
                TimeRangePipe,
                {
                    provide: TranslatePipe,
                    useValue: translate,
                },
            ],
        });

        pipe = TestBed.inject(TimeRangePipe);
    });

    it('should return allday on empty from/to input', () => {
        expect(pipe.transform({})).toBe('allday');
        expect(pipe.transform()).toBe('allday');
    });

    it('should return allday on empty 00002400 input', () => {
        expect(pipe.transform({ timeFrom: '0000', timeTo: '2400' })).toBe(
            'allday',
        );
    });

    it('should return 06:00 - 13:00 on 06001300 input', () => {
        expect(pipe.transform({ timeFrom: '0600', timeTo: '1300' })).toBe(
            '06:00 — 13:00',
        );
    });
});
