mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 11:53:49 +00:00
refactor: clarify responsabilities
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { dayInMs } from 'ontime-utils';
|
||||
import { TimerType } from 'ontime-types';
|
||||
|
||||
import { getCurrent, getExpectedFinish, skipedOutOfEvent } from '../timerUtils.js';
|
||||
import { config } from '../../config/config.js';
|
||||
import { getCurrent, getExpectedFinish, skippedOutOfEvent } from '../timerUtils.js';
|
||||
|
||||
describe('getExpectedFinish()', () => {
|
||||
it('is null if we havent started', () => {
|
||||
@@ -356,88 +355,105 @@ describe('getExpectedFinish() and getCurrentTime() combined', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('skipedOutOfEvent()', () => {
|
||||
it('normal roll out of event', () => {
|
||||
describe('skippedOutOfEvent()', () => {
|
||||
const testSkipLimit = 32;
|
||||
it('does not consider an event end as a skip', () => {
|
||||
const startedAt = 1000;
|
||||
const duration = 1000;
|
||||
const expectedFinish = startedAt + duration;
|
||||
const previousTime = expectedFinish - config.timeSkipLimit / 2;
|
||||
const previousTime = expectedFinish - testSkipLimit / 2;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
clock += config.timeSkipLimit;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock += testSkipLimit;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
});
|
||||
|
||||
it('normal roll backwards out of event', () => {
|
||||
it('allows rolling backwards in an event', () => {
|
||||
const startedAt = 1000;
|
||||
const duration = 1000;
|
||||
const expectedFinish = startedAt + duration;
|
||||
const previousTime = startedAt + config.timeSkipLimit / 2;
|
||||
const previousTime = startedAt + testSkipLimit / 2;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
clock -= config.timeSkipLimit;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock -= testSkipLimit;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
});
|
||||
|
||||
it('normal roll out of event over midnight', () => {
|
||||
const startedAt = dayInMs - config.timeSkipLimit;
|
||||
it('accounts for crossing midnight', () => {
|
||||
const startedAt = dayInMs - testSkipLimit;
|
||||
const expectedFinish = 10;
|
||||
const previousTime = dayInMs - 1;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
clock = config.timeSkipLimit - 2;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock = testSkipLimit - 2;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
});
|
||||
|
||||
it('normal roll backwards out of event over midnight', () => {
|
||||
const startedAt = dayInMs - config.timeSkipLimit;
|
||||
it('allows rolling backwards in an event across midnight', () => {
|
||||
const startedAt = dayInMs - testSkipLimit;
|
||||
const expectedFinish = 10;
|
||||
const previousTime = startedAt + 1;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
clock -= config.timeSkipLimit;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock -= testSkipLimit;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
});
|
||||
|
||||
it('skip out of event', () => {
|
||||
it('finds skip forwards out of event', () => {
|
||||
const startedAt = 1000;
|
||||
const duration = 1000;
|
||||
const expectedFinish = startedAt + duration;
|
||||
const previousTime = expectedFinish - config.timeSkipLimit / 2;
|
||||
const previousTime = expectedFinish - testSkipLimit / 2;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
clock += config.timeSkipLimit + 1;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(true);
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock += testSkipLimit + 1;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(true);
|
||||
});
|
||||
|
||||
it('skip backwards out of event', () => {
|
||||
it('finds skip backwards out of event', () => {
|
||||
const startedAt = 1000;
|
||||
const duration = 1000;
|
||||
const expectedFinish = startedAt + duration;
|
||||
const previousTime = startedAt + config.timeSkipLimit / 2;
|
||||
const previousTime = startedAt + testSkipLimit / 2;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
clock -= config.timeSkipLimit + 1;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(true);
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock -= testSkipLimit + 1;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(true);
|
||||
});
|
||||
|
||||
it('skip out of event over midnight', () => {
|
||||
const startedAt = dayInMs - config.timeSkipLimit;
|
||||
it('finds skip forwards out of event across midnight', () => {
|
||||
const startedAt = dayInMs - testSkipLimit;
|
||||
const expectedFinish = 10;
|
||||
const previousTime = dayInMs - 3;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
clock = config.timeSkipLimit - 2;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(true);
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock = testSkipLimit - 2;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(true);
|
||||
});
|
||||
|
||||
it('skip backwards out of event over midnight', () => {
|
||||
const startedAt = dayInMs - config.timeSkipLimit;
|
||||
it('finds skip backwards out of event across midnight', () => {
|
||||
const startedAt = dayInMs - testSkipLimit;
|
||||
const expectedFinish = 10;
|
||||
const previousTime = startedAt + 1;
|
||||
|
||||
let clock = previousTime;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(false);
|
||||
clock -= config.timeSkipLimit + 1;
|
||||
expect(skipedOutOfEvent(previousTime, clock, startedAt, expectedFinish)).toBe(true);
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(false);
|
||||
|
||||
clock -= testSkipLimit + 1;
|
||||
expect(skippedOutOfEvent(previousTime, clock, startedAt, expectedFinish, testSkipLimit)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user