import { TranslatePipe } from '@ngx-translate/core';
import { DayChangePipe } from './day-change.pipe';

describe('DatePipe', () => {
    const date = new Date(2021, 10, 22, 17, 34);
    const translate: TranslatePipe = {
        transform: jasmine.createSpy('transform').withArgs('SHARED.DAY').and.returnValue('day'),
    } as any;
    let pipe: DayChangePipe;

    beforeEach(() => {
        pipe = new DayChangePipe(translate);
    });
    it('should return empty on empty input', () => {
        expect(pipe.transform(null)).toBe('');
        expect(pipe.transform(undefined)).toBe('');
        expect(pipe.transform('' as any)).toBe('');
        expect(pipe.transform({ value: null } as any)).toBe('');
        expect(pipe.transform({ value: 0 } as any)).toBe('');
        expect(pipe.transform({ value: 9, title: '' }, null)).toBe('');
        expect(pipe.transform({ value: 9, title: '' }, undefined)).toBe('');
    });

    it('should format (+-)1 day', () => {
        expect(pipe.transform({ value: 1, title: '' })).toEqual('day');
        expect(pipe.transform({ value: -1, title: '' })).toEqual('day');
    });

    it('should format more/less than 1 day with date as date', () => {
        expect(pipe.transform({ value: 2, title: '' }, date)).toEqual('22.11.2021');
        expect(pipe.transform({ value: -2, title: '' }, date)).toEqual('22.11.2021');
    });

    it('should format more/less than 1 day with date as string', () => {
        expect(pipe.transform({ value: 2, title: '' }, date.toISOString())).toEqual('22.11.2021');
        expect(pipe.transform({ value: -2, title: '' }, date.toISOString())).toEqual('22.11.2021');
    });
});
