excel import leading and trailing whitespace (#902)

* add test for leading and trailing whitespace

* trim whitespace
This commit is contained in:
Alex Christoffer Rasmussen
2024-04-19 19:36:06 +01:00
committed by GitHub
parent c4136a0ec7
commit b14ac07568
2 changed files with 35 additions and 2 deletions
@@ -1407,4 +1407,37 @@ describe('parseExcel()', () => {
expect(events.at(6).timeStart).toEqual(59400000);
expect(events.at(7).timeStart).toEqual(78300000);
});
it('handle leading and trailing whitespace', () => {
const testData = [
['Time Start', 'Time End', ' Title', 'End Action', 'Public', 'Skip', 'Notes', 'Colour ', 'cue'],
['4:30:00', '4:30:00', 'A song from the hearth', 'load-next', 'x', '', 'Rainbow chase', '#F00', 102],
];
const importMap = {
worksheet: 'event schedule',
timeStart: ' time start',
timeEnd: 'time end ',
duration: 'duration',
cue: 'cue',
title: 'title',
isPublic: 'public',
skip: 'skip',
note: 'notes',
colour: 'colour',
endAction: 'end action',
timerType: 'timer type',
timeWarning: 'warning time',
timeDanger: 'danger time',
custom: {},
};
const result = parseExcel(testData, importMap);
const rundown = parseRundown(result);
const events = rundown.filter((e) => e.type === SupportedEvent.Event) as OntimeEvent[];
expect(events.at(0).timeStart).toEqual(16200000); //<--leading white space in MAP
expect(events.at(0).timeEnd).toEqual(16200000); //<--trailing white space in MAP
expect(events.at(0).title).toEqual('A song from the hearth'); //<--leading white space in Excel data
expect(events.at(0).colour).toEqual('#F00'); //<--trailing white space in Excel data
});
});
+2 -2
View File
@@ -74,7 +74,7 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ImportMap>)
for (const [key, value] of Object.entries(importMap)) {
if (typeof value === 'string') {
importMap[key] = value.toLocaleLowerCase();
importMap[key] = value.toLocaleLowerCase().trim();
}
}
@@ -222,7 +222,7 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ImportMap>)
if (column.length === 0) {
continue;
}
const columnText = column.toLowerCase();
const columnText = column.toLowerCase().trim();
// check if it is an ontime column
if (handlers[columnText]) {