import { TranslatePipe } from '@ngx-translate/core';
import { DurationPipe } from './duration.pipe';

describe('DurationPipe', () => {
    let translate: TranslatePipe;
    let pipe: DurationPipe;
    beforeEach(() => {
        translate = {
            transform: jasmine
                .createSpy('transform')
                .withArgs('SHARED.SHORT-HOUR')
                .and.returnValue('h')
                .withArgs('SHARED.SHORT-MIN')
                .and.returnValue('m')
                .withArgs('SHARED.SHORT-DAY')
                .and.returnValue('d'),
        } as any;
        pipe = new DurationPipe(translate);
    });
    it('should return empty on empty input', () => {
        expect(pipe.transform(null)).toBe('');
        expect(pipe.transform(undefined)).toBe('');
        expect(pipe.transform('' as any)).toBe('');
    });

    it('should return 0h 0m on empty hour/minute input', () => {
        expect(pipe.transform({} as any)).toBe('0h 0m');
    });

    it('should return time string on non empty hour/minute input', () => {
        expect(pipe.transform({ days: 0, minutes: 10, hours: 3 })).toBe('3h 10m');
    });

    it('should return time string on non empty day/hour/minute input', () => {
        expect(pipe.transform({ days: 4, minutes: 10, hours: 3 })).toBe('4d 3h 10m');
    });
});
