Feat: reorder events with alt+ctrl + arrow up/down (#645)

* fix: key guard

* feat: reorder events

* refactor: return index from the getEvent functions
This commit is contained in:
Alex Christoffer Rasmussen
2023-12-28 13:41:43 +01:00
committed by GitHub
parent b2c01a141a
commit 96280e5932
5 changed files with 176 additions and 59 deletions
@@ -1,6 +1,43 @@
import { OntimeRundown, SupportedEvent } from 'ontime-types';
import { getNextEvent, getPreviousEvent } from './rundownUtils';
import { getNext, getNextEvent, getPrevious, getPreviousEvent } from './rundownUtils';
describe('getNext()', () => {
it('returns the next event of type event', () => {
const testRundown = [
{ id: '1', type: SupportedEvent.Event },
{ id: '2', type: SupportedEvent.Event },
{ id: '3', type: SupportedEvent.Event },
];
const { nextEvent, nextIndex } = getNext(testRundown as OntimeRundown, '1');
expect(nextEvent?.id).toBe('2');
expect(nextIndex).toBe(1);
});
it('alows other event types', () => {
const testRundown = [
{ id: '1', type: SupportedEvent.Event },
{ id: '2', type: SupportedEvent.Delay },
{ id: '3', type: SupportedEvent.Block },
{ id: '4', type: SupportedEvent.Event },
];
const { nextEvent, nextIndex } = getNext(testRundown as OntimeRundown, '1');
expect(nextEvent?.id).toBe('2');
expect(nextIndex).toBe(1);
});
it('returns null if none found', () => {
const testRundown = [
{ id: '1', type: SupportedEvent.Event },
{ id: '2', type: SupportedEvent.Delay },
{ id: '3', type: SupportedEvent.Block },
];
const { nextEvent, nextIndex } = getNext(testRundown as OntimeRundown, '3');
expect(nextEvent).toBe(null);
expect(nextIndex).toBe(null);
});
});
describe('getNextEvent()', () => {
it('returns the next event of type event', () => {
@@ -10,8 +47,9 @@ describe('getNextEvent()', () => {
{ id: '3', type: SupportedEvent.Event },
];
const next = getNextEvent(testRundown as OntimeRundown, '1');
expect(next?.id).toBe('2');
const { nextEvent, nextIndex } = getNextEvent(testRundown as OntimeRundown, '1');
expect(nextEvent?.id).toBe('2');
expect(nextIndex).toBe(1);
});
it('ignores other event types', () => {
const testRundown = [
@@ -21,8 +59,9 @@ describe('getNextEvent()', () => {
{ id: '4', type: SupportedEvent.Event },
];
const next = getNextEvent(testRundown as OntimeRundown, '1');
expect(next?.id).toBe('4');
const { nextEvent, nextIndex } = getNextEvent(testRundown as OntimeRundown, '1');
expect(nextEvent?.id).toBe('4');
expect(nextIndex).toBe(3);
});
it('returns null if none found', () => {
const testRundown = [
@@ -31,8 +70,46 @@ describe('getNextEvent()', () => {
{ id: '3', type: SupportedEvent.Block },
];
const next = getNextEvent(testRundown as OntimeRundown, '1');
expect(next).toBe(null);
const { nextEvent, nextIndex } = getNextEvent(testRundown as OntimeRundown, '1');
expect(nextEvent).toBe(null);
expect(nextIndex).toBe(null);
});
});
describe('getPrevious()', () => {
it('returns the previous event of type event', () => {
const testRundown = [
{ id: '1', type: SupportedEvent.Event },
{ id: '2', type: SupportedEvent.Event },
{ id: '3', type: SupportedEvent.Event },
];
const { previousEvent, previousIndex } = getPrevious(testRundown as OntimeRundown, '3');
expect(previousEvent?.id).toBe('2');
expect(previousIndex).toBe(1);
});
it('allow other event types', () => {
const testRundown = [
{ id: '1', type: SupportedEvent.Event },
{ id: '2', type: SupportedEvent.Delay },
{ id: '3', type: SupportedEvent.Block },
{ id: '4', type: SupportedEvent.Event },
];
const { previousEvent, previousIndex } = getPrevious(testRundown as OntimeRundown, '3');
expect(previousEvent?.id).toBe('2');
expect(previousIndex).toBe(1);
});
it('returns null if none found', () => {
const testRundown = [
{ id: '2', type: SupportedEvent.Delay },
{ id: '3', type: SupportedEvent.Block },
{ id: '4', type: SupportedEvent.Event },
];
const { previousEvent, previousIndex } = getPrevious(testRundown as OntimeRundown, '2');
expect(previousEvent).toBe(null);
expect(previousIndex).toBe(null);
});
});
@@ -44,8 +121,9 @@ describe('getPreviousEvent()', () => {
{ id: '3', type: SupportedEvent.Event },
];
const previous = getPreviousEvent(testRundown as OntimeRundown, '3');
expect(previous?.id).toBe('2');
const { previousEvent, previousIndex } = getPreviousEvent(testRundown as OntimeRundown, '3');
expect(previousEvent?.id).toBe('2');
expect(previousIndex).toBe(1);
});
it('ignores other event types', () => {
const testRundown = [
@@ -55,8 +133,9 @@ describe('getPreviousEvent()', () => {
{ id: '4', type: SupportedEvent.Event },
];
const previous = getPreviousEvent(testRundown as OntimeRundown, '4');
expect(previous?.id).toBe('1');
const { previousEvent, previousIndex } = getPreviousEvent(testRundown as OntimeRundown, '4');
expect(previousEvent?.id).toBe('1');
expect(previousIndex).toBe(0);
});
it('returns null if none found', () => {
const testRundown = [
@@ -65,7 +144,8 @@ describe('getPreviousEvent()', () => {
{ id: '4', type: SupportedEvent.Event },
];
const previous = getNextEvent(testRundown as OntimeRundown, '1');
expect(previous).toBe(null);
const { previousEvent, previousIndex } = getPreviousEvent(testRundown as OntimeRundown, '2');
expect(previousEvent).toBe(null);
expect(previousIndex).toBe(null);
});
});