mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 18:33:53 +00:00
Fix/roll (#39)
* roll locks to first in case there are events with overlapping time, roll will play the one that started first * sanitize data entry fixes issue where input field would not return seconds if not modified * update chakra * fix time input in chrome fix issue in chrome where value of input does not contain seconds
This commit is contained in:
@@ -242,3 +242,143 @@ describe('test that roll loads selection in right order', () => {
|
||||
expect(state).toStrictEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
// test getSelectionByRoll()
|
||||
describe('test that roll behaviour with overlapping times', () => {
|
||||
const eventlist = [
|
||||
{
|
||||
id: 1,
|
||||
timeStart: 10,
|
||||
timeEnd: 10,
|
||||
isPublic: false,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
timeStart: 10,
|
||||
timeEnd: 20,
|
||||
isPublic: true,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
timeStart: 10,
|
||||
timeEnd: 30,
|
||||
isPublic: false,
|
||||
},
|
||||
];
|
||||
|
||||
it('if timer is at 0', () => {
|
||||
const now = 0;
|
||||
const expected = {
|
||||
nowIndex: null,
|
||||
nowId: null,
|
||||
publicIndex: null,
|
||||
nextIndex: 0,
|
||||
publicNextIndex: 1,
|
||||
timers: null,
|
||||
timeToNext: 10,
|
||||
};
|
||||
|
||||
const state = getSelectionByRoll(eventlist, now);
|
||||
expect(state).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it('if timer is at 10', () => {
|
||||
const now = 10;
|
||||
const expected = {
|
||||
nowIndex: 1,
|
||||
nowId: 2,
|
||||
publicIndex: 1,
|
||||
nextIndex: 2,
|
||||
publicNextIndex: null,
|
||||
timers: {
|
||||
_finishAt: 20,
|
||||
_startedAt: 10,
|
||||
current: 10,
|
||||
duration: 10,
|
||||
},
|
||||
timeToNext: 0,
|
||||
};
|
||||
|
||||
const state = getSelectionByRoll(eventlist, now);
|
||||
expect(state).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it('if timer is at 15', () => {
|
||||
const now = 15;
|
||||
const expected = {
|
||||
nowIndex: 1,
|
||||
nowId: 2,
|
||||
publicIndex: 1,
|
||||
nextIndex: 2,
|
||||
publicNextIndex: null,
|
||||
timers: {
|
||||
_startedAt: 10,
|
||||
_finishAt: 20,
|
||||
current: 5,
|
||||
duration: 10,
|
||||
},
|
||||
timeToNext: -5,
|
||||
};
|
||||
|
||||
const state = getSelectionByRoll(eventlist, now);
|
||||
expect(state).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it('if timer is at 20', () => {
|
||||
const now = 20;
|
||||
const expected = {
|
||||
nowIndex: 2,
|
||||
nowId: 3,
|
||||
publicIndex: 1,
|
||||
nextIndex: null,
|
||||
publicNextIndex: null,
|
||||
timers: {
|
||||
_startedAt: 10,
|
||||
_finishAt: 30,
|
||||
current: 10,
|
||||
duration: 20,
|
||||
},
|
||||
timeToNext: null,
|
||||
};
|
||||
|
||||
const state = getSelectionByRoll(eventlist, now);
|
||||
expect(state).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it('if timer is at 25', () => {
|
||||
const now = 25;
|
||||
const expected = {
|
||||
nowIndex: 2,
|
||||
nowId: 3,
|
||||
publicIndex: 1,
|
||||
nextIndex: null,
|
||||
publicNextIndex: null,
|
||||
timers: {
|
||||
_startedAt: 10,
|
||||
_finishAt: 30,
|
||||
current: 5,
|
||||
duration: 20,
|
||||
},
|
||||
timeToNext: null,
|
||||
};
|
||||
|
||||
const state = getSelectionByRoll(eventlist, now);
|
||||
expect(state).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it('if timer is at 31', () => {
|
||||
const now = 31;
|
||||
const expected = {
|
||||
nowIndex: null,
|
||||
nowId: null,
|
||||
publicIndex: null,
|
||||
nextIndex: null,
|
||||
publicNextIndex: null,
|
||||
timers: null,
|
||||
timeToNext: null,
|
||||
};
|
||||
|
||||
const state = getSelectionByRoll(eventlist, now);
|
||||
expect(state).toStrictEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,6 +37,9 @@ export const getSelectionByRoll = (arr, now) => {
|
||||
// Order events by startTime
|
||||
const orderedEvents = sortArrayByProperty(arr, 'timeStart');
|
||||
|
||||
// flags: select first event if several overlapping
|
||||
let nowFound = false;
|
||||
|
||||
// exit early if we are past the events
|
||||
const lastEventEnd = orderedEvents[orderedEvents.length - 1].timeEnd;
|
||||
if (now > lastEventEnd) {
|
||||
@@ -57,7 +60,7 @@ export const getSelectionByRoll = (arr, now) => {
|
||||
const normalEnd =
|
||||
e.timeEnd < e.timeStart ? (e.timeEnd += this.DAYMS) : e.timeEnd;
|
||||
|
||||
if (normalEnd < now) {
|
||||
if (normalEnd <= now) {
|
||||
// event ran already
|
||||
|
||||
// public event might not be the one running
|
||||
@@ -65,7 +68,7 @@ export const getSelectionByRoll = (arr, now) => {
|
||||
publicTime = normalEnd;
|
||||
publicIndex = arr.findIndex((a) => a.id === e.id);
|
||||
}
|
||||
} else if (normalEnd >= now && now >= e.timeStart) {
|
||||
} else if (normalEnd > now && now >= e.timeStart && !nowFound) {
|
||||
// event is running
|
||||
|
||||
// it could also be public
|
||||
@@ -84,6 +87,7 @@ export const getSelectionByRoll = (arr, now) => {
|
||||
duration: normalEnd - e.timeStart,
|
||||
current: normalEnd - now,
|
||||
};
|
||||
nowFound = true;
|
||||
} else if (normalEnd > now) {
|
||||
// event will run
|
||||
|
||||
@@ -93,18 +97,14 @@ export const getSelectionByRoll = (arr, now) => {
|
||||
// look for next events
|
||||
// check how far the start is from now
|
||||
const wait = e.timeStart - now;
|
||||
if (wait > 0) {
|
||||
if (nextIndex === null || wait < timeToNext) {
|
||||
timeToNext = wait;
|
||||
nextIndex = arr.findIndex((a) => a.id === e.id);
|
||||
}
|
||||
if (
|
||||
(publicNextIndex === null || wait < publicTimeToNext) &&
|
||||
e.isPublic
|
||||
) {
|
||||
publicTimeToNext = wait;
|
||||
publicNextIndex = arr.findIndex((a) => a.id === e.id);
|
||||
}
|
||||
|
||||
if (nextIndex === null || wait < timeToNext) {
|
||||
timeToNext = wait;
|
||||
nextIndex = arr.findIndex((a) => a.id === e.id);
|
||||
}
|
||||
if ((publicNextIndex === null || wait < publicTimeToNext) && e.isPublic) {
|
||||
publicTimeToNext = wait;
|
||||
publicNextIndex = arr.findIndex((a) => a.id === e.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user