Files
flights_web/ClientApp/src/app/shared/models-legacy/duration.model.spec.ts
T

54 lines
1.9 KiB
TypeScript

import { Duration, getDuration, getDurationDiff } from './duration.model';
import * as moment from 'moment';
describe('DurationMode', () => {
it('should handle empty values', () => {
expect(getDuration(new Date(), undefined)).toBeUndefined();
expect(getDuration(undefined, new Date())).toBeUndefined();
expect(getDuration(undefined, undefined)).toBeUndefined();
});
it('should return duration from dates', () => {
const from = moment();
const to = from.clone();
to.add(5, 'hour').add(12, 'minute');
const actual = getDuration(from.toDate(), to.toDate());
const expected: Duration = { days: 0, hours: 5, minutes: 12 };
expect(actual).toEqual(expected);
});
it('should return duration from dates with more than 1 day', () => {
const from = moment();
const to = from.clone();
to.add(5, 'hour').add(12, 'minute').add(2, 'day');
const actual = getDuration(from.toDate(), to.toDate());
const expected: Duration = { days: 2, hours: 5, minutes: 12 };
expect(actual).toEqual(expected);
});
it('should return duration from dates in string', () => {
const from = moment();
const to = from.clone();
to.add(5, 'hour').add(12, 'minute');
const actual = getDuration(from.toDate().toISOString(), to.toDate().toISOString());
const expected: Duration = { days: 0, hours: 5, minutes: 12 };
expect(actual).toEqual(expected);
});
it('should calculate diff between two durations', () => {
const first = { days: 1, hours: 2, minutes: 4 } as Duration;
const next = { days: 2, hours: 5, minutes: 12 } as Duration;
const actual = getDurationDiff(first, next);
const expected: Duration = { days: 1, hours: 3, minutes: 8 };
expect(actual).toEqual(expected);
});
});