import { datesEqual, startOfDate } from 'web-foundation/etc/date-helpers';

describe('datesEqual', function() {
    it('should return true if dates are exactly equal', function() {
        const dateA = new Date(2016, 6, 13),
            dateB = new Date(2016, 6, 13);

        expect(datesEqual(dateA, dateB)).to.be.true;
    });

    it('should return false if dates are not equal', function() {
        const dateA = new Date(2016, 6, 13),
            dateB = new Date(2016, 5, 14);

        expect(datesEqual(dateA, dateB)).to.be.false;
    });

    it('should return false if inputs are not valid', function() {
        const date = new Date();

        expect(datesEqual(date, null)).to.be.false;
    });
});

describe('startOfDate', function() {
    it('should give me the start of time', function() {
        const dateA = new Date(2016, 6, 15, 16, 40);
        let dateB;

        dateB = startOfDate(dateA, 'seconds');
        expect(dateB.getMilliseconds()).to.equal(0);

        dateB = startOfDate(dateA, 'minutes');
        expect(dateB.getSeconds()).to.equal(0);

        dateB = startOfDate(dateA, 'hours');
        expect(dateB.getMinutes()).to.equal(0);

        dateB = startOfDate(dateA, 'days');
        expect(dateB.getHours()).to.equal(0);

        dateB = startOfDate(dateA, 'months');
        expect(dateB.getDate()).to.equal(1);

        dateB = startOfDate(dateA, 'years');
        expect(dateB.getMonth()).to.equal(0);
    });

    it('should fall through properly', function() {
        const dateA = new Date(2016, 6, 15, 16, 40, 53, 123),
            dateB = startOfDate(dateA, 'days');

        expect(dateB.getHours()).to.equal(0);
        expect(dateB.getMinutes()).to.equal(0);
        expect(dateB.getSeconds()).to.equal(0);
    });

    it('should return null for invalid input', function() {
        expect(startOfDate(3)).to.be.null;
    });

    it('should return original date for invalid unit', function() {
        const dateA = new Date(2016, 6, 15, 16, 40),
            dateB = startOfDate(dateA, 'foo');

        expect(dateB.getTime()).to.equal(dateA.getTime());
    });
});
