blob: 9b1971b2941e441aa7b68a559951993fff1a2792 [file]
/*
******************************************************************************
* Copyright © 2018 PTA GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************
*/
import { Util } from './util';
import { Globals } from './globals';
import {
INPUTDATESTRINGARRAY0,
INPUTDATESTRINGARRAY1,
INPUTDATESTRINGARRAY2,
INPUTDATESTRINGARRAY3,
INPUTDATESTRINGARRAY4,
INPUTDATESTRINGARRAY5,
INPUTDATESTRINGARRAY6
} from './../test-data/datestringarrays';
describe('Util', () => {
let element: HTMLElement;
beforeEach(() => {
element = document.createElement('div');
});
it('calculates the correct drop orientation', () => {
spyOn(element, 'getBoundingClientRect').and.returnValue({'top': Globals.DATEPICKER_HEIGHT});
expect(Util.calcDatepickerDropOrientation(element)).toBe('down');
});
it('calculates the correct drop orientation', () => {
spyOn(element, 'getBoundingClientRect').and.returnValue({'top': Globals.DATEPICKER_HEIGHT - 1});
expect(Util.calcDatepickerDropOrientation(element)).toBe('down');
});
it('calculates the correct drop orientation', () => {
spyOn(element, 'getBoundingClientRect').and.returnValue({'top': Globals.DATEPICKER_HEIGHT + 1});
expect(Util.calcDatepickerDropOrientation(element)).toBe('up');
});
it('calculates the correct drop orientation for no valid HTML element', () => {
expect(Util.calcDatepickerDropOrientation(null)).toBe('');
});
it('should calculate earliest datestring', () => {
expect(Util.getEarliestValidDateString(INPUTDATESTRINGARRAY0)).toBe('');
expect(Util.getEarliestValidDateString(INPUTDATESTRINGARRAY1)).toBe('');
expect(Util.getEarliestValidDateString(INPUTDATESTRINGARRAY2)).toBe('');
expect(Util.getEarliestValidDateString(INPUTDATESTRINGARRAY3)).toBe('2017-01-15T11:11:00z');
expect(Util.getEarliestValidDateString(INPUTDATESTRINGARRAY4)).toBe('2017-01-16T11:11:00z');
expect(Util.getEarliestValidDateString(INPUTDATESTRINGARRAY5)).toBe('2017-01-01T11:11:00z');
expect(Util.getEarliestValidDateString(INPUTDATESTRINGARRAY6)).toBe('2016-02-15T11:11:00z');
});
it('should calculate latest datestring', () => {
expect(Util.getLatestValidDateString(INPUTDATESTRINGARRAY0)).toBe('');
expect(Util.getLatestValidDateString(INPUTDATESTRINGARRAY1)).toBe('');
expect(Util.getLatestValidDateString(INPUTDATESTRINGARRAY2)).toBe('');
expect(Util.getLatestValidDateString(INPUTDATESTRINGARRAY3)).toBe('2017-01-15T11:11:00z');
expect(Util.getLatestValidDateString(INPUTDATESTRINGARRAY4)).toBe('2017-01-16T11:11:00z');
expect(Util.getLatestValidDateString(INPUTDATESTRINGARRAY5)).toBe('2017-02-15T11:11:00z');
expect(Util.getLatestValidDateString(INPUTDATESTRINGARRAY6)).toBe('2018-01-01T11:11:00z');
});
});