import {
    countMinutesInUrlTime,
    minutesToTimeString,
    toTimeString,
} from '@utils/time';

describe('countMinutesInUrlTime', () => {
    it('should count minutes', () => {
        expect(countMinutesInUrlTime(undefined)).toBe(undefined);
        expect(countMinutesInUrlTime('0225')).toBe(145);
        expect(countMinutesInUrlTime('1225')).toBe(745);
        expect(countMinutesInUrlTime('0025')).toBe(25);
        expect(countMinutesInUrlTime('0000')).toBe(0);
        expect(countMinutesInUrlTime('1200')).toBe(720);
        expect(countMinutesInUrlTime('1000')).toBe(600);
        expect(countMinutesInUrlTime('0100')).toBe(60);
        expect(countMinutesInUrlTime('0010')).toBe(10);
        expect(countMinutesInUrlTime('0001')).toBe(1);
    });
});

describe('minutesToTimeString', () => {
    it('should format minutes as string', () => {
        expect(minutesToTimeString(undefined)).toBe(undefined);
        expect(minutesToTimeString(145)).toBe('0225');
        expect(minutesToTimeString(745)).toBe('1225');
        expect(minutesToTimeString(25)).toBe('0025');
        expect(minutesToTimeString(0)).toBe('0000');
        expect(minutesToTimeString(720)).toBe('1200');
        expect(minutesToTimeString(600)).toBe('1000');
        expect(minutesToTimeString(60)).toBe('0100');
        expect(minutesToTimeString(10)).toBe('0010');
        expect(minutesToTimeString(1)).toBe('0001');
    });
});

describe('toTimeString', () => {
    it('should add zeros for one digit numbers', () => {
        expect(toTimeString(0)).toBe('00');
        expect(toTimeString(9)).toBe('09');
    });

    it('should not add zeros for two digits numbers', () => {
        expect(toTimeString(10)).toBe('10');
        expect(toTimeString(19)).toBe('19');
    });
});
