mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
refactor: simplify string comparisons
This commit is contained in:
committed by
Carlos Valente
parent
39e012452b
commit
7f8dbbfa87
@@ -107,6 +107,16 @@ describe('testConditions()', () => {
|
|||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('string comparisons should be case insensitive', () => {
|
||||||
|
const mockStore = makeRuntimeStateData({ eventNow: { title: 'Title' } as PlayableEvent });
|
||||||
|
const result = testConditions(
|
||||||
|
[{ field: 'eventNow.title', operator: 'equals', value: 'title' }],
|
||||||
|
'all',
|
||||||
|
mockStore,
|
||||||
|
);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('should check if a value does not exist', () => {
|
it('should check if a value does not exist', () => {
|
||||||
const mockStore = makeRuntimeStateData({ eventNow: null });
|
const mockStore = makeRuntimeStateData({ eventNow: null });
|
||||||
const result = testConditions([{ field: 'eventNow.title', operator: 'equals', value: '' }], 'all', mockStore);
|
const result = testConditions([{ field: 'eventNow.title', operator: 'equals', value: '' }], 'all', mockStore);
|
||||||
|
|||||||
@@ -82,10 +82,13 @@ export function testConditions(
|
|||||||
switch (operator) {
|
switch (operator) {
|
||||||
case 'equals':
|
case 'equals':
|
||||||
// handle the case where we are comparing boolean strings
|
// handle the case where we are comparing boolean strings
|
||||||
|
|
||||||
if (typeof fieldValue === 'boolean') {
|
if (typeof fieldValue === 'boolean') {
|
||||||
return isBooleanEquals(fieldValue, lowerCasedValue);
|
return isBooleanEquals(fieldValue, lowerCasedValue);
|
||||||
}
|
}
|
||||||
|
// make string comparisons case insensitive
|
||||||
|
if (typeof fieldValue === 'string') {
|
||||||
|
return fieldValue.toLowerCase() === lowerCasedValue;
|
||||||
|
}
|
||||||
// overload the edge case where we use empty string to check if a value does not exist
|
// overload the edge case where we use empty string to check if a value does not exist
|
||||||
if (value === '' && fieldValue === undefined) {
|
if (value === '' && fieldValue === undefined) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user