mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 00:43:54 +00:00
1849b4d39f
* chore: migrate eslint to oxlint * chore: migrate prettier to oxfmt * chore: migrate typescript * chore: toThrow should have a expected value * chore: cast test value as Day * chore: small title fix * chore: mocks should be hoisted * chore: incorrect async useage * chore: test should be inside description * chore: test sohuld include an expeced * chore: oxfmt --------- Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { Day } from 'ontime-types';
|
|
|
|
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE, dayInMs } from './conversionUtils';
|
|
import { getTimeFrom } from './getTimeFrom';
|
|
|
|
describe('getTimeFrom', () => {
|
|
it('returns the time elapsed (gap or overlap) from the previous', () => {
|
|
const expected = 75600000 - 71700000; // current start - previousEnd
|
|
expect(
|
|
getTimeFrom(
|
|
{ timeStart: 21 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
|
|
{
|
|
timeStart: 19 * MILLIS_PER_HOUR + 20 * MILLIS_PER_MINUTE,
|
|
duration: 35 * MILLIS_PER_MINUTE,
|
|
dayOffset: 0 as Day,
|
|
},
|
|
),
|
|
).toBe(expected);
|
|
});
|
|
|
|
it('accounts for partially overlapping events', () => {
|
|
const expected = -1;
|
|
expect(
|
|
getTimeFrom({ timeStart: 11, dayOffset: 0 as Day }, { timeStart: 10, duration: 2, dayOffset: 0 as Day }),
|
|
).toBe(expected);
|
|
});
|
|
|
|
it('accounts for events that are fully contained', () => {
|
|
const expected = -6;
|
|
expect(
|
|
getTimeFrom({ timeStart: 10, dayOffset: 0 as Day }, { timeStart: 8, duration: 8, dayOffset: 0 as Day }),
|
|
).toBe(expected);
|
|
});
|
|
|
|
it('fully overlapping events are the next day', () => {
|
|
const expected = dayInMs - 2 * MILLIS_PER_HOUR;
|
|
expect(
|
|
getTimeFrom(
|
|
{ timeStart: 10 * MILLIS_PER_HOUR, dayOffset: 1 as Day },
|
|
{ timeStart: 10 * MILLIS_PER_HOUR, duration: 2 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
|
|
),
|
|
).toBe(expected);
|
|
});
|
|
|
|
it('accounts for events that are the day after', () => {
|
|
const expected = -MILLIS_PER_HOUR; // (previousEnd - currentStart);
|
|
expect(
|
|
getTimeFrom(
|
|
{ timeStart: 22 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
|
|
{ timeStart: 20 * MILLIS_PER_HOUR, duration: 3 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
|
|
),
|
|
).toBe(expected);
|
|
});
|
|
|
|
it('accounts for events that cross midnight', () => {
|
|
const expected = -MILLIS_PER_HOUR; // (previousEnd - currentStart);
|
|
expect(
|
|
getTimeFrom(
|
|
{ timeStart: 1 * MILLIS_PER_HOUR, dayOffset: 1 as Day },
|
|
{ timeStart: 20 * MILLIS_PER_HOUR, duration: 6 * MILLIS_PER_HOUR, dayOffset: 0 as Day },
|
|
),
|
|
).toBe(expected);
|
|
});
|
|
});
|