import Daterange from 'dasf-web/lib/dateSelection/daterangepicker/DateRange';

function getClassUnderTest(): Daterange{
    let cut = new Daterange();
    cut.minDate = new Date("2000-01-01");
    cut.maxDate = new Date("2100-01-01");;
    cut.selectedMinDate = new Date("2015-01-01");
    cut.selectedMaxDate = new Date("2020-01-01");

    return cut;
}

describe("Daterange Model", () => {
    test('set min value', () => {
        let cut: Daterange = getClassUnderTest();
        let expectVal: Date = new Date();
        cut.minDate = expectVal;

        expect(cut.minDate).toBe(expectVal);
    });

    test('min value > max value', () => {
        let cut: Daterange = getClassUnderTest();
        let minValue: Date = new Date(cut.maxDate.getTime() + (1000*60));
        
        cut.minDate = minValue;

        expect(cut.minDate).toBe(cut.maxDate);
    });

    test('set max value', () => {
        let cut: Daterange = getClassUnderTest();
        let expectVal: Date = new Date();
        cut.maxDate = expectVal;

        expect(cut.maxDate).toBe(expectVal);
    });

    test('max value < min value', () => {
        let cut: Daterange = getClassUnderTest();
        cut.maxDate = new Date(cut.minDate.getTime() - (1000*60));

        expect(cut.maxDate).toBe(cut.minDate);
    });

    test('higher selected max value is equal to max value', () => {
        let cut: Daterange = getClassUnderTest();
        cut.selectedMaxDate = new Date(cut.maxDate.getTime() + (1000*60*60*24*3));
        
        expect(cut.selectedMaxDate).toBe(cut.maxDate);
    });

    test('lower selected min value is equal to min value', () => {
        let cut: Daterange = getClassUnderTest();
        cut.selectedMinDate = new Date(cut.minDate.getTime() - (1000*60*60*24*3));

        expect(cut.selectedMinDate).toBe(cut.minDate);
    });

})
